Skip to content

Commit 0899250

Browse files
committed
make all shaders output vec4, not vec3
1 parent 5e4e128 commit 0899250

File tree

8 files changed

+27
-35
lines changed

8 files changed

+27
-35
lines changed

data/cage/shaders/effects/bloomApply.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ layout(binding = 1) uniform sampler2D texBloom;
1010

1111
layout(location = 0) uniform int uniLodLevel;
1212

13-
out vec3 outColor;
13+
out vec4 outColor;
1414

1515
void main()
1616
{
@@ -19,5 +19,5 @@ void main()
1919
vec2 uv = vec2(gl_FragCoord) / textureSize(texColor, 0).xy;
2020
for (int i = 0; i < uniLodLevel; i++)
2121
bloom += textureLod(texBloom, uv, i).rgb;
22-
outColor = color + bloom / uniLodLevel; // additive mixing
22+
outColor = vec4(color + bloom / uniLodLevel, 1); // additive mixing
2323
}

data/cage/shaders/effects/bloomGenerate.glsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ layout(location = 0) uniform vec4 uniBloomParams; // threshold
99

1010
layout(binding = 0) uniform sampler2D texColor;
1111

12-
out vec3 outBloom;
12+
out vec4 outBloom;
1313

1414
const int downscale = 3;
1515

@@ -32,7 +32,7 @@ void main()
3232
}
3333
}
3434
if (cnt > 0)
35-
outBloom = acc / float(cnt);
35+
outBloom = vec4(acc / float(cnt), 1);
3636
else
37-
outBloom = vec3(0.0);
37+
outBloom = vec4(0, 0, 0, 1);
3838
}

data/cage/shaders/effects/dofApply.glsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ layout(binding = 0) uniform sampler2D texColor;
3838
layout(binding = 1) uniform sampler2D texDepth;
3939
layout(binding = 2) uniform sampler2D texDof;
4040

41-
out vec3 outColor;
41+
out vec4 outColor;
4242

4343
void main()
4444
{
@@ -48,12 +48,12 @@ void main()
4848
float depth = texelFetch(texDepth, ivec2(gl_FragCoord), 0).x;
4949
if (depth > 1 - 1e-7)
5050
{ // skybox
51-
outColor = color;
51+
outColor = vec4(color, 1);
5252
return;
5353
}
5454
vec3 colorDof = textureLod(texDof, uv, 0).rgb;
5555
float near;
5656
float far;
5757
dofContribution(uv, depth, near, far);
58-
outColor = color * (1 - near - far) + colorDof * (near + far);
58+
outColor = vec4(color * (1 - near - far) + colorDof * (near + far), 1);
5959
}

data/cage/shaders/effects/dofCollect.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ $define shader fragment
77

88
layout(binding = 0) uniform sampler2D texColor;
99

10-
out vec3 outDof;
10+
out vec4 outDof;
1111

1212
const int downscale = 3;
1313

@@ -21,5 +21,5 @@ void main()
2121
for (int x = 0; x < downscale; x++)
2222
color += texelFetch(texColor, ivec2(gl_FragCoord) * downscale + ivec2(x, y) - downscale / 2, 0).rgb;
2323
color /= float(downscale * downscale);
24-
outDof = color;
24+
outDof = vec4(color, 1);
2525
}

data/cage/shaders/effects/fxaa.glsl

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,16 @@ layout(binding = 0) uniform sampler2D texColor;
1212
out vec4 outColor;
1313

1414
const float lumaThreshold = 0.5;
15-
const float mulReduce = 1.0 / 8.0;
16-
const float minReduce = 1.0 / 128.0;
17-
const float maxSpan = 8.0;
15+
const float mulReduce = 1 / 8.0;
16+
const float minReduce = 1 / 128.0;
17+
const float maxSpan = 8;
1818
const vec3 toLuma = vec3(0.299, 0.587, 0.114);
1919

