transparent shadows update

This commit is contained in:
Turanszki Janos
2020-11-25 21:41:19 +01:00
parent 85e729bfab
commit 507f691a0b
7 changed files with 18 additions and 55 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ TEXTURE2D(texture_transmittancelut, float4, TEXSLOT_TRANSMITTANCELUT);
TEXTURE2D(texture_multiscatteringlut, float4, TEXSLOT_MULTISCATTERINGLUT);
TEXTURE2DARRAY(texture_shadowarray_2d, float, TEXSLOT_SHADOWARRAY_2D);
TEXTURECUBEARRAY(texture_shadowarray_cube, float, TEXSLOT_SHADOWARRAY_CUBE);
TEXTURE2DARRAY(texture_shadowarray_transparent, float4, TEXSLOT_SHADOWARRAY_TRANSPARENT);
TEXTURE2DARRAY(texture_shadowarray_transparent, float3, TEXSLOT_SHADOWARRAY_TRANSPARENT);
TEXTURE3D(texture_voxelradiance, float4, TEXSLOT_VOXELRADIANCE);
STRUCTUREDBUFFER(EntityTiles, uint, SBSLOT_ENTITYTILES);
STRUCTUREDBUFFER(EntityArray, ShaderEntity, SBSLOT_ENTITYARRAY);
+3 -11
View File
@@ -61,7 +61,7 @@ inline float3 shadowCascade(in ShaderEntity light, in float3 shadowPos, in float
[loop]
for (float x = -range; x <= range; x += 1.0f)
{
shadow.x += texture_shadowarray_2d.SampleCmpLevelZero(sampler_cmp_depth, float3(shadowUV + float2(x, y) * light.shadowKernel, light.GetShadowMapIndex() + cascade), realDistance).r;
shadow.x += texture_shadowarray_2d.SampleCmpLevelZero(sampler_cmp_depth, float3(shadowUV + float2(x, y) * light.shadowKernel, light.GetShadowMapIndex() + cascade), realDistance);
shadow.y++;
}
}
@@ -73,15 +73,7 @@ inline float3 shadowCascade(in ShaderEntity light, in float3 shadowPos, in float
#ifndef DISABLE_TRANSPARENT_SHADOWMAP
if (g_xFrame_Options & OPTION_BIT_TRANSPARENTSHADOWS_ENABLED)
{
// unfortunately transparents will not receive transparent shadow map
// because we cannot distinguish without using secondary depth buffer for transparents
// but I don't wanna do that, not overly important for now
float4 transparent_shadowmap = texture_shadowarray_transparent.SampleLevel(sampler_linear_clamp, float3(shadowUV, light.GetShadowMapIndex() + cascade), 0).rgba;
// Tint the shadow:
shadow *= transparent_shadowmap.rgb;
// Reduce shadow by caustics (caustics can also increase total light above maximum):
const float causticsStrength = 20;
shadow += transparent_shadowmap.a * causticsStrength;
shadow *= texture_shadowarray_transparent.SampleLevel(sampler_linear_clamp, float3(shadowUV, light.GetShadowMapIndex() + cascade), 0);
}
#endif //DISABLE_TRANSPARENT_SHADOWMAP
@@ -876,4 +868,4 @@ inline float4 EnvironmentReflection_Local(in Surface surface, in ShaderEntity pr
return float4(envmapColor, edgeBlend);
}
#endif // WI_LIGHTING_HF
#endif // WI_LIGHTING_HF
+1 -16
View File
@@ -32,22 +32,7 @@ float4 main(VertextoPixel input) : SV_TARGET
float opacity = color.a;
color.rgb *= 1 - opacity;
// Use the alpha channel for refraction caustics effect:
[branch]
if (g_xMaterial.uvset_normalMap >= 0)
{
float3 bumpColor;
const float2 UV_normalMap = g_xMaterial.uvset_normalMap == 0 ? input.uvsets.xy : input.uvsets.zw;
bumpColor = float3(2.0f * texture_normalmap.Sample(sampler_objectshader, UV_normalMap - g_xMaterial.texMulAdd.ww).rg - 1.0f, 1);
bumpColor.rg *= g_xMaterial.refractionIndex;
bumpColor.rg *= g_xMaterial.normalMapStrength;
bumpColor = normalize(max(bumpColor, float3(0, 0, 0.0001f)));
color.a = 1 - saturate(dot(bumpColor, float3(0, 0, 1)));
}
color.rgb *= 1 - opacity; // if fully opaque, then black (not let through any light)
return color;
}
+7 -6
View File
@@ -32,12 +32,8 @@ float4 main(VertextoPixel input) : SV_TARGET
float opacity = color.a;
// Water does not generate shadows to not mess up the smooth falloff on geometry intersections:
// This could be resolved if this shader could sample depth, but the depthbuffer is currently bound
// so leave it at this for the moment
color.rgb = 1;
color.rgb = 1; // disable water shadow because it has already fog
// Use the alpha channel for refraction caustics effect:
[branch]
if (g_xMaterial.uvset_normalMap >= 0)
{
@@ -53,7 +49,12 @@ float4 main(VertextoPixel input) : SV_TARGET
bumpColor.rg *= g_xMaterial.normalMapStrength;
bumpColor = normalize(max(bumpColor, float3(0, 0, 0.0001f)));
color.a = 1 - saturate(abs(dot(bumpColor, float3(0, 0, 1))));
float caustic = abs(dot(bumpColor, float3(0, 1, 0)));
caustic = saturate(caustic);
caustic = pow(caustic, 2);
caustic *= 20;
color.rgb += caustic;
}
return color;
-1
View File
@@ -421,6 +421,5 @@ enum BSTYPES
BSTYPE_ENVIRONMENTALLIGHT,
BSTYPE_DECAL,
BSTYPE_MULTIPLY,
BSTYPE_TRANSPARENTSHADOWMAP,
BSTYPE_COUNT
};
+5 -19
View File
@@ -28,10 +28,9 @@
#include "wiPlatform.h"
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <array>
#include <atomic>
using namespace std;
using namespace wiGraphics;
@@ -721,7 +720,7 @@ SHADERTYPE GetPSTYPE(RENDERPASS renderPass, bool alphatest, bool transparent, Ma
case RENDERPASS_SHADOW:
if (transparent)
{
realPS = PSTYPE_SHADOW_TRANSPARENT;
realPS = shaderType == MaterialComponent::SHADERTYPE_WATER ? PSTYPE_SHADOW_WATER : PSTYPE_SHADOW_TRANSPARENT;
}
else
{
@@ -1251,7 +1250,7 @@ void LoadShaders()
case RENDERPASS_DEPTHONLY:
case RENDERPASS_SHADOW:
case RENDERPASS_SHADOWCUBE:
desc.bs = &blendStates[transparency ? BSTYPE_TRANSPARENTSHADOWMAP : BSTYPE_COLORWRITEDISABLE];
desc.bs = &blendStates[transparency ? BSTYPE_TRANSPARENT : BSTYPE_COLORWRITEDISABLE];
break;
default:
break;
@@ -2362,19 +2361,6 @@ void SetUpStates()
bd.AlphaToCoverageEnable = false;
bd.IndependentBlendEnable = false;
device->CreateBlendState(&bd, &blendStates[BSTYPE_MULTIPLY]);
bd.RenderTarget[0].SrcBlend = BLEND_DEST_COLOR;
bd.RenderTarget[0].DestBlend = BLEND_ZERO;
bd.RenderTarget[0].BlendOp = BLEND_OP_ADD;
bd.RenderTarget[0].SrcBlendAlpha = BLEND_ONE;
bd.RenderTarget[0].DestBlendAlpha = BLEND_ONE;
bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD;
bd.RenderTarget[0].BlendEnable = true;
bd.RenderTarget[0].RenderTargetWriteMask = COLOR_WRITE_ENABLE_ALL;
bd.AlphaToCoverageEnable = false;
bd.IndependentBlendEnable = false;
device->CreateBlendState(&bd, &blendStates[BSTYPE_TRANSPARENTSHADOWMAP]);
}
void ModifySampler(const SamplerDesc& desc, int slot)
@@ -3029,6 +3015,7 @@ void RenderMeshes(
{
const GPUResource* res[] = {
material.GetBaseColorMap(),
material.GetNormalMap(), //reminder: transparent shadow might need it!
};
device->BindResources(PS, res, TEXSLOT_RENDERER_BASECOLORMAP, arraysize(res), cmd);
}
@@ -4773,9 +4760,8 @@ void SetShadowProps2D(int resolution, int count, int softShadowQuality)
device->CreateTexture(&desc, nullptr, &shadowMapArray_2D);
desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE;
desc.Format = FORMAT_R8G8B8A8_UNORM;
desc.Format = FORMAT_R11G11B10_FLOAT;
desc.layout = IMAGE_LAYOUT_SHADER_RESOURCE;
// RGB: Shadow tint (multiplicative), A: Refraction caustics(additive)
desc.clear.color[0] = 1;
desc.clear.color[1] = 1;
desc.clear.color[2] = 1;
+1 -1
View File
@@ -9,7 +9,7 @@ namespace wiVersion
// minor features, major updates, breaking API changes
const int minor = 50;
// minor bug fixes, alterations, refactors, updates
const int revision = 4;
const int revision = 5;
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);