Skip to content
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

feat: revised dynamic cubemaps #218

Merged
merged 9 commits into from
Mar 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: revised dynamic cubemaps
doodlum committed Mar 13, 2024

Verified

This commit was signed with the committer’s verified signature.
amimart Arnaud Mimart
commit 44731029b143fbd9e8510e599dfe34f62691d4b4
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified features/Dynamic Cubemaps - Metals/textures/1WR/ingotiron01_e.dds
Binary file not shown.
Binary file modified features/Dynamic Cubemaps - Metals/textures/1WR/mushroom04_e.dds
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified features/Dynamic Cubemaps - Metals/textures/cubemaps/AMBEbony_e.dds
Binary file not shown.
Binary file modified features/Dynamic Cubemaps - Metals/textures/cubemaps/Ceramic.dds
Binary file not shown.
Binary file modified features/Dynamic Cubemaps - Metals/textures/cubemaps/Orcish_e.dds
Binary file not shown.
Binary file modified features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Dull_e.dds
Binary file not shown.
Binary file modified features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Ebony_e.dds
Binary file not shown.
Binary file modified features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Elven_e.dds
Binary file not shown.
Binary file modified features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Iron_e.dds
Binary file not shown.
Binary file modified features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Shiny_e.dds
Binary file not shown.
Binary file modified features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Steel_e.dds
Binary file not shown.
Binary file modified features/Dynamic Cubemaps - Metals/textures/cubemaps/Silver_e.dds
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified features/Dynamic Cubemaps - Metals/textures/cubemaps/bronze_e.dds
Binary file not shown.
Binary file modified features/Dynamic Cubemaps - Metals/textures/cubemaps/chitin_e.dds
Binary file not shown.
Binary file not shown.
Binary file modified features/Dynamic Cubemaps - Metals/textures/cubemaps/chrome_e.dds
Binary file not shown.
Binary file modified features/Dynamic Cubemaps - Metals/textures/cubemaps/copper_e.dds
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified features/Dynamic Cubemaps - Metals/textures/cubemaps/guard.dds
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified features/Dynamic Cubemaps - Metals/textures/cubemaps/testsky_e.dds
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ float2 EnvBRDFApprox(float3 F0, float Roughness, float NoV)
}