2020
void main()
2121
{
22-
vec2 texelStep = 1.0 / vec2(textureSize(texColor, 0));
22+
vec2 texelStep = 1 / vec2(textureSize(texColor, 0));
2323
vec2 uv = gl_FragCoord.xy * texelStep;
2424
vec3 rgbM = textureLod(texColor, uv, 0).rgb;
25-
if (false)
26-
{
27-
outColor = vec4(rgbM, 1.0);
28-
return;
29-
}
3025

3126
vec3 rgbNW = textureLodOffset(texColor, uv, 0, ivec2(-1, 1)).rgb;
3227
vec3 rgbNE = textureLodOffset(texColor, uv, 0, ivec2(1, 1)).rgb;
@@ -41,28 +36,25 @@ void main()
4136
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
4237
if (lumaMax - lumaMin <= lumaMax * lumaThreshold)
4338
{
44-
outColor = vec4(rgbM, 1.0);
39+
outColor = vec4(rgbM, 1);
4540
return;
4641
}
4742

4843
vec2 samplingDirection;
4944
samplingDirection.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
5045
samplingDirection.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
5146
float samplingDirectionReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * 0.25 * mulReduce, minReduce);
52-
float minSamplingDirectionFactor = 1.0 / (min(abs(samplingDirection.x), abs(samplingDirection.y)) + samplingDirectionReduce);
47+
float minSamplingDirectionFactor = 1 / (min(abs(samplingDirection.x), abs(samplingDirection.y)) + samplingDirectionReduce);
5348
samplingDirection = clamp(samplingDirection * minSamplingDirectionFactor, vec2(-maxSpan), vec2(maxSpan)) * texelStep;
54-
vec3 rgbSampleNeg = textureLod(texColor, uv + samplingDirection * (1.0/3.0 - 0.5), 0).rgb;
55-
vec3 rgbSamplePos = textureLod(texColor, uv + samplingDirection * (2.0/3.0 - 0.5), 0).rgb;
49+
vec3 rgbSampleNeg = textureLod(texColor, uv + samplingDirection * (1/3.0 - 0.5), 0).rgb;
50+
vec3 rgbSamplePos = textureLod(texColor, uv + samplingDirection * (2/3.0 - 0.5), 0).rgb;
5651
vec3 rgbTwoTab = (rgbSamplePos + rgbSampleNeg) * 0.5;
57-
vec3 rgbSampleNegOuter = textureLod(texColor, uv + samplingDirection * (0.0/3.0 - 0.5), 0).rgb;
58-
vec3 rgbSamplePosOuter = textureLod(texColor, uv + samplingDirection * (3.0/3.0 - 0.5), 0).rgb;
52+
vec3 rgbSampleNegOuter = textureLod(texColor, uv + samplingDirection * (0/3.0 - 0.5), 0).rgb;
53+
vec3 rgbSamplePosOuter = textureLod(texColor, uv + samplingDirection * (3/3.0 - 0.5), 0).rgb;
5954
vec3 rgbFourTab = (rgbSamplePosOuter + rgbSampleNegOuter) * 0.25 + rgbTwoTab * 0.5;
6055
float lumaFourTab = dot(rgbFourTab, toLuma);
6156
if (lumaFourTab < lumaMin || lumaFourTab > lumaMax)
62-
outColor = vec4(rgbTwoTab, 1.0);
57+
outColor = vec4(rgbTwoTab, 1);
6358
else
64-
outColor = vec4(rgbFourTab, 1.0);
65-
66-
if (false)
67-
outColor.r = 1.0;
59+
outColor = vec4(rgbFourTab, 1);
6860
}

data/cage/shaders/effects/gaussianBlur.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ layout(location = 1) uniform int uniLodLevel;
1919

2020
void main()
2121
{
22-
vec2 texelSize = 1.0 / textureSize(texInput, uniLodLevel).xy;
22+
vec2 texelSize = 1 / vec2(textureSize(texInput, uniLodLevel));
2323
vec2 center = gl_FragCoord.xy;
2424
vec4 val = textureLod(texInput, center * texelSize, uniLodLevel) * weights[0];
2525
for(int i = 1; i < 3; i++)

data/cage/shaders/effects/sharpening.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ layout(std140, binding = CAGE_SHADER_UNIBLOCK_CUSTOMDATA) uniform Sharpening
1212
vec4 params; // strength
1313
};
1414

15-
out vec3 outColor;
15+
out vec4 outColor;
1616

1717
void main()
1818
{
@@ -24,5 +24,5 @@ void main()
2424
vec3 right = texelFetch(texColor, coord + ivec2(1, 0), 0).rgb;
2525
float strength = params.x;
2626
vec3 sharpenedColor = center * (1 + 4 * strength) - (up + down + left + right) * strength;
27-
outColor = clamp(sharpenedColor, 0, 1);
27+
outColor = vec4(clamp(sharpenedColor, 0, 1), 1);
2828
}

data/cage/shaders/effects/tonemap.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ layout(std140, binding = CAGE_SHADER_UNIBLOCK_CUSTOMDATA) uniform Tonemap
1212
vec4 params; // gamma, tonemapEnabled
1313
};
1414

15-
out vec3 outColor;
15+
out vec4 outColor;
1616

1717
// https://github.com/KhronosGroup/ToneMapping/blob/main/PBR_Neutral/pbrNeutral.glsl
1818
vec3 neutralToneMapping(vec3 color)
@@ -42,5 +42,5 @@ void main()
4242
// gamma correction
4343
color = pow(color, vec3(params[0]));
4444

45-
outColor = color;
45+
outColor = vec4(color, 1);
4646
}

0 commit comments

Comments
 (0)