diff --git a/features/Dynamic Cubemaps - Metals/textures/1NGArmor/mushroom04_e.dds b/features/Dynamic Cubemaps - Metals/textures/1NGArmor/mushroom04_e.dds deleted file mode 100644 index 8398136be..000000000 Binary files a/features/Dynamic Cubemaps - Metals/textures/1NGArmor/mushroom04_e.dds and /dev/null differ diff --git a/features/Dynamic Cubemaps - Metals/textures/1WR/ingotiron01_e.dds b/features/Dynamic Cubemaps - Metals/textures/1WR/ingotiron01_e.dds deleted file mode 100644 index 8398136be..000000000 Binary files a/features/Dynamic Cubemaps - Metals/textures/1WR/ingotiron01_e.dds and /dev/null differ diff --git a/features/Dynamic Cubemaps - Metals/textures/1WR/mushroom04_e.dds b/features/Dynamic Cubemaps - Metals/textures/1WR/mushroom04_e.dds deleted file mode 100644 index 8398136be..000000000 Binary files a/features/Dynamic Cubemaps - Metals/textures/1WR/mushroom04_e.dds and /dev/null differ diff --git a/features/Dynamic Cubemaps - Metals/textures/1YsmirArmor/ingotiron01_e.dds b/features/Dynamic Cubemaps - Metals/textures/1YsmirArmor/ingotiron01_e.dds deleted file mode 100644 index 8398136be..000000000 Binary files a/features/Dynamic Cubemaps - Metals/textures/1YsmirArmor/ingotiron01_e.dds and /dev/null differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/AMBEbonyGold_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/AMBEbonyGold_e.dds deleted file mode 100644 index 13b6c13bb..000000000 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/AMBEbonyGold_e.dds and /dev/null differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/AMBEbony_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/AMBEbony_e.dds deleted file mode 100644 index 0f44edbf1..000000000 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/AMBEbony_e.dds and /dev/null differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/Ceramic.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/Ceramic.dds deleted file mode 100644 index 56f8f4391..000000000 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/Ceramic.dds and /dev/null differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/Orcish_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/Orcish_e.dds index aa2d00d12..3bc8ac177 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/Orcish_e.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/Orcish_e.dds differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Dull_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Dull_e.dds index 8398136be..6767de9e1 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Dull_e.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Dull_e.dds differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Ebony_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Ebony_e.dds index 33c310f7b..07c05b4c7 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Ebony_e.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Ebony_e.dds differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Elven_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Elven_e.dds index a6a4aadd6..85d081ece 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Elven_e.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Elven_e.dds differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Iron_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Iron_e.dds index 8398136be..4137c7d3a 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Iron_e.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Iron_e.dds differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Shiny_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Shiny_e.dds index ba7a6a613..f514b52a1 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Shiny_e.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Shiny_e.dds differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Steel_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Steel_e.dds index fd9b35131..0d388baef 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Steel_e.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/SR_Steel_e.dds differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/Silver_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/Silver_e.dds index 1e0f29f74..95a98eaf1 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/Silver_e.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/Silver_e.dds differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/bleakfallscube_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/bleakfallscube_e.dds deleted file mode 100644 index 98b48c214..000000000 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/bleakfallscube_e.dds and /dev/null differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/bloodshinybright_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/bloodshinybright_e.dds deleted file mode 100644 index 74266fba6..000000000 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/bloodshinybright_e.dds and /dev/null differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/bronze_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/bronze_e.dds index 276ddb659..0d75ace07 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/bronze_e.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/bronze_e.dds differ diff --git a/features/Dynamic Cubemaps - Metals/textures/1FlutedArmor/ore_iron_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/caveicecubemap_e.dds similarity index 84% rename from features/Dynamic Cubemaps - Metals/textures/1FlutedArmor/ore_iron_e.dds rename to features/Dynamic Cubemaps - Metals/textures/cubemaps/caveicecubemap_e.dds index 8398136be..d3d3c7ff2 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/1FlutedArmor/ore_iron_e.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/caveicecubemap_e.dds differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/chitin_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/chitin_e.dds index ce46c17ab..4673db108 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/chitin_e.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/chitin_e.dds differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/chitin_e_ebony.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/chitin_e_ebony.dds index fa1bbc7a0..df4ed52e9 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/chitin_e_ebony.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/chitin_e_ebony.dds differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/chrome_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/chrome_e.dds deleted file mode 100644 index 98b48c214..000000000 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/chrome_e.dds and /dev/null differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/copper_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/copper_e.dds index 276ddb659..0d75ace07 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/copper_e.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/copper_e.dds differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/eyecubemap.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/eyecubemap.dds deleted file mode 100644 index 74266fba6..000000000 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/eyecubemap.dds and /dev/null differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/guard.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/guard.dds deleted file mode 100644 index 1e0f29f74..000000000 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/guard.dds and /dev/null differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/guard_gold.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/guard_gold.dds deleted file mode 100644 index a6a4aadd6..000000000 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/guard_gold.dds and /dev/null differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/quicksky_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/quicksky_e.dds index 98b48c214..70a70bd20 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/quicksky_e.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/quicksky_e.dds differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/quickskydark_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/quickskydark_e.dds index 98b48c214..70a70bd20 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/quickskydark_e.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/quickskydark_e.dds differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinybright_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinybright_e.dds index 98b48c214..f514b52a1 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinybright_e.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinybright_e.dds differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinycontrast_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinycontrast_e.dds index 98b48c214..33b486151 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinycontrast_e.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinycontrast_e.dds differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinydull_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinydull_e.dds deleted file mode 100644 index 35774fe55..000000000 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinydull_e.dds and /dev/null differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinydullds_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinydullds_e.dds deleted file mode 100644 index 35774fe55..000000000 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinydullds_e.dds and /dev/null differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinyglass_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinyglass_e.dds index 74266fba6..6767de9e1 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinyglass_e.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinyglass_e.dds differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinyglass_e2.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinyglass_e2.dds deleted file mode 100644 index 74266fba6..000000000 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/shinyglass_e2.dds and /dev/null differ diff --git a/features/Dynamic Cubemaps - Metals/textures/1Infantryman/bleakfallscube_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/simplegrey_e.dds similarity index 84% rename from features/Dynamic Cubemaps - Metals/textures/1Infantryman/bleakfallscube_e.dds rename to features/Dynamic Cubemaps - Metals/textures/cubemaps/simplegrey_e.dds index 8398136be..2af1c6a92 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/1Infantryman/bleakfallscube_e.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/simplegrey_e.dds differ diff --git a/features/Dynamic Cubemaps - Metals/textures/cubemaps/testsky_e.dds b/features/Dynamic Cubemaps - Metals/textures/cubemaps/testsky_e.dds index 1c1bed15b..6767de9e1 100644 Binary files a/features/Dynamic Cubemaps - Metals/textures/cubemaps/testsky_e.dds and b/features/Dynamic Cubemaps - Metals/textures/cubemaps/testsky_e.dds differ diff --git a/features/Dynamic Cubemaps/Shaders/DynamicCubemaps/DynamicCubemaps.hlsli b/features/Dynamic Cubemaps/Shaders/DynamicCubemaps/DynamicCubemaps.hlsli index f81b3e9c5..0296ce3d1 100644 --- a/features/Dynamic Cubemaps/Shaders/DynamicCubemaps/DynamicCubemaps.hlsli +++ b/features/Dynamic Cubemaps/Shaders/DynamicCubemaps/DynamicCubemaps.hlsli @@ -1,18 +1,30 @@ TextureCube specularTexture : register(t64); // https://www.unrealengine.com/en-US/blog/physically-based-shading-on-mobile -float2 EnvBRDFApprox(float3 F0, float Roughness, float NoV) +half2 EnvBRDFApprox(half Roughness, half NoV) { - const float4 c0 = { -1, -0.0275, -0.572, 0.022 }; - const float4 c1 = { 1, 0.0425, 1.04, -0.04 }; - float4 r = Roughness * c0 + c1; - float a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y; - float2 AB = float2(-1.04, 1.04) * a004 + r.zw; + const half4 c0 = { -1, -0.0275, -0.572, 0.022 }; + const half4 c1 = { 1, 0.0425, 1.04, -0.04 }; + half4 r = Roughness * c0 + c1; + half a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y; + half2 AB = half2(-1.04, 1.04) * a004 + r.zw; return AB; } #if !defined(WATER) -float3 GetDynamicCubemap(float2 uv, float3 N, float3 VN, float3 V, float roughness, float3 F0, float complexMaterial) + +# if defined(CREATOR) +struct CreatorSettingsCB +{ + uint Enabled; + uint pad0[3]; + float4 CubemapColor; +}; + +StructuredBuffer perFrameCreator : register(t65); +# endif + +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,9 +34,11 @@ 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.5; + + specularIrradiance = lerp(specularIrradiance, diffuseColor, saturate(distance / 1000.0)); - float2 specularBRDF = EnvBRDFApprox(F0, roughness, NoV); + float2 specularBRDF = EnvBRDFApprox(roughness, NoV); // Horizon specular occlusion // https://marmosetco.tumblr.com/post/81245981087 @@ -36,6 +50,28 @@ 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); +} + +float3 GetDynamicCubemapFresnel(float2 uv, float3 N, float3 VN, float3 V, float roughness, float distance) +{ + float NoV = saturate(dot(N, V)); + float2 specularBRDF = EnvBRDFApprox(roughness, NoV); + if (specularBRDF.y > 0.001) { + float level = roughness * 9.0; + float3 R = reflect(-V, N); + + float3 specularIrradiance = specularTexture.SampleLevel(SampColorSampler, R, level); + specularIrradiance = sRGB2Lin(specularIrradiance); + specularIrradiance = specularIrradiance * (1.0 - saturate(distance / 1000.0)); + + // Horizon specular occlusion + // https://marmosetco.tumblr.com/post/81245981087 + float horizon = min(1.0 + dot(R, VN), 1.0); + specularIrradiance *= horizon * horizon; + + return specularIrradiance * specularBRDF.y; + } + return 0.0; } #endif diff --git a/features/Dynamic Cubemaps/Shaders/DynamicCubemaps/InferCubemapCS.hlsl b/features/Dynamic Cubemaps/Shaders/DynamicCubemaps/InferCubemapCS.hlsl index df1816b5f..5ee383e26 100644 --- a/features/Dynamic Cubemaps/Shaders/DynamicCubemaps/InferCubemapCS.hlsl +++ b/features/Dynamic Cubemaps/Shaders/DynamicCubemaps/InferCubemapCS.hlsl @@ -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); diff --git a/features/Dynamic Cubemaps/Shaders/DynamicCubemaps/UpdateCubemapCS.hlsl b/features/Dynamic Cubemaps/Shaders/DynamicCubemaps/UpdateCubemapCS.hlsl index 56dfc0fdb..4f509f2bd 100644 --- a/features/Dynamic Cubemaps/Shaders/DynamicCubemaps/UpdateCubemapCS.hlsl +++ b/features/Dynamic Cubemaps/Shaders/DynamicCubemaps/UpdateCubemapCS.hlsl @@ -204,7 +204,7 @@ float smoothbumpstep(float edge0, float edge1, float x) float4 color = DynamicCubemapRaw[ThreadID]; float distanceFactor = sqrt(smoothbumpstep(0.0, 1.0, length(position.xyz))); - color *= max(distanceFactor, position.w); + color *= max(0.01, max(distanceFactor, position.w)); DynamicCubemap[ThreadID] = max(0, color); } diff --git a/package/Shaders/Lighting.hlsl b/package/Shaders/Lighting.hlsl index 3d497e2a0..240d48833 100644 --- a/package/Shaders/Lighting.hlsl +++ b/package/Shaders/Lighting.hlsl @@ -1781,7 +1781,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace float3 nsLightColor = lightColor; float3 normalizedLightDirection = normalize(lightDirection); - [branch] if (!FrameParams.z && FrameParams.y && (light.firstPersonShadow || perPassLLF[0].EnableContactShadows) && shadowComponent != 0.0) + [branch] if (perPassLLF[0].EnableGlobalLights && !FrameParams.z && FrameParams.y && (light.firstPersonShadow || perPassLLF[0].EnableContactShadows) && shadowComponent != 0.0) { float3 normalizedLightDirectionVS = normalize(light.positionVS[eyeIndex].xyz - viewPosition.xyz); float contactShadow = ContactShadows(viewPosition, screenUV, screenNoise, normalizedLightDirectionVS, light.radius, light.firstPersonShadow, eyeIndex); @@ -1880,39 +1880,50 @@ 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; -# else + float3 F0 = 0.0; + float envRoughness = 1.0; + uint2 envSize; TexEnvSampler.GetDimensions(envSize.x, envSize.y); - bool dynamicCubemap = envMask != 0 && envSize.x == 1; + + bool dynamicCubemap = false; + [flatten] if (envMask != 0 && envSize.x == 1) + { + dynamicCubemap = true; + envColorBase = TexEnvSampler.SampleLevel(SampEnvSampler, float3(1.0, 0.0, 0.0), 0); + if (envColorBase.a < 1.0) { + F0 = sRGB2Lin(envColorBase.rgb) + sRGB2Lin(baseColor.rgb); + envRoughness = envColorBase.a; + } else { + F0 = 1.0; + envRoughness = 1.0 / 9.0; + } + } + +# if defined(CREATOR) + if (perFrameCreator[0].Enabled) { + dynamicCubemap = true; + F0 = sRGB2Lin(perFrameCreator[0].CubemapColor.rgb) + sRGB2Lin(baseColor.xyz); + envRoughness = perFrameCreator[0].CubemapColor.a; + } +# endif + 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); +# 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; - 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; -# endif 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) @@ -2004,6 +2015,22 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace color.xyz += wetnessSpecular * wetnessGlossinessSpecular; # endif +# if defined(DYNAMIC_CUBEMAPS) +# if defined(EYE) + color.xyz += GetDynamicCubemapFresnel(screenUV, worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, 1.0 / 9.0, viewPosition.z) * input.Color.xyz * envMask; +# elif defined(ENVMAP) || defined(MULTI_LAYER_PARALLAX) + color.xyz += 0.25 * GetDynamicCubemapFresnel(screenUV, worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, (2.0 - saturate(envMask)) / 9.0, viewPosition.z) * (1.0 - ((float)dynamicCubemap * saturate(envMask))) * input.Color.xyz; +# elif defined(HAIR) + color.xyz += 0.25 * GetDynamicCubemapFresnel(screenUV, worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, 2.0 / 9.0, viewPosition.z); +# else + color.xyz += 0.25 * GetDynamicCubemapFresnel(screenUV, worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, 2.0 / 9.0, viewPosition.z) * input.Color.xyz; +# endif +# endif + +# if defined(EYE) + color.xyz *= saturate(normalize(input.EyeNormal2.xyz).y); // Occlusion +# endif + # if defined(WATER_CAUSTICS) color.xyz *= ComputeWaterCaustics(waterHeight, input.WorldPosition.xyz, worldSpaceNormal); # endif @@ -2020,7 +2047,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) @@ -2115,8 +2142,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace } # endif // WATER_BLENDING - psout.ScreenSpaceNormals.w = 0.0; - # if (defined(ENVMAP) || defined(MULTI_LAYER_PARALLAX) || defined(EYE)) # if defined(DYNAMIC_CUBEMAPS) psout.ScreenSpaceNormals.w = saturate(sqrt(envMask)); @@ -2175,12 +2200,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace # endif # endif -# if defined(EYE) - float eyeCurve = saturate(normalize(input.EyeNormal2.xyz).y); // Occlusion - float eyeCenter = pow(eyeCurve, 150); // Iris - psout.Albedo.xyz *= eyeCurve + eyeCenter; -# endif - # if defined(OUTLINE) psout.Albedo = float4(1, 0, 0, 1); # endif // OUTLINE diff --git a/src/Features/DynamicCubemaps.cpp b/src/Features/DynamicCubemaps.cpp index 8b819ba4e..07a9d925d 100644 --- a/src/Features/DynamicCubemaps.cpp +++ b/src/Features/DynamicCubemaps.cpp @@ -1,4 +1,5 @@ #include "DynamicCubemaps.h" +#include #include constexpr auto MIPLEVELS = 10; @@ -32,6 +33,73 @@ void DynamicCubemaps::DrawSettings() ImGui::EndTable(); } } + + if (ImGui::TreeNodeEx("Dynamic Cubemap Creator", ImGuiTreeNodeFlags_DefaultOpen)) { + ImGui::Text("You must enable creator mode by adding the shader define CREATOR"); + ImGui::Checkbox("Enable Creator", &enableCreator); + if (enableCreator) { + ImGui::ColorEdit3("Color", (float*)&cubemapColor); + ImGui::SliderFloat("Roughness", &cubemapColor.w, 0.0f, 1.0f, "%.2f"); + if (ImGui::Button("Export")) { + auto renderer = RE::BSGraphics::Renderer::GetSingleton(); + auto device = renderer->GetRuntimeData().forwarder; + auto context = renderer->GetRuntimeData().context; + + D3D11_TEXTURE2D_DESC texDesc{}; + texDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + texDesc.Height = 1; + texDesc.Width = 1; + texDesc.ArraySize = 6; + texDesc.MipLevels = 1; + texDesc.SampleDesc.Count = 1; + texDesc.Usage = D3D11_USAGE_DEFAULT; + texDesc.BindFlags = 0; + texDesc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE; + + D3D11_SUBRESOURCE_DATA subresourceData[6]; + + struct PixelData + { + uint8_t r, g, b, a; + }; + + static PixelData colorPixel{}; + + colorPixel = { (uint8_t)((cubemapColor.x * 255.0f) + 0.5f), + (uint8_t)((cubemapColor.y * 255.0f) + 0.5f), + (uint8_t)((cubemapColor.z * 255.0f) + 0.5f), + std::min((uint8_t)254u, (uint8_t)((cubemapColor.w * 255.0f) + 0.5f)) }; + + static PixelData emptyPixel{}; + + subresourceData[0].pSysMem = &colorPixel; + subresourceData[0].SysMemPitch = sizeof(PixelData); + subresourceData[0].SysMemSlicePitch = sizeof(PixelData); + + for (uint i = 1; i < 6; i++) { + subresourceData[i].pSysMem = &emptyPixel; + subresourceData[i].SysMemPitch = sizeof(PixelData); + subresourceData[i].SysMemSlicePitch = sizeof(PixelData); + } + + ID3D11Texture2D* tempTexture; + DX::ThrowIfFailed(device->CreateTexture2D(&texDesc, subresourceData, &tempTexture)); + + DirectX::ScratchImage image; + DX::ThrowIfFailed(CaptureTexture(device, context, tempTexture, image)); + + std::string filename = std::format("Data\\Textures\\DynamicCubemaps\\{:.2f}{:.2f}{:.2f}R{:.2f}.dds", cubemapColor.x, cubemapColor.y, cubemapColor.z, cubemapColor.w); + + std::wstring wfilename = std::wstring(filename.begin(), filename.end()); + DX::ThrowIfFailed(SaveToDDSFile(image.GetImages(), image.GetImageCount(), image.GetMetadata(), DirectX::DDS_FLAGS::DDS_FLAGS_NONE, wfilename.c_str())); + + image.Release(); + tempTexture->Release(); + } + } + ImGui::TreePop(); + } + ImGui::Spacing(); ImGui::Spacing(); @@ -300,7 +368,7 @@ void DynamicCubemaps::UpdateCubemap() const SpecularMapFilterSettingsCB spmapConstants = { level * delta_roughness }; spmapCB->Update(spmapConstants); - auto uav = uavArray[level - 1].get(); + auto uav = uavArray[level - 1]; context->CSSetUnorderedAccessViews(0, 1, &uav, nullptr); context->Dispatch(numGroups, numGroups, 6); @@ -333,8 +401,22 @@ void DynamicCubemaps::Draw(const RE::BSShader* shader, const uint32_t) auto renderer = RE::BSGraphics::Renderer::GetSingleton(); auto context = renderer->GetRuntimeData().context; - ID3D11ShaderResourceView* view = envTexture->srv.get(); - context->PSSetShaderResources(64, 1, &view); + if (enableCreator) { + CreatorSettingsCB data{}; + data.Enabled = true; + data.CubemapColor = cubemapColor; + + D3D11_MAPPED_SUBRESOURCE mapped; + DX::ThrowIfFailed(context->Map(perFrameCreator->resource.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped)); + size_t bytes = sizeof(CreatorSettingsCB); + memcpy_s(mapped.pData, bytes, &data, bytes); + context->Unmap(perFrameCreator->resource.get(), 0); + } + + ID3D11ShaderResourceView* views[2]; + views[0] = envTexture->srv.get(); + views[1] = enableCreator ? perFrameCreator->srv.get() : nullptr; + context->PSSetShaderResources(64, 2, views); } } } @@ -458,9 +540,27 @@ void DynamicCubemaps::SetupResources() for (std::uint32_t level = 1; level < MIPLEVELS; ++level) { uavDesc.Texture2DArray.MipSlice = level; - DX::ThrowIfFailed(device->CreateUnorderedAccessView(envTexture->resource.get(), &uavDesc, uavArray[level - 1].put())); + DX::ThrowIfFailed(device->CreateUnorderedAccessView(envTexture->resource.get(), &uavDesc, &uavArray[level - 1])); } } + + { + D3D11_BUFFER_DESC sbDesc{}; + sbDesc.Usage = D3D11_USAGE_DYNAMIC; + sbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + sbDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + sbDesc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; + sbDesc.StructureByteStride = sizeof(CreatorSettingsCB); + sbDesc.ByteWidth = sizeof(CreatorSettingsCB); + perFrameCreator = std::make_unique(sbDesc); + + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; + srvDesc.Format = DXGI_FORMAT_UNKNOWN; + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; + srvDesc.Buffer.FirstElement = 0; + srvDesc.Buffer.NumElements = 1; + perFrameCreator->CreateSRV(srvDesc); + } } void DynamicCubemaps::Reset() diff --git a/src/Features/DynamicCubemaps.h b/src/Features/DynamicCubemaps.h index f40a2711e..9d9146c77 100644 --- a/src/Features/DynamicCubemaps.h +++ b/src/Features/DynamicCubemaps.h @@ -34,7 +34,7 @@ struct DynamicCubemaps : Feature ID3D11ComputeShader* specularIrradianceCS = nullptr; ConstantBuffer* spmapCB = nullptr; Texture2D* envTexture = nullptr; - winrt::com_ptr uavArray[9]; + ID3D11UnorderedAccessView* uavArray[9]; // Reflection capture @@ -70,6 +70,20 @@ struct DynamicCubemaps : Feature ID3D11UnorderedAccessView* cubemapUAV; + // Editor window + + bool enableCreator = false; + float4 cubemapColor{ 1.0f, 1.0f, 1.0f, 0.0f }; + + struct alignas(16) CreatorSettingsCB + { + uint Enabled; + uint pad0[3]; + float4 CubemapColor; + }; + + std::unique_ptr perFrameCreator = nullptr; + void UpdateCubemap(); virtual inline std::string GetName() { return "Dynamic Cubemaps"; }