Skip to content
Snippets Groups Projects
Commit f2d9f3e2 authored by Alexander Rose's avatar Alexander Rose
Browse files

avoid function overloading in shaders for comaptibility

parent d41c630b
No related branches found
No related tags found
No related merge requests found
...@@ -36,14 +36,14 @@ float decodeFloatRGB(const in vec3 rgb) { ...@@ -36,14 +36,14 @@ float decodeFloatRGB(const in vec3 rgb) {
return m; return m;
} }
mat2 transpose(const in mat2 m) { mat2 transpose2(const in mat2 m) {
return mat2( return mat2(
m[0][0], m[1][0], m[0][0], m[1][0],
m[0][1], m[1][1] m[0][1], m[1][1]
); );
} }
mat3 transpose(const in mat3 m) { mat3 transpose3(const in mat3 m) {
return mat3( return mat3(
m[0][0], m[1][0], m[2][0], m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1], m[0][1], m[1][1], m[2][1],
...@@ -51,7 +51,7 @@ float decodeFloatRGB(const in vec3 rgb) { ...@@ -51,7 +51,7 @@ float decodeFloatRGB(const in vec3 rgb) {
); );
} }
mat4 transpose(const in mat4 m) { mat4 transpose4(const in mat4 m) {
return mat4( return mat4(
m[0][0], m[1][0], m[2][0], m[3][0], m[0][0], m[1][0], m[2][0], m[3][0],
m[0][1], m[1][1], m[2][1], m[3][1], m[0][1], m[1][1], m[2][1], m[3][1],
...@@ -60,18 +60,18 @@ float decodeFloatRGB(const in vec3 rgb) { ...@@ -60,18 +60,18 @@ float decodeFloatRGB(const in vec3 rgb) {
); );
} }
// inverse
float inverse(const in float m) { float inverse(const in float m) {
return 1.0 / m; return 1.0 / m;
} }
// inverse mat2 inverse2(const in mat2 m) {
mat2 inverse(const in mat2 m) {
return mat2(m[1][1],-m[0][1], return mat2(m[1][1],-m[0][1],
-m[1][0], m[0][0]) / (m[0][0]*m[1][1] - m[0][1]*m[1][0]); -m[1][0], m[0][0]) / (m[0][0]*m[1][1] - m[0][1]*m[1][0]);
} }
mat3 inverse(const in mat3 m) { mat3 inverse3(const in mat3 m) {
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2]; float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2]; float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2]; float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
...@@ -87,7 +87,7 @@ float decodeFloatRGB(const in vec3 rgb) { ...@@ -87,7 +87,7 @@ float decodeFloatRGB(const in vec3 rgb) {
b21, (-a21 * a00 + a01 * a20), (a11 * a00 - a01 * a10)) / det; b21, (-a21 * a00 + a01 * a20), (a11 * a00 - a01 * a10)) / det;
} }
mat4 inverse(const in mat4 m) { mat4 inverse4(const in mat4 m) {
float float
a00 = m[0][0], a01 = m[0][1], a02 = m[0][2], a03 = m[0][3], a00 = m[0][0], a01 = m[0][1], a02 = m[0][2], a03 = m[0][3],
a10 = m[1][0], a11 = m[1][1], a12 = m[1][2], a13 = m[1][3], a10 = m[1][0], a11 = m[1][1], a12 = m[1][2], a13 = m[1][3],
...@@ -127,5 +127,13 @@ float decodeFloatRGB(const in vec3 rgb) { ...@@ -127,5 +127,13 @@ float decodeFloatRGB(const in vec3 rgb) {
a31 * b01 - a30 * b03 - a32 * b00, a31 * b01 - a30 * b03 - a32 * b00,
a20 * b03 - a21 * b01 + a22 * b00) / det; a20 * b03 - a21 * b01 + a22 * b00) / det;
} }
#else
#define transpose2(m) transpose(m)
#define transpose3(m) transpose(m)
#define transpose4(m) transpose(m)
#define inverse2(m) inverse(m)
#define inverse3(m) inverse(m)
#define inverse4(m) inverse(m)
#endif #endif
` `
\ No newline at end of file
...@@ -204,7 +204,7 @@ void main(void) { ...@@ -204,7 +204,7 @@ void main(void) {
n0.z + t * (n0.z - n1.z) n0.z + t * (n0.z - n1.z)
); );
mat3 normalMatrix = transpose(inverse(mat3(uGridTransform))); mat3 normalMatrix = transpose3(inverse3(mat3(uGridTransform)));
gl_FragData[1].xyz = normalMatrix * gl_FragData[1].xyz; gl_FragData[1].xyz = normalMatrix * gl_FragData[1].xyz;
} }
` `
\ No newline at end of file
...@@ -44,7 +44,7 @@ void main(){ ...@@ -44,7 +44,7 @@ void main(){
#else #else
vec3 normal = aNormal; vec3 normal = aNormal;
#endif #endif
mat3 normalMatrix = transpose(inverse(mat3(modelView))); mat3 normalMatrix = transpose3(inverse3(mat3(modelView)));
vec3 transformedNormal = normalize(normalMatrix * normalize(normal)); vec3 transformedNormal = normalize(normalMatrix * normalize(normal));
#if defined(dFlipSided) && !defined(dDoubleSided) // TODO checking dDoubleSided should not be required, ASR #if defined(dFlipSided) && !defined(dDoubleSided) // TODO checking dDoubleSided should not be required, ASR
transformedNormal = -transformedNormal; transformedNormal = -transformedNormal;
......
...@@ -52,7 +52,7 @@ void quadraticProjection(const in float radius, const in vec3 position){ ...@@ -52,7 +52,7 @@ void quadraticProjection(const in float radius, const in vec3 position){
position.x, position.y, position.z, 1.0 position.x, position.y, position.z, 1.0
); );
mat4 R = transpose(uProjection * uModelView * aTransform * T); mat4 R = transpose4(uProjection * uModelView * aTransform * T);
float A = dot(R[3], D * R[3]); float A = dot(R[3], D * R[3]);
float B = -2.0 * dot(R[0], D * R[3]); float B = -2.0 * dot(R[0], D * R[3]);
float C = dot(R[0], D * R[0]); float C = dot(R[0], D * R[0]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment