-
-
Notifications
You must be signed in to change notification settings - Fork 534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
volumetric: Add volumetric lighting #3668
base: master
Are you sure you want to change the base?
Changes from all commits
309df34
ba793f7
03859b0
ea16d23
1e365fe
0907fd0
5e468ff
92e93c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,7 @@ uniform vec4 diffuseLight; | |
uniform vec4 specularLight; | ||
|
||
|
||
uniform vec4 cameraPos; // in modelSpace | ||
//uniform vec4 cameraPos; // in modelSpace | ||
uniform vec4 sunPos; // in modelSpace, normalized | ||
|
||
// fog | ||
|
@@ -148,10 +148,14 @@ vec4 doBumpMapping(BumpData b, vec3 lightDir, vec3 halfVec) { | |
|
||
vec4 res = (b.color*light) + light_spec; | ||
|
||
MaterialInfo materialInfo; | ||
materialInfo.albedo = b.color; | ||
materialInfo.gloss = b.gloss; | ||
|
||
#if WZ_POINT_LIGHT_ENABLED == 1 | ||
// point lights | ||
vec2 clipSpaceCoord = gl_FragCoord.xy / vec2(float(viewportWidth), float(viewportHeight)); | ||
res += iterateOverAllPointLights(clipSpaceCoord, fragPos, b.N, normalize(halfVec - lightDir), b.color, b.gloss, ModelTangentMatrix); | ||
res += iterateOverAllPointLights(clipSpaceCoord, fragPos, b.N, normalize(halfVec - lightDir), materialInfo, ModelTangentMatrix); | ||
#endif | ||
|
||
return vec4(res.rgb, b.color.a); | ||
|
@@ -186,7 +190,13 @@ void main() | |
{ | ||
vec4 fragColor = main_bumpMapping(); | ||
|
||
if (fogEnabled > 0) | ||
if (WZ_VOLUMETRIC_LIGHTING_ENABLED != 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please elaborate why in this particular place the condition is |
||
vec4 lightmap_vec4 = texture(lightmap_tex, uvLightmap, 0.f); | ||
vec2 clipSpaceCoord = gl_FragCoord.xy / vec2(viewportWidth, viewportHeight); | ||
vec4 volumetric = volumetricLights(clipSpaceCoord, cameraPos.xyz, fragPos, diffuseLight.xyz); | ||
fragColor.xyz = toneMap(fragColor.xyz * volumetric.a + volumetric.xyz) * lightmap_vec4.a; | ||
} | ||
else if (fogEnabled > 0) | ||
{ | ||
// Calculate linear fog | ||
float fogFactor = (fogEnd - vertexDistance) / (fogEnd - fogStart); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ layout (constant_id = 1) const uint WZ_SHADOW_MODE = 1; | |
layout (constant_id = 2) const uint WZ_SHADOW_FILTER_SIZE = 5; | ||
layout (constant_id = 3) const uint WZ_SHADOW_CASCADES_COUNT = 3; | ||
layout (constant_id = 4) const uint WZ_POINT_LIGHT_ENABLED = 0; | ||
layout (constant_id = 5) const uint WZ_VOLUMETRIC_LIGHTING_ENABLED = 0; | ||
|
||
layout(set = 1, binding = 0) uniform sampler2D lightmap_tex; | ||
|
||
|
@@ -64,6 +65,10 @@ vec3 blendAddEffectLighting(vec3 a, vec3 b) { | |
} | ||
|
||
vec4 doBumpMapping(BumpData b, vec3 lightDir, vec3 halfVec) { | ||
MaterialInfo materialInfo; | ||
materialInfo.albedo = b.color; | ||
materialInfo.gloss = b.gloss; | ||
|
||
vec3 L = normalize(lightDir); | ||
float lambertTerm = max(dot(b.N, L), 0.0); // diffuse lighting | ||
// Gaussian specular term computation | ||
|
@@ -90,7 +95,7 @@ vec4 doBumpMapping(BumpData b, vec3 lightDir, vec3 halfVec) { | |
{ | ||
// point lights | ||
vec2 clipSpaceCoord = gl_FragCoord.xy / vec2(viewportWidth, viewportHeight); | ||
res += iterateOverAllPointLights(clipSpaceCoord, frag.fragPos, b.N, normalize(halfVec - lightDir), b.color, b.gloss, ModelTangentMatrix); | ||
res += iterateOverAllPointLights(clipSpaceCoord, frag.fragPos, b.N, normalize(halfVec - lightDir), materialInfo, ModelTangentMatrix); | ||
} | ||
|
||
return vec4(res.rgb, b.color.a); | ||
|
@@ -125,7 +130,13 @@ void main() | |
{ | ||
vec4 fragColor = main_bumpMapping(); | ||
|
||
if (fogEnabled > 0) | ||
if (WZ_VOLUMETRIC_LIGHTING_ENABLED != 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
vec4 lightmap_vec4 = texture(lightmap_tex, frag.uvLightmap, 0.f); | ||
vec2 clipSpaceCoord = gl_FragCoord.xy / vec2(viewportWidth, viewportHeight); | ||
vec4 volumetric = volumetricLights(clipSpaceCoord, cameraPos.xyz, frag.fragPos, diffuseLight.xyz); | ||
fragColor.xyz = toneMap(fragColor.xyz * volumetric.a + volumetric.xyz) * lightmap_vec4.a; | ||
} | ||
else if (fogEnabled > 0) | ||
{ | ||
// Calculate linear fog | ||
float fogFactor = (fogEnd - frag.vertexDistance) / (fogEnd - fogStart); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to keep commented code. We can always bring it back via git, if needed.