Commit e6f2fd5c274926b98c1a189650e7f9548eca74ac

Authored by Adeel Kazmi
1 parent 6ffb190b

(RefractionEffect) Ensure shader compiles with more strict compilers

Shader does not compile with latest Nvidia driver on Ubuntu as we did not set the default precision
and used an f at the end of a float in the shader. Other shader compilers are more permissive so
this was not spotted before.

Change-Id: I235b901f08a73086b8b581a8c40bb4ed517ba35d
examples/shader-effect/refraction-effect-example.cpp
@@ -94,6 +94,7 @@ public: @@ -94,6 +94,7 @@ public:
94 static NoEffect New() 94 static NoEffect New()
95 { 95 {
96 std::string vertexShader = MAKE_SHADER( 96 std::string vertexShader = MAKE_SHADER(
  97 + precision mediump float;\n
97 uniform mediump vec4 uTextureRect;\n 98 uniform mediump vec4 uTextureRect;\n
98 void main()\n 99 void main()\n
99 {\n 100 {\n
@@ -102,6 +103,7 @@ public: @@ -102,6 +103,7 @@ public:
102 }\n 103 }\n
103 ); 104 );
104 std::string fragmentShader = MAKE_SHADER( 105 std::string fragmentShader = MAKE_SHADER(
  106 + precision mediump float;\n
105 void main()\n 107 void main()\n
106 {\n 108 {\n
107 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n 109 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
@@ -153,6 +155,7 @@ public: @@ -153,6 +155,7 @@ public:
153 static RefractionEffect New() 155 static RefractionEffect New()
154 { 156 {
155 std::string vertexShader = MAKE_SHADER( 157 std::string vertexShader = MAKE_SHADER(
  158 + precision mediump float;\n
156 varying mediump vec2 vTextureOffset;\n 159 varying mediump vec2 vTextureOffset;\n
157 void main()\n 160 void main()\n
158 {\n 161 {\n
@@ -167,6 +170,7 @@ public: @@ -167,6 +170,7 @@ public:
167 ); 170 );
168 171
169 std::string fragmentShader = MAKE_SHADER( 172 std::string fragmentShader = MAKE_SHADER(
  173 + precision mediump float;\n
170 uniform mediump float uEffectStrength;\n 174 uniform mediump float uEffectStrength;\n
171 uniform mediump vec3 uLightPosition;\n 175 uniform mediump vec3 uLightPosition;\n
172 uniform mediump vec2 uLightXYOffset;\n 176 uniform mediump vec2 uLightXYOffset;\n
@@ -205,7 +209,7 @@ public: @@ -205,7 +209,7 @@ public:
205 {\n 209 {\n
206 vec3 normal = normalize( vNormal);\n 210 vec3 normal = normalize( vNormal);\n
207 211
208 - vec3 lightPosition = uLightPosition + vec3(uLightXYOffset+uLightSpinOffset, 0.f);\n 212 + vec3 lightPosition = uLightPosition + vec3(uLightXYOffset+uLightSpinOffset, 0.0);\n
209 mediump vec3 vecToLight = normalize( (lightPosition - vVertex.xyz) * 0.01 );\n 213 mediump vec3 vecToLight = normalize( (lightPosition - vVertex.xyz) * 0.01 );\n
210 mediump float spotEffect = pow( max(0.05, vecToLight.z ) - 0.05, 8.0);\n 214 mediump float spotEffect = pow( max(0.05, vecToLight.z ) - 0.05, 8.0);\n
211 215