Bläddra i källkod

Add precision qualifiers and fix floats

Daniel Salvadori 6 år sedan
förälder
incheckning
cf98332151

+ 2 - 0
renderer/shaders/basic_fragment.glsl

@@ -2,6 +2,8 @@
 // Fragment Shader template
 //
 
+precision highp float;
+
 in vec3 Color;
 out vec4 FragColor;
 

+ 4 - 2
renderer/shaders/panel_fragment.glsl

@@ -2,6 +2,8 @@
 // Fragment Shader template
 //
 
+precision highp float;
+
 // Texture uniforms
 uniform sampler2D	MatTexture;
 uniform vec2		MatTexinfo[3];
@@ -79,7 +81,7 @@ void main() {
 		if (TextureValid) {
             // Adjust texture coordinates to fit texture inside the content area
             vec2 offset = vec2(-Content[0], -Content[1]);
-            vec2 factor = vec2(1/Content[2], 1/Content[3]);
+            vec2 factor = vec2(1.0/Content[2], 1.0/Content[3]);
             vec2 texcoord = (FragTexcoord + offset) * factor;
             vec4 texColor = texture(MatTexture, texcoord * MatTexRepeat + MatTexOffset);
 
@@ -97,7 +99,7 @@ void main() {
             texPre.rgb *= texPre.a;
 
             // Combine colors the premultiplied final color
-            color = texPre + contentPre * (1 - texPre.a);
+            color = texPre + contentPre * (1.0 - texPre.a);
 
             // Un-pre-multiply (pre-divide? :P)
             color.rgb /= color.a;

+ 1 - 1
renderer/shaders/panel_vertex.glsl

@@ -14,7 +14,7 @@ void main() {
 
     // Always flip texture coordinates
     vec2 texcoord = VertexTexcoord;
-    texcoord.y = 1 - texcoord.y;
+    texcoord.y = 1.0 - texcoord.y;
     FragTexcoord = texcoord;
 
     // Set position

+ 2 - 0
renderer/shaders/phong_fragment.glsl

@@ -2,6 +2,8 @@
 // Fragment Shader template
 //
 
+precision highp float;
+
 // Inputs from vertex shader
 in vec4 Position;       // Vertex position in camera coordinates.
 in vec3 Normal;         // Vertex normal in camera coordinates.

+ 1 - 1
renderer/shaders/phong_vertex.glsl

@@ -34,7 +34,7 @@ void main() {
     vec2 texcoord = VertexTexcoord;
 #if MAT_TEXTURES>0
     if (MatTexFlipY(0)) {
-        texcoord.y = 1 - texcoord.y;
+        texcoord.y = 1.0 - texcoord.y;
     }
 #endif
     FragTexcoord = texcoord;

+ 2 - 0
renderer/shaders/point_fragment.glsl

@@ -1,3 +1,5 @@
+precision highp float;
+
 #include <material>
 
 // GLSL 3.30 does not allow indexing texture sampler with non constant values.

+ 20 - 7
renderer/shaders/sources.go

@@ -300,6 +300,8 @@ const basic_fragment_source = `//
 // Fragment Shader template
 //
 
+precision highp float;
+
 in vec3 Color;
 out vec4 FragColor;
 
@@ -334,6 +336,8 @@ const panel_fragment_source = `//
 // Fragment Shader template
 //
 
+precision highp float;
+
 // Texture uniforms
 uniform sampler2D	MatTexture;
 uniform vec2		MatTexinfo[3];
@@ -411,7 +415,7 @@ void main() {
 		if (TextureValid) {
             // Adjust texture coordinates to fit texture inside the content area
             vec2 offset = vec2(-Content[0], -Content[1]);
-            vec2 factor = vec2(1/Content[2], 1/Content[3]);
+            vec2 factor = vec2(1.0/Content[2], 1.0/Content[3]);
             vec2 texcoord = (FragTexcoord + offset) * factor;
             vec4 texColor = texture(MatTexture, texcoord * MatTexRepeat + MatTexOffset);
 
@@ -429,7 +433,7 @@ void main() {
             texPre.rgb *= texPre.a;
 
             // Combine colors the premultiplied final color
-            color = texPre + contentPre * (1 - texPre.a);
+            color = texPre + contentPre * (1.0 - texPre.a);
 
             // Un-pre-multiply (pre-divide? :P)
             color.rgb /= color.a;
@@ -473,7 +477,7 @@ void main() {
 
     // Always flip texture coordinates
     vec2 texcoord = VertexTexcoord;
-    texcoord.y = 1 - texcoord.y;
+    texcoord.y = 1.0 - texcoord.y;
     FragTexcoord = texcoord;
 
     // Set position
@@ -487,6 +491,8 @@ const phong_fragment_source = `//
 // Fragment Shader template
 //
 
+precision highp float;
+
 // Inputs from vertex shader
 in vec4 Position;       // Vertex position in camera coordinates.
 in vec3 Normal;         // Vertex normal in camera coordinates.
@@ -572,7 +578,7 @@ void main() {
     vec2 texcoord = VertexTexcoord;
 #if MAT_TEXTURES>0
     if (MatTexFlipY(0)) {
-        texcoord.y = 1 - texcoord.y;
+        texcoord.y = 1.0 - texcoord.y;
     }
 #endif
     FragTexcoord = texcoord;
@@ -1056,7 +1062,9 @@ void main() {
 
 `
 
-const point_fragment_source = `#include <material>
+const point_fragment_source = `precision highp float;
+
+#include <material>
 
 // GLSL 3.30 does not allow indexing texture sampler with non constant values.
 // This macro is used to mix the texture with the specified index with the material color.
@@ -1136,6 +1144,8 @@ const sprite_fragment_source = `//
 // Fragment shader for sprite
 //
 
+precision highp float;
+
 #include <material>
 
 // Inputs from vertex shader
@@ -1193,7 +1203,7 @@ void main() {
     vec2 texcoord = VertexTexcoord;
 #if MAT_TEXTURES>0
     if (MatTexFlipY[0]) {
-        texcoord.y = 1 - texcoord.y;
+        texcoord.y = 1.0 - texcoord.y;
     }
 #endif
     FragTexcoord = texcoord;
@@ -1204,6 +1214,9 @@ void main() {
 const standard_fragment_source = `//
 // Fragment Shader template
 //
+
+precision highp float;
+
 #include <material>
 
 // Inputs from Vertex shader
@@ -1291,7 +1304,7 @@ void main() {
 #if MAT_TEXTURES > 0
     // Flips texture coordinate Y if requested.
     if (MatTexFlipY(0)) {
-        texcoord.y = 1 - texcoord.y;
+        texcoord.y = 1.0 - texcoord.y;
     }
 #endif
     FragTexcoord = texcoord;

+ 2 - 0
renderer/shaders/sprite_fragment.glsl

@@ -2,6 +2,8 @@
 // Fragment shader for sprite
 //
 
+precision highp float;
+
 #include <material>
 
 // Inputs from vertex shader

+ 1 - 1
renderer/shaders/sprite_vertex.glsl

@@ -25,7 +25,7 @@ void main() {
     vec2 texcoord = VertexTexcoord;
 #if MAT_TEXTURES>0
     if (MatTexFlipY[0]) {
-        texcoord.y = 1 - texcoord.y;
+        texcoord.y = 1.0 - texcoord.y;
     }
 #endif
     FragTexcoord = texcoord;

+ 3 - 0
renderer/shaders/standard_fragment.glsl

@@ -1,6 +1,9 @@
 //
 // Fragment Shader template
 //
+
+precision highp float;
+
 #include <material>
 
 // Inputs from Vertex shader

+ 1 - 1
renderer/shaders/standard_vertex.glsl

@@ -42,7 +42,7 @@ void main() {
 #if MAT_TEXTURES > 0
     // Flips texture coordinate Y if requested.
     if (MatTexFlipY(0)) {
-        texcoord.y = 1 - texcoord.y;
+        texcoord.y = 1.0 - texcoord.y;
     }
 #endif
     FragTexcoord = texcoord;