flat sprite lighting in deferred pipeline

sprite_light_experimental
cosmonaut 2020-12-12 02:36:53 -08:00
parent a76c0234d4
commit 9bd7f84d26
3 changed files with 22 additions and 27 deletions

View File

@ -18,8 +18,6 @@ namespace Kav
EffectParameter farPlaneParam; EffectParameter farPlaneParam;
EffectParameter worldParam;
EffectParameter worldInverseParam;
EffectParameter worldViewProjectionParam; EffectParameter worldViewProjectionParam;
public Texture2D GPosition { get; set; } public Texture2D GPosition { get; set; }
@ -47,7 +45,7 @@ namespace Kav
set set
{ {
world = value; world = value;
dirtyFlags |= EffectDirtyFlags.WorldViewProj | EffectDirtyFlags.World; dirtyFlags |= EffectDirtyFlags.WorldViewProj;
} }
} }
@ -114,14 +112,6 @@ namespace Kav
farPlaneParam.SetValue(FarPlane); farPlaneParam.SetValue(FarPlane);
if ((dirtyFlags & EffectDirtyFlags.World) != 0)
{
worldParam.SetValue(world);
worldInverseParam.SetValue(Matrix.Invert(world));
dirtyFlags &= ~EffectDirtyFlags.World;
}
if ((dirtyFlags & EffectDirtyFlags.WorldViewProj) != 0) if ((dirtyFlags & EffectDirtyFlags.WorldViewProj) != 0)
{ {
worldViewProjectionParam.SetValue(world * view * projection); worldViewProjectionParam.SetValue(world * view * projection);
@ -145,8 +135,6 @@ namespace Kav
farPlaneParam = Parameters["FarPlane"]; farPlaneParam = Parameters["FarPlane"];
worldParam = Parameters["World"];
worldInverseParam = Parameters["WorldInverse"];
worldViewProjectionParam = Parameters["WorldViewProjection"]; worldViewProjectionParam = Parameters["WorldViewProjection"];
} }
} }

Binary file not shown.

View File

@ -21,8 +21,6 @@ BEGIN_CONSTANTS
MATRIX_CONSTANTS MATRIX_CONSTANTS
float4x4 WorldInverse _ps(c4) _cb(c8);
float4x4 World _ps(c8) _cb(c12);
float4x4 WorldViewProjection _vs(c0) _cb(c4); float4x4 WorldViewProjection _vs(c0) _cb(c4);
END_CONSTANTS END_CONSTANTS
@ -88,17 +86,26 @@ float4 main_ps(PixelInput input) : SV_TARGET0
float3 albedo = SAMPLE_TEXTURE(gAlbedo, texCoord).rgb; float3 albedo = SAMPLE_TEXTURE(gAlbedo, texCoord).rgb;
float2 metallicRoughness = SAMPLE_TEXTURE(gMetallicRoughness, texCoord).rg; float2 metallicRoughness = SAMPLE_TEXTURE(gMetallicRoughness, texCoord).rg;
float3 objectZNormal = mul(normal, WorldInverse); if (isSprite == 1.0)
objectZNormal.xz *= -1; {
float3 invertedZNormalWorld = mul(objectZNormal, World); float3 lightDir = PointLightPosition - worldPosition;
float3 L = normalize(lightDir);
float distance = length(lightDir);
float attenuation = 1.0 / (distance * distance);
float3 radiance = PointLightColor * attenuation;
return float4(albedo * radiance * 0.1, 1.0);
}
else
{
return ComputeColor( return ComputeColor(
worldPosition, worldPosition,
normal, normal,
albedo, albedo,
metallicRoughness.r, metallicRoughness.r,
metallicRoughness.g metallicRoughness.g
) + (isSprite * ComputeColor(worldPosition, invertedZNormalWorld, albedo, metallicRoughness.r, metallicRoughness.g)); );
}
} }
Technique DeferredPBR_Point Technique DeferredPBR_Point