#if !defined(WATER)
float3 GetDynamicCubemap(float2 uv, float3 N, float3 VN, float3 V, float roughness, float3 F0, float complexMaterial)
float3 GetDynamicCubemap(float2 uv, float3 N, float3 VN, float3 V, float roughness, float3 F0, float3 diffuseColor, float distance)
{
float3 R = reflect(-V, N);
float NoV = saturate(dot(N, V));
@@ -22,7 +22,9 @@ float3 GetDynamicCubemap(float2 uv, float3 N, float3 VN, float3 V, float roughne
float3 specularIrradiance = specularTexture.SampleLevel(SampColorSampler, R, level);
specularIrradiance = sRGB2Lin(specularIrradiance);

F0 = sRGB2Lin(F0);
diffuseColor = sRGB2Lin(diffuseColor * 0.25);

specularIrradiance = lerp(specularIrradiance, diffuseColor, saturate(distance / 1000.0));

float2 specularBRDF = EnvBRDFApprox(F0, roughness, NoV);

@@ -36,6 +38,6 @@ float3 GetDynamicCubemap(float2 uv, float3 N, float3 VN, float3 V, float roughne
float3 Fr = max(1.0.xxx - roughness.xxx, F0) - F0;
float3 S = Fr * pow(1.0 - NoV, 5.0);

return lerp(specularIrradiance * F0, specularIrradiance * ((F0 * S) * specularBRDF.x + specularBRDF.y), complexMaterial);
return specularIrradiance * ((F0 + S) * specularBRDF.x + specularBRDF.y);
}
#endif
Original file line number Diff line number Diff line change
@@ -127,8 +127,6 @@ float noise(in float3 p)

#if defined(REFLECTIONS)
color.rgb = lerp(color.rgb, sRGB2Lin(EnvReflectionsTexture[ThreadID]), saturate(mipLevel * (1.0 / 10.0)));
#else
color.rgb = lerp(color.rgb, max(float3(0.0, 0.0, 0.0), color.rgb * noise(uv * 5.0)), mipLevel * (1.0 / 10.0));
#endif

color.rgb = Lin2sRGB(color.rgb);
47 changes: 27 additions & 20 deletions package/Shaders/Lighting.hlsl
Original file line number Diff line number Diff line change
@@ -1880,38 +1880,45 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
float envMask = (EnvmapData.y * (envMaskColor - glossiness) + glossiness) * (EnvmapData.x * MaterialData.x);
float viewNormalAngle = dot(worldSpaceNormal.xyz, viewDirection);
float3 envSamplingPoint = (viewNormalAngle * 2) * modelNormal.xyz - viewDirection;
float3 envColorBase = TexEnvSampler.Sample(SampEnvSampler, envSamplingPoint).xyz;
float4 envColorBase = TexEnvSampler.Sample(SampEnvSampler, envSamplingPoint);
float3 envColor = envColorBase * envMask;
# if defined(DYNAMIC_CUBEMAPS)
# if defined(EYE)
bool dynamicCubemap = true;
envColor = GetDynamicCubemap(screenUV, worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, 1.0 / 9.0, 0.25, true) * envMask;
envColor = GetDynamicCubemap(screenUV, worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, 1.0 / 9.0, 0.25, diffuseColor, viewPosition.z) * envMask;
# else
float3 F0 = 0.0;
float envRoughness = 1.0;

uint2 envSize;
TexEnvSampler.GetDimensions(envSize.x, envSize.y);
bool dynamicCubemap = envMask != 0 && envSize.x == 1;
if (dynamicCubemap) {
# if defined(CPM_AVAILABLE) && defined(ENVMAP)
float3 F0 = lerp(envColorBase, 1.0, envColorBase.x == 0.0 && envColorBase.y == 0.0 && envColorBase.z == 0.0);

envColor = GetDynamicCubemap(screenUV, worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, lerp(1.0 / 9.0, 1.0 - complexMaterialColor.y, complexMaterial), lerp(F0, complexSpecular, complexMaterial), complexMaterial) * envMask;
# else
float3 F0 = lerp(envColorBase, 1.0, envColorBase.x == 0.0 && envColorBase.y == 0.0 && envColorBase.z == 0.0);
envColor = GetDynamicCubemap(screenUV, worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, 1.0 / 9.0, F0, 0.0) * envMask;
bool dynamicCubemap = false;
[flatten] if (envMask != 0 && envSize.x == 1)
{
dynamicCubemap = true;
F0 = 1.0;
envRoughness = 1.0 / 9.0;
} else if (envColorBase.a < (1.0 - (4.0 / 255.0))){
dynamicCubemap = true;
F0 = (sRGB2Lin(envColorBase * 2.5)) + baseColor.xyz;
envRoughness = envColorBase.a;
}

if (dynamicCubemap)
{
# if defined(CPM_AVAILABLE)
envRoughness = lerp(envRoughness, 1.0 - complexMaterialColor.y, (float)complexMaterial);
F0 = lerp(F0, sRGB2Lin(complexSpecular), (float)complexMaterial);
# endif

envColor = GetDynamicCubemap(screenUV, worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, envRoughness, F0, diffuseColor, viewPosition.z) * envMask;

if (shaderDescriptors[0].PixelShaderDescriptor & _DefShadow && shaderDescriptors[0].PixelShaderDescriptor & _ShadowDir) {
float upAngle = saturate(dot(float3(0, 0, 1), normalizedDirLightDirectionWS.xyz));
envColor *= lerp(1.0, shadowColor.x, saturate(upAngle) * 0.2);
envColor *= lerp(1.0, shadowColor.x, saturate(upAngle) / 3.0);
}
}
# if !defined(VR)
// else if (envMask > 0.0 && !FrameParams.z && FrameParams.y) {
// float4 ssrBlurred = ssrTexture.SampleLevel(SampColorSampler, screenUV, 0);
// float4 ssrRaw = ssrRawTexture.SampleLevel(SampColorSampler, screenUV, 0);
// float4 ssrTexture = lerp(ssrRaw, ssrBlurred, 1.0 - saturate(envMask));
// envColor = lerp(envColor, ssrTexture.rgb * envColor * 10, ssrTexture.a);
// }
# endif
# endif
# endif
# endif // defined (ENVMAP) || defined (MULTI_LAYER_PARALLAX) || defined(EYE)
@@ -2020,7 +2027,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
# endif // defined (SPECULAR) || defined(SPARKLE)

# if defined(ENVMAP) && defined(TESTCUBEMAP)
color.xyz = specularTexture.SampleLevel(SampEnvSampler, envSamplingPoint, 0).xyz;
color.xyz = specularTexture.SampleLevel(SampEnvSampler, envSamplingPoint, 1).xyz;
# endif

# if defined(LANDSCAPE) && !defined(LOD_LAND_BLEND)