|
|
@@ -92,20 +92,19 @@ void appendDecalColors(in Decal decal, in vec3 worldPos, inout vec3 diffuseColor
|
|
|
vec2 texCoords2 = texCoords4.xy / texCoords4.w;
|
|
|
|
|
|
// Clamp the tex coords. Expect a border in the texture atlas
|
|
|
- texCoords2 = clamp(texCoords2, 0.0, 1.0);
|
|
|
+ texCoords2 = saturate(texCoords2);
|
|
|
|
|
|
- vec2 diffUv = texCoords2 * decal.diffUv.zw + decal.diffUv.xy;
|
|
|
+ vec2 diffUv = mad(texCoords2, decal.diffUv.zw, decal.diffUv.xy);
|
|
|
vec4 dcol = texture(u_diffDecalTex, diffUv);
|
|
|
diffuseColor = mix(diffuseColor, dcol.rgb, dcol.a * decal.blendFactors[0]);
|
|
|
|
|
|
// Roughness
|
|
|
- vec2 roughnessUv = texCoords2 * decal.normRoughnessUv.zw + decal.normRoughnessUv.xy;
|
|
|
+ vec2 roughnessUv = mad(texCoords2, decal.normRoughnessUv.zw, decal.normRoughnessUv.xy);
|
|
|
float r = texture(u_normalRoughnessDecalTex, roughnessUv).w;
|
|
|
roughness = mix(roughness, r, dcol.a * decal.blendFactors[1]);
|
|
|
}
|
|
|
|
|
|
-void readIndirect(
|
|
|
- in uint idxOffset, in vec3 pos, in vec3 r, in vec3 n, in float lod, out vec3 specIndirect, out vec3 diffIndirect)
|
|
|
+void readIndirect(uint idxOffset, vec3 pos, vec3 r, vec3 n, float lod, out vec3 specIndirect, out vec3 diffIndirect)
|
|
|
{
|
|
|
specIndirect = vec3(0.0);
|
|
|
diffIndirect = vec3(0.0);
|
|
|
@@ -138,7 +137,7 @@ void readIndirect(
|
|
|
|
|
|
// Do the same for diffuse
|
|
|
uv = computeCubemapVecAccurate(n, R2, f);
|
|
|
- vec3 id = texture(u_irradianceTex, vec4(uv, cubemapIndex)).rgb;
|
|
|
+ vec3 id = textureLod(u_irradianceTex, vec4(uv, cubemapIndex), 0.0).rgb;
|
|
|
diffIndirect = mix(id, diffIndirect, factor);
|
|
|
}
|
|
|
}
|
|
|
@@ -149,11 +148,8 @@ void main()
|
|
|
vec2 ndc = UV_TO_NDC(in_uv);
|
|
|
|
|
|
// Get world position
|
|
|
- vec3 worldPos;
|
|
|
- {
|
|
|
- vec4 worldPos4 = u_invViewProjMat * vec4(ndc, depth, 1.0);
|
|
|
- worldPos = worldPos4.xyz / worldPos4.w;
|
|
|
- }
|
|
|
+ vec4 worldPos4 = u_invViewProjMat * vec4(ndc, depth, 1.0);
|
|
|
+ vec3 worldPos = worldPos4.xyz / worldPos4.w;
|
|
|
|
|
|
// Decode GBuffer
|
|
|
vec3 normal;
|
|
|
@@ -174,10 +170,6 @@ void main()
|
|
|
subsurface = max(gbuffer.subsurface, SUBSURFACE_MIN);
|
|
|
emission = gbuffer.emission;
|
|
|
|
|
|
- // Get SSAO
|
|
|
- float ssao = texture(u_ssaoTex, in_uv).r;
|
|
|
- diffCol *= ssao;
|
|
|
-
|
|
|
// Get first light index
|
|
|
uint idxOffset;
|
|
|
{
|
|
|
@@ -197,6 +189,10 @@ void main()
|
|
|
appendDecalColors(decal, worldPos, diffCol, roughness);
|
|
|
}
|
|
|
|
|
|
+ // Apply SSAO
|
|
|
+ float ssao = texture(u_ssaoTex, in_uv).r;
|
|
|
+ diffCol *= ssao;
|
|
|
+
|
|
|
// Ambient and emissive color
|
|
|
vec3 outC = diffCol * emission;
|
|
|
|
|
|
@@ -248,19 +244,21 @@ void main()
|
|
|
}
|
|
|
|
|
|
// Indirect
|
|
|
- vec3 eye = -viewDir;
|
|
|
- vec3 reflVec = reflect(eye, normal);
|
|
|
+ {
|
|
|
+ vec3 eye = -viewDir;
|
|
|
+ vec3 reflVec = reflect(eye, normal);
|
|
|
|
|
|
- float reflLod = float(IR_MIPMAP_COUNT) * a2;
|
|
|
+ float reflLod = float(IR_MIPMAP_COUNT - 1u) * a2;
|
|
|
|
|
|
- float ndotv = dot(normal, viewDir);
|
|
|
- vec2 envBRDF = texture(u_integrationLut, vec2(a2, ndotv)).xy;
|
|
|
- vec3 specIndirectTerm = specCol * envBRDF.x + envBRDF.y;
|
|
|
+ vec3 specIndirect, diffIndirect;
|
|
|
+ readIndirect(idxOffset, worldPos, reflVec, normal, reflLod, specIndirect, diffIndirect);
|
|
|
|
|
|
- vec3 specIndirect, diffIndirect;
|
|
|
- readIndirect(idxOffset, worldPos, reflVec, normal, reflLod, specIndirect, diffIndirect);
|
|
|
+ float ndotv = dot(normal, viewDir);
|
|
|
+ vec2 envBRDF = texture(u_integrationLut, vec2(a2, ndotv)).xy;
|
|
|
+ vec3 specIndirectTerm = specCol * envBRDF.x + envBRDF.y;
|
|
|
|
|
|
- outC += specIndirect * specIndirectTerm + diffIndirect * diffCol;
|
|
|
+ outC += specIndirect * specIndirectTerm + diffIndirect * diffCol;
|
|
|
+ }
|
|
|
|
|
|
out_color = outC;
|
|
|
#if 0
|