optimized tile-based decal rendering

This commit is contained in:
Turanszki Janos
2017-10-10 21:14:59 +01:00
parent c5b278baf8
commit dc2b8b20b8
3 changed files with 21 additions and 5 deletions
+2 -2
View File
@@ -102,7 +102,7 @@ void o_BitonicSort( in uint localIdxFlattened )
uint nSwapElem = nMergeSubSize == nMergeSize >> 1 ? index_high + ( 2 * nMergeSubSize - 1 ) - index_low : index_high + nMergeSubSize + index_low;
if( nSwapElem < numArray && index < numArray )
{
if( o_LightList[ index ] > o_LightList[ nSwapElem ] )
if( o_LightList[ index ] < o_LightList[ nSwapElem ] )
{
uint uTemp = o_LightList[ index ];
o_LightList[ index ] = o_LightList[ nSwapElem ];
@@ -136,7 +136,7 @@ void t_BitonicSort( in uint localIdxFlattened )
uint nSwapElem = nMergeSubSize == nMergeSize >> 1 ? index_high + ( 2 * nMergeSubSize - 1 ) - index_low : index_high + nMergeSubSize + index_low;
if( nSwapElem < numArray && index < numArray )
{
if( t_LightList[ index ] > t_LightList[ nSwapElem ] )
if( t_LightList[ index ] < t_LightList[ nSwapElem ] )
{
uint uTemp = t_LightList[ index ];
t_LightList[ index ] = t_LightList[ nSwapElem ];
+18 -2
View File
@@ -172,6 +172,10 @@ inline void TiledLighting(in float2 pixel, in float3 N, in float3 V, in float3 P
specular = 0;
diffuse = 0;
#ifndef DISABLE_DECALS
float4 decalAccumulation = 0;
#endif
[loop]
for (uint i = 0; i < lightCount; i++)
{
@@ -220,18 +224,26 @@ inline void TiledLighting(in float2 pixel, in float3 N, in float3 V, in float3 P
#ifndef DISABLE_DECALS
case 100/*DECAL*/:
{
[branch]
if (decalAccumulation.a > (1.0f - 1.0f / 255.0f))
{
break; // early out if decal accumulation is already at maximum
}
float3 clipSpace = mul(float4(P, 1), light.shadowMat[0]).xyz;
float3 projTex = clipSpace.xyz*float3(0.5f, -0.5f, 0.5f) + 0.5f;
[branch]
if ((saturate(projTex.x) == projTex.x) && (saturate(projTex.y) == projTex.y) && (saturate(projTex.z) == projTex.z))
{
// can't do mipmapping here because of the variable length loop :(
// todo: hack in some fake mipmapping here:
float4 decalColor = texture_decalatlas.SampleLevel(sampler_linear_clamp, projTex.xy*light.texMulAdd.xy + light.texMulAdd.zw, 0);
float edgeBlend = 1 - pow(saturate(abs(clipSpace.z)), 8); // blend out if close to cube Z
decalColor.a *= edgeBlend;
decalColor *= light.color;
albedo.rgb = lerp(albedo.rgb, decalColor.rgb, decalColor.a);
result.specular = decalColor.rgb * light.energy * edgeBlend; // apply emissive (light.energy = decal.emissive)
// perform manual blending of decals:
// they are sorted top-to-bottom, but blending is performed bottom-to-top
decalAccumulation.rgb = (1 - decalAccumulation.a) * (decalColor.a*decalColor.rgb) + decalAccumulation.rgb;
decalAccumulation.a = decalColor.a + (1 - decalColor.a) * decalAccumulation.a;
}
}
break;
@@ -242,6 +254,10 @@ inline void TiledLighting(in float2 pixel, in float3 N, in float3 V, in float3 P
diffuse += max(0.0f, result.diffuse);
specular += max(0.0f, result.specular);
}
#ifndef DISABLE_DECALS
albedo.rgb = lerp(albedo.rgb, decalAccumulation.rgb, decalAccumulation.a);
#endif
}
+1 -1
View File
@@ -9,7 +9,7 @@ namespace wiVersion
// minor features, major updates
const int minor = 13;
// minor bug fixes, alterations, refactors, updates
const int revision = 21;
const int revision = 22;
long GetVersion()