Skip to content

Commit fddfb58

Browse files
committed
REVIEWED: Potential shader issues
1 parent af163ba commit fddfb58

File tree

5 files changed

+30
-34
lines changed

5 files changed

+30
-34
lines changed

Diff for: examples/shaders/resources/shaders/glsl100/depth.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ void main()
2222
float depth = (2.0*zNear)/(zFar + zNear - z*(zFar - zNear));
2323

2424
// Calculate final fragment color
25-
gl_FragColor = vec4(depth, depth, depth, 1.0f);
25+
gl_FragColor = vec4(depth, depth, depth, 1.0);
2626
}

Diff for: examples/shaders/resources/shaders/glsl120/shadowmap.fs

+10-10
Original file line numberDiff line numberDiff line change
@@ -46,34 +46,34 @@ void main()
4646
vec4 finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
4747

4848
// Shadow calculations
49-
vec4 fragPosLightSpace = lightVP * vec4(fragPosition, 1);
49+
vec4 fragPosLightSpace = lightVP*vec4(fragPosition, 1);
5050
fragPosLightSpace.xyz /= fragPosLightSpace.w; // Perform the perspective division
51-
fragPosLightSpace.xyz = (fragPosLightSpace.xyz + 1.0f) / 2.0f; // Transform from [-1, 1] range to [0, 1] range
51+
fragPosLightSpace.xyz = (fragPosLightSpace.xyz + 1.0)/2.0; // Transform from [-1, 1] range to [0, 1] range
5252
vec2 sampleCoords = fragPosLightSpace.xy;
5353
float curDepth = fragPosLightSpace.z;
54+
5455
// Slope-scale depth bias: depth biasing reduces "shadow acne" artifacts, where dark stripes appear all over the scene.
5556
// The solution is adding a small bias to the depth
5657
// In this case, the bias is proportional to the slope of the surface, relative to the light
57-
float bias = max(0.0008 * (1.0 - dot(normal, l)), 0.00008);
58+
float bias = max(0.0008*(1.0 - dot(normal, l)), 0.00008);
5859
int shadowCounter = 0;
5960
const int numSamples = 9;
61+
6062
// PCF (percentage-closer filtering) algorithm:
6163
// Instead of testing if just one point is closer to the current point,
6264
// we test the surrounding points as well.
6365
// This blurs shadow edges, hiding aliasing artifacts.
64-
vec2 texelSize = vec2(1.0f / float(shadowMapResolution));
66+
vec2 texelSize = vec2(1.0/float(shadowMapResolution));
6567
for (int x = -1; x <= 1; x++)
6668
{
6769
for (int y = -1; y <= 1; y++)
6870
{
69-
float sampleDepth = texture2D(shadowMap, sampleCoords + texelSize * vec2(x, y)).r;
70-
if (curDepth - bias > sampleDepth)
71-
{
72-
shadowCounter++;
73-
}
71+
float sampleDepth = texture2D(shadowMap, sampleCoords + texelSize*vec2(x, y)).r;
72+
if (curDepth - bias > sampleDepth) shadowCounter++;
7473
}
7574
}
76-
finalColor = mix(finalColor, vec4(0, 0, 0, 1), float(shadowCounter) / float(numSamples));
75+
76+
finalColor = mix(finalColor, vec4(0, 0, 0, 1), float(shadowCounter)/float(numSamples));
7777

7878
// Add ambient lighting whether in shadow or not
7979
finalColor += texelColor*(ambient/10.0)*colDiffuse;

Diff for: examples/shaders/resources/shaders/glsl330/depth.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ void main()
2323
float depth = (2.0*zNear)/(zFar + zNear - z*(zFar - zNear));
2424

2525
// Calculate final fragment color
26-
finalColor = vec4(depth, depth, depth, 1.0f);
26+
finalColor = vec4(depth, depth, depth, 1.0);
2727
}

Diff for: examples/shaders/resources/shaders/glsl330/julia_set.fs

+10-13
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,20 @@ uniform vec2 offset; // Offset of the scale.
1212
uniform float zoom; // Zoom of the scale.
1313

1414
const int maxIterations = 255; // Max iterations to do.
15-
const float colorCycles = 2.0f; // Number of times the color palette repeats. Can show higher detail for higher iteration numbers.
15+
const float colorCycles = 2.0; // Number of times the color palette repeats. Can show higher detail for higher iteration numbers.
1616

1717
// Square a complex number
1818
vec2 ComplexSquare(vec2 z)
1919
{
20-
return vec2(
21-
z.x*z.x - z.y*z.y,
22-
z.x*z.y*2.0f
23-
);
20+
return vec2(z.x*z.x - z.y*z.y, z.x*z.y*2.0);
2421
}
2522

2623
// Convert Hue Saturation Value (HSV) color into RGB
2724
vec3 Hsv2rgb(vec3 c)
2825
{
29-
vec4 K = vec4(1.0f, 2.0f/3.0f, 1.0f/3.0f, 3.0f);
30-
vec3 p = abs(fract(c.xxx + K.xyz)*6.0f - K.www);
31-
return c.z*mix(K.xxx, clamp(p - K.xxx, 0.0f, 1.0f), c.y);
26+
vec4 K = vec4(1.0, 2.0/3.0, 1.0/3.0, 3.0);
27+
vec3 p = abs(fract(c.xxx + K.xyz)*6.0 - K.www);
28+
return c.z*mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
3229
}
3330

3431
void main()
@@ -54,7 +51,7 @@ void main()
5451

5552
// The pixel coordinates are scaled so they are on the mandelbrot scale
5653
// NOTE: fragTexCoord already comes as normalized screen coordinates but offset must be normalized before scaling and zoom
57-
vec2 z = vec2((fragTexCoord.x - 0.5f)*2.5f, (fragTexCoord.y - 0.5f)*1.5f)/zoom;
54+
vec2 z = vec2((fragTexCoord.x - 0.5f)*2.5, (fragTexCoord.y - 0.5)*1.5)/zoom;
5855
z.x += offset.x;
5956
z.y += offset.y;
6057

@@ -63,7 +60,7 @@ void main()
6360
{
6461
z = ComplexSquare(z) + c; // Iterate function
6562

66-
if (dot(z, z) > 4.0f) break;
63+
if (dot(z, z) > 4.0) break;
6764
}
6865

6966
// Another few iterations decreases errors in the smoothing calculation.
@@ -72,12 +69,12 @@ void main()
7269
z = ComplexSquare(z) + c;
7370

7471
// This last part smooths the color (again see link above).
75-
float smoothVal = float(iterations) + 1.0f - (log(log(length(z)))/log(2.0f));
72+
float smoothVal = float(iterations) + 1.0 - (log(log(length(z)))/log(2.0));
7673

7774
// Normalize the value so it is between 0 and 1.
7875
float norm = smoothVal/float(maxIterations);
7976

8077
// If in set, color black. 0.999 allows for some float accuracy error.
81-
if (norm > 0.999f) finalColor = vec4(0.0f, 0.0f, 0.0f, 1.0f);
82-
else finalColor = vec4(Hsv2rgb(vec3(norm*colorCycles, 1.0f, 1.0f)), 1.0f);
78+
if (norm > 0.999) finalColor = vec4(0.0, 0.0, 0.0, 1.0);
79+
else finalColor = vec4(Hsv2rgb(vec3(norm*colorCycles, 1.0, 1.0)), 1.0);
8380
}

Diff for: examples/shaders/resources/shaders/glsl330/shadowmap.fs

+8-9
Original file line numberDiff line numberDiff line change
@@ -51,32 +51,31 @@ void main()
5151
// Shadow calculations
5252
vec4 fragPosLightSpace = lightVP * vec4(fragPosition, 1);
5353
fragPosLightSpace.xyz /= fragPosLightSpace.w; // Perform the perspective division
54-
fragPosLightSpace.xyz = (fragPosLightSpace.xyz + 1.0f) / 2.0f; // Transform from [-1, 1] range to [0, 1] range
54+
fragPosLightSpace.xyz = (fragPosLightSpace.xyz + 1.0)/2.0; // Transform from [-1, 1] range to [0, 1] range
5555
vec2 sampleCoords = fragPosLightSpace.xy;
5656
float curDepth = fragPosLightSpace.z;
57+
5758
// Slope-scale depth bias: depth biasing reduces "shadow acne" artifacts, where dark stripes appear all over the scene.
5859
// The solution is adding a small bias to the depth
5960
// In this case, the bias is proportional to the slope of the surface, relative to the light
60-
float bias = max(0.0002 * (1.0 - dot(normal, l)), 0.00002) + 0.00001;
61+
float bias = max(0.0002*(1.0 - dot(normal, l)), 0.00002) + 0.00001;
6162
int shadowCounter = 0;
6263
const int numSamples = 9;
64+
6365
// PCF (percentage-closer filtering) algorithm:
6466
// Instead of testing if just one point is closer to the current point,
6567
// we test the surrounding points as well.
6668
// This blurs shadow edges, hiding aliasing artifacts.
67-
vec2 texelSize = vec2(1.0f / float(shadowMapResolution));
69+
vec2 texelSize = vec2(1.0/float(shadowMapResolution));
6870
for (int x = -1; x <= 1; x++)
6971
{
7072
for (int y = -1; y <= 1; y++)
7173
{
72-
float sampleDepth = texture(shadowMap, sampleCoords + texelSize * vec2(x, y)).r;
73-
if (curDepth - bias > sampleDepth)
74-
{
75-
shadowCounter++;
76-
}
74+
float sampleDepth = texture(shadowMap, sampleCoords + texelSize*vec2(x, y)).r;
75+
if (curDepth - bias > sampleDepth) shadowCounter++;
7776
}
7877
}
79-
finalColor = mix(finalColor, vec4(0, 0, 0, 1), float(shadowCounter) / float(numSamples));
78+
finalColor = mix(finalColor, vec4(0, 0, 0, 1), float(shadowCounter)/float(numSamples));
8079

8180
// Add ambient lighting whether in shadow or not
8281
finalColor += texelColor*(ambient/10.0)*colDiffuse;

0 commit comments

Comments
 (0)