updated tiled lighting
This commit is contained in:
@@ -11,16 +11,14 @@ inline float offset_lookup(Texture2D<float> intex, SamplerComparisonState map,
|
||||
float2 loc,
|
||||
float2 offset,
|
||||
float scale,
|
||||
float realDistance)
|
||||
float biasedDistance)
|
||||
{
|
||||
float BiasedDistance = realDistance - g_xDirLight_mBiasResSoftshadow.x;
|
||||
|
||||
return intex.SampleCmpLevelZero( map, loc + offset / scale, BiasedDistance).r;
|
||||
return intex.SampleCmpLevelZero( map, loc + offset / scale, biasedDistance).r;
|
||||
}
|
||||
|
||||
|
||||
inline float shadowCascade(float4 shadowPos, float2 ShTex, Texture2D<float> shadowTexture){
|
||||
float realDistance = shadowPos.z/shadowPos.w;
|
||||
inline float shadowCascade(float4 shadowPos, float2 ShTex, float bias, Texture2D<float> shadowTexture){
|
||||
float realDistance = shadowPos.z/shadowPos.w - bias;
|
||||
float sum = 0;
|
||||
float scale = g_xDirLight_mBiasResSoftshadow.y;
|
||||
float retVal = 1;
|
||||
@@ -65,9 +63,9 @@ inline void dirLight(in float3 P, in float3 N, in float3 V, in float roughness,
|
||||
ShTex[1] = ShPos[1].xyz*float3(1,-1,1)/ShPos[1].w/2.0f +0.5f;
|
||||
ShTex[2] = ShPos[2].xyz*float3(1,-1,1)/ShPos[2].w/2.0f +0.5f;
|
||||
const float shadows[3]={
|
||||
shadowCascade(ShPos[0],ShTex[0].xy,texture_shadow0),
|
||||
shadowCascade(ShPos[1],ShTex[1].xy,texture_shadow1),
|
||||
shadowCascade(ShPos[2],ShTex[2].xy,texture_shadow2)
|
||||
shadowCascade(ShPos[0],ShTex[0].xy, g_xDirLight_mBiasResSoftshadow.x,texture_shadow0),
|
||||
shadowCascade(ShPos[1],ShTex[1].xy, g_xDirLight_mBiasResSoftshadow.x,texture_shadow1),
|
||||
shadowCascade(ShPos[2],ShTex[2].xy, g_xDirLight_mBiasResSoftshadow.x,texture_shadow2)
|
||||
};
|
||||
[branch]if((saturate(ShTex[2].x) == ShTex[2].x) && (saturate(ShTex[2].y) == ShTex[2].y) && (saturate(ShTex[2].z) == ShTex[2].z))
|
||||
{
|
||||
|
||||
+12
-12
@@ -135,9 +135,9 @@ inline void DirectionalLight(in float3 N, in float3 V, in float3 P, in float3 f0
|
||||
ShTex[1] = ShPos[1].xyz*float3(1, -1, 1) / ShPos[1].w / 2.0f + 0.5f;
|
||||
ShTex[2] = ShPos[2].xyz*float3(1, -1, 1) / ShPos[2].w / 2.0f + 0.5f;
|
||||
const float shadows[3] = {
|
||||
shadowCascade(ShPos[0],ShTex[0].xy,texture_shadow0),
|
||||
shadowCascade(ShPos[1],ShTex[1].xy,texture_shadow1),
|
||||
shadowCascade(ShPos[2],ShTex[2].xy,texture_shadow2)
|
||||
shadowCascade(ShPos[0],ShTex[0].xy,0.0001f,texture_shadow0),
|
||||
shadowCascade(ShPos[1],ShTex[1].xy,0.0001f,texture_shadow1),
|
||||
shadowCascade(ShPos[2],ShTex[2].xy,0.0001f,texture_shadow2)
|
||||
};
|
||||
[branch]if ((saturate(ShTex[2].x) == ShTex[2].x) && (saturate(ShTex[2].y) == ShTex[2].y) && (saturate(ShTex[2].z) == ShTex[2].z))
|
||||
{
|
||||
@@ -186,14 +186,16 @@ inline void TiledLighting(in float2 pixel, in float3 N, in float3 V, in float3 P
|
||||
|
||||
LightingResult result = (LightingResult)0;
|
||||
|
||||
float3 lightColor = light.color.rgb * light.energy;
|
||||
|
||||
switch (light.type)
|
||||
{
|
||||
case 0/*DIRECTIONAL*/:
|
||||
{
|
||||
L = light.direction.xyz;
|
||||
BRDF_MAKE(N, L, V);
|
||||
result.specular = light.color.rgb * BRDF_SPECULAR(roughness, f0);
|
||||
result.diffuse = light.color.rgb * BRDF_DIFFUSE(roughness);
|
||||
result.specular = lightColor * BRDF_SPECULAR(roughness, f0);
|
||||
result.diffuse = lightColor * BRDF_DIFFUSE(roughness);
|
||||
|
||||
float sh = max(NdotL, 0);
|
||||
float4 ShPos[3];
|
||||
@@ -205,9 +207,9 @@ inline void TiledLighting(in float2 pixel, in float3 N, in float3 V, in float3 P
|
||||
ShTex[1] = ShPos[1].xyz*float3(1, -1, 1) / ShPos[1].w / 2.0f + 0.5f;
|
||||
ShTex[2] = ShPos[2].xyz*float3(1, -1, 1) / ShPos[2].w / 2.0f + 0.5f;
|
||||
const float shadows[3] = {
|
||||
shadowCascade(ShPos[0],ShTex[0].xy,texture_shadow0),
|
||||
shadowCascade(ShPos[1],ShTex[1].xy,texture_shadow1),
|
||||
shadowCascade(ShPos[2],ShTex[2].xy,texture_shadow2)
|
||||
shadowCascade(ShPos[0],ShTex[0].xy, light.shadowBias,texture_shadow0),
|
||||
shadowCascade(ShPos[1],ShTex[1].xy, light.shadowBias,texture_shadow1),
|
||||
shadowCascade(ShPos[2],ShTex[2].xy, light.shadowBias,texture_shadow2)
|
||||
};
|
||||
[branch]if ((saturate(ShTex[2].x) == ShTex[2].x) && (saturate(ShTex[2].y) == ShTex[2].y) && (saturate(ShTex[2].z) == ShTex[2].z))
|
||||
{
|
||||
@@ -237,10 +239,8 @@ inline void TiledLighting(in float2 pixel, in float3 N, in float3 V, in float3 P
|
||||
case 1/*POINT*/:
|
||||
{
|
||||
BRDF_MAKE(N, L, V);
|
||||
result.specular = light.color.rgb * BRDF_SPECULAR(roughness, f0);
|
||||
result.diffuse = light.color.rgb * BRDF_DIFFUSE(roughness);
|
||||
result.diffuse *= light.energy;
|
||||
result.specular *= light.energy;
|
||||
result.specular = lightColor * BRDF_SPECULAR(roughness, f0);
|
||||
result.diffuse = lightColor * BRDF_DIFFUSE(roughness);
|
||||
|
||||
float att = (light.energy * (light.range / (light.range + 1 + lightDistance)));
|
||||
float attenuation = /*saturate*/(att * (light.range - lightDistance) / light.range);
|
||||
|
||||
@@ -31,40 +31,40 @@ void main(
|
||||
|
||||
element.tex=float2(0,0);
|
||||
element.pos=pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos.xyz+=-right*frame.x+normal*frame.y+wind;
|
||||
element.pos = mul(element.pos, xWorld);
|
||||
float4 savedPos = element.pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos = element.pos2D = mul(element.pos, g_xCamera_VP);
|
||||
element.pos2DPrev = mul(savedPos, g_xCamera_PrevVP);
|
||||
output.Append(element);
|
||||
|
||||
element.tex=float2(1,0);
|
||||
element.pos=pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos.xyz+=right*frame.x+normal*frame.y+wind;
|
||||
element.pos = mul(element.pos, xWorld);
|
||||
savedPos = element.pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos = element.pos2D = mul(element.pos, g_xCamera_VP);
|
||||
element.pos2DPrev = mul(savedPos, g_xCamera_PrevVP);
|
||||
output.Append(element);
|
||||
|
||||
element.tex=float2(0,1);
|
||||
element.pos=pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos.xyz += -right*frame.x;
|
||||
element.pos = mul(element.pos, xWorld);
|
||||
savedPos = element.pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos = element.pos2D = mul(element.pos, g_xCamera_VP);
|
||||
element.pos2DPrev = mul(savedPos, g_xCamera_PrevVP);
|
||||
output.Append(element);
|
||||
|
||||
element.tex=float2(1,1);
|
||||
element.pos=pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos.xyz += right*frame.x;
|
||||
element.pos = mul(element.pos, xWorld);
|
||||
savedPos = element.pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos = element.pos2D = mul(element.pos, g_xCamera_VP);
|
||||
element.pos2DPrev = mul(savedPos, g_xCamera_PrevVP);
|
||||
output.Append(element);
|
||||
@@ -75,40 +75,40 @@ void main(
|
||||
|
||||
element.tex=float2(0,0);
|
||||
element.pos=pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos.xyz += -front*frame.x + normal*frame.y + wind;
|
||||
element.pos = mul(element.pos, xWorld);
|
||||
savedPos = element.pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos = element.pos2D = mul(element.pos, g_xCamera_VP);
|
||||
element.pos2DPrev = mul(savedPos, g_xCamera_PrevVP);
|
||||
output.Append(element);
|
||||
|
||||
element.tex=float2(1,0);
|
||||
element.pos=pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos.xyz += front*frame.x + normal*frame.y + wind;
|
||||
element.pos = mul(element.pos, xWorld);
|
||||
savedPos = element.pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos = element.pos2D = mul(element.pos, g_xCamera_VP);
|
||||
element.pos2DPrev = mul(savedPos, g_xCamera_PrevVP);
|
||||
output.Append(element);
|
||||
|
||||
element.tex=float2(0,1);
|
||||
element.pos=pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos.xyz += -front*frame.x;
|
||||
element.pos = mul(element.pos, xWorld);
|
||||
savedPos = element.pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos = element.pos2D = mul(element.pos, g_xCamera_VP);
|
||||
element.pos2DPrev = mul(savedPos, g_xCamera_PrevVP);
|
||||
output.Append(element);
|
||||
|
||||
element.tex=float2(1,1);
|
||||
element.pos=pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos.xyz += front*frame.x;
|
||||
element.pos = mul(element.pos, xWorld);
|
||||
savedPos = element.pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos = element.pos2D = mul(element.pos, g_xCamera_VP);
|
||||
element.pos2DPrev = mul(savedPos, g_xCamera_PrevVP);
|
||||
output.Append(element);
|
||||
|
||||
@@ -39,40 +39,40 @@ void main(
|
||||
|
||||
element.tex=float2(rand%2?1:0,0);
|
||||
element.pos=pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos.xyz+=-right*frame.x+normal*frame.y+wind;
|
||||
element.pos = mul(element.pos, xWorld);
|
||||
float4 savedPos = element.pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos = element.pos2D = mul(element.pos,g_xCamera_VP);
|
||||
element.pos2DPrev = mul(savedPos, g_xCamera_PrevVP);
|
||||
output.Append(element);
|
||||
|
||||
element.tex=float2(rand%2?0:1,0);
|
||||
element.pos=pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos.xyz+=right*frame.x+normal*frame.y+wind;
|
||||
element.pos = mul(element.pos, xWorld);
|
||||
savedPos = element.pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos = element.pos2D = mul(element.pos, g_xCamera_VP);
|
||||
element.pos2DPrev = mul(savedPos, g_xCamera_PrevVP);
|
||||
output.Append(element);
|
||||
|
||||
element.tex=float2(rand%2?1:0,1);
|
||||
element.pos=pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos.xyz += -right*frame.x;
|
||||
element.pos = mul(element.pos, xWorld);
|
||||
savedPos = element.pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos = element.pos2D = mul(element.pos, g_xCamera_VP);
|
||||
element.pos2DPrev = mul(savedPos, g_xCamera_PrevVP);
|
||||
output.Append(element);
|
||||
|
||||
element.tex=float2(rand%2?0:1,1);
|
||||
element.pos=pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos.xyz += right*frame.x;
|
||||
element.pos = mul(element.pos, xWorld);
|
||||
savedPos = element.pos;
|
||||
element.pos3D = element.pos.xyz;
|
||||
element.pos = element.pos2D = mul(element.pos, g_xCamera_VP);
|
||||
element.pos2DPrev = mul(savedPos, g_xCamera_PrevVP);
|
||||
output.Append(element);
|
||||
|
||||
@@ -2982,6 +2982,10 @@ void wiRenderer::DrawWorld(Camera* camera, bool tessellation, GRAPHICSTHREAD thr
|
||||
|
||||
GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREADEQUAL], 0, threadID);
|
||||
}
|
||||
else if (shaderType == SHADERTYPE_ALPHATESTONLY)
|
||||
{
|
||||
GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], STENCILREF_DEFAULT, threadID);
|
||||
}
|
||||
|
||||
|
||||
for(Cullable* object : culledObjects){
|
||||
@@ -3561,6 +3565,7 @@ void wiRenderer::ComputeTiledLightCulling(GRAPHICSTHREAD threadID)
|
||||
lightArray[lightCounter].col = l->color;
|
||||
lightArray[lightCounter].energy = l->enerDis.x;
|
||||
lightArray[lightCounter].type = l->type;
|
||||
lightArray[lightCounter].shadowBias = l->shadowBias;
|
||||
switch (l->type)
|
||||
{
|
||||
case Light::DIRECTIONAL:
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace wiVersion
|
||||
{
|
||||
// major features
|
||||
// main engine core
|
||||
const int major = 0;
|
||||
// minor features, major bug fixes
|
||||
// minor features, major updates
|
||||
const int minor = 9;
|
||||
// minor bug fixes, alterations, refactors
|
||||
const int revision = 0;
|
||||
// minor bug fixes, alterations, refactors, updates
|
||||
const int revision = 2;
|
||||
|
||||
|
||||
long GetVersion()
|
||||
|
||||
Reference in New Issue
Block a user