File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -160,9 +160,20 @@ -(void)buildFragmentFunctions
160160 // map alpha also allows the effect to be disabled for specific pixels.
161161 vec4 refraction = normalMap.a * inBounds * texture2D (u_refractEnvMap, refractTexCoords) * (1.0 - primaryColor.a );
162162
163+ // Compute Schlick's approximation (http://en.wikipedia.org/wiki/Schlick's_approximation) of the
164+ // fresnel reflectance.
165+ float fresnel = max (u_fresnelBias + (1.0 - u_fresnelBias) * pow ((1.0 - nDotV), u_fresnelPower), 0.0 );
166+
167+ // Apply a cutoff to nDotV to reduce the aliasing that occurs in the reflected
168+ // image. As the surface normal approaches a 90 degree angle relative to the viewing
169+ // direction, the sampling of the reflection map becomes more and more compressed
170+ // which can lead to undesirable aliasing artifacts. The cutoff threshold reduces
171+ // the contribution of these pixels to the final image and hides this aliasing.
172+ const float NDOTV_CUTOFF = 0.2 ;
173+ fresnel *= smoothstep (0.0 , NDOTV_CUTOFF, nDotV);
174+
163175 // Add the reflected color modulated by the fresnel term. Multiplying by the normal
164176 // map alpha also allows the effect to be disabled for specific pixels.
165- float fresnel = max (u_fresnelBias + (1.0 - u_fresnelBias) * pow ((1.0 - nDotV), u_fresnelPower), 0.0 );
166177 vec4 reflection = normalMap.a * fresnel * u_shininess * texture2D (u_reflectEnvMap, reflectTexCoords);
167178
168179 return primaryColor + refraction + reflection;
Original file line number Diff line number Diff line change @@ -137,8 +137,18 @@ -(void)buildFragmentFunctions
137137 // Compute the combination of the sprite's color and texture.
138138 vec4 primaryColor = inputValue;
139139
140+ // Compute Schlick's approximation (http://en.wikipedia.org/wiki/Schlick's_approximation) of the
141+ // fresnel reflectance.
140142 float fresnel = max (u_fresnelBias + (1.0 - u_fresnelBias) * pow ((1.0 - nDotV), u_fresnelPower), 0.0 );
141143
144+ // Apply a cutoff to nDotV to reduce the aliasing that occurs in the reflected
145+ // image. As the surface normal approaches a 90 degree angle relative to the viewing
146+ // direction, the sampling of the reflection map becomes more and more compressed
147+ // which can lead to undesirable aliasing artifacts. The cutoff threshold reduces
148+ // the contribution of these pixels to the final image and hides this aliasing.
149+ const float NDOTV_CUTOFF = 0.2 ;
150+ fresnel *= smoothstep (0.0 , NDOTV_CUTOFF, nDotV);
151+
142152 // If the reflected texture coordinates are within the bounds of the environment map
143153 // blend the primary color with the reflected environment. Multiplying by the normal
144154 // map alpha also allows the effect to be disabled for specific pixels.
You can’t perform that action at this time.
0 commit comments