experimenting with g buffer sprites
parent
3a0aa8894d
commit
a76c0234d4
|
@ -17,6 +17,7 @@ namespace Kav
|
||||||
EffectParameter roughnessParam;
|
EffectParameter roughnessParam;
|
||||||
|
|
||||||
EffectParameter uvOffsetAndDimensionsParam;
|
EffectParameter uvOffsetAndDimensionsParam;
|
||||||
|
EffectParameter isSpriteParam;
|
||||||
|
|
||||||
EffectParameter numTextureRowsParam;
|
EffectParameter numTextureRowsParam;
|
||||||
EffectParameter numTextureColumnsParam;
|
EffectParameter numTextureColumnsParam;
|
||||||
|
@ -35,6 +36,8 @@ namespace Kav
|
||||||
Vector2 uvOffset;
|
Vector2 uvOffset;
|
||||||
Vector2 subTextureDimensions;
|
Vector2 subTextureDimensions;
|
||||||
|
|
||||||
|
bool isSprite = false;
|
||||||
|
|
||||||
int numTextureRows = 1;
|
int numTextureRows = 1;
|
||||||
int numTextureColumns = 1;
|
int numTextureColumns = 1;
|
||||||
|
|
||||||
|
@ -178,6 +181,16 @@ namespace Kav
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsSprite
|
||||||
|
{
|
||||||
|
get { return isSprite; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
isSprite = value;
|
||||||
|
isSpriteParam.SetValue(isSprite ? 1f : 0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool HardwareInstancingEnabled
|
public bool HardwareInstancingEnabled
|
||||||
{
|
{
|
||||||
get { return hardwareInstancingEnabled; }
|
get { return hardwareInstancingEnabled; }
|
||||||
|
@ -313,6 +326,7 @@ namespace Kav
|
||||||
numTextureColumnsParam = Parameters["NumTextureColumns"];
|
numTextureColumnsParam = Parameters["NumTextureColumns"];
|
||||||
|
|
||||||
uvOffsetAndDimensionsParam = Parameters["UVOffsetAndDimensions"];
|
uvOffsetAndDimensionsParam = Parameters["UVOffsetAndDimensions"];
|
||||||
|
isSpriteParam = Parameters["IsSprite"];
|
||||||
|
|
||||||
shaderIndexParam = Parameters["PixelShaderIndex"];
|
shaderIndexParam = Parameters["PixelShaderIndex"];
|
||||||
vertexShaderIndexParam = Parameters["VertexShaderIndex"];
|
vertexShaderIndexParam = Parameters["VertexShaderIndex"];
|
||||||
|
|
|
@ -18,6 +18,8 @@ namespace Kav
|
||||||
|
|
||||||
EffectParameter farPlaneParam;
|
EffectParameter farPlaneParam;
|
||||||
|
|
||||||
|
EffectParameter worldParam;
|
||||||
|
EffectParameter worldInverseParam;
|
||||||
EffectParameter worldViewProjectionParam;
|
EffectParameter worldViewProjectionParam;
|
||||||
|
|
||||||
public Texture2D GPosition { get; set; }
|
public Texture2D GPosition { get; set; }
|
||||||
|
@ -45,7 +47,7 @@ namespace Kav
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
world = value;
|
world = value;
|
||||||
dirtyFlags |= EffectDirtyFlags.WorldViewProj;
|
dirtyFlags |= EffectDirtyFlags.WorldViewProj | EffectDirtyFlags.World;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,6 +114,14 @@ 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);
|
||||||
|
@ -135,6 +145,8 @@ namespace Kav
|
||||||
|
|
||||||
farPlaneParam = Parameters["FarPlane"];
|
farPlaneParam = Parameters["FarPlane"];
|
||||||
|
|
||||||
|
worldParam = Parameters["World"];
|
||||||
|
worldInverseParam = Parameters["WorldInverse"];
|
||||||
worldViewProjectionParam = Parameters["WorldViewProjection"];
|
worldViewProjectionParam = Parameters["WorldViewProjection"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
BIN
Effects/FXB/DeferredPBR_GBufferEffect.fxb (Stored with Git LFS)
BIN
Effects/FXB/DeferredPBR_GBufferEffect.fxb (Stored with Git LFS)
Binary file not shown.
BIN
Effects/FXB/DeferredPBR_PointLightEffect.fxb (Stored with Git LFS)
BIN
Effects/FXB/DeferredPBR_PointLightEffect.fxb (Stored with Git LFS)
Binary file not shown.
|
@ -5,6 +5,7 @@ DECLARE_TEXTURE(NormalTexture, 1);
|
||||||
DECLARE_TEXTURE(MetallicRoughnessTexture, 2);
|
DECLARE_TEXTURE(MetallicRoughnessTexture, 2);
|
||||||
|
|
||||||
float4 UVOffsetAndDimensions;
|
float4 UVOffsetAndDimensions;
|
||||||
|
float IsSprite;
|
||||||
|
|
||||||
BEGIN_CONSTANTS
|
BEGIN_CONSTANTS
|
||||||
|
|
||||||
|
@ -119,7 +120,7 @@ PixelOutput NonePS(PixelInput input)
|
||||||
PixelOutput output;
|
PixelOutput output;
|
||||||
|
|
||||||
output.gPosition = float4(input.PositionWorld, 1.0);
|
output.gPosition = float4(input.PositionWorld, 1.0);
|
||||||
output.gNormal = float4(normalize(input.NormalWorld), 1.0);
|
output.gNormal = float4(normalize(input.NormalWorld), IsSprite);
|
||||||
output.gAlbedo = float4(AlbedoValue, 1.0);
|
output.gAlbedo = float4(AlbedoValue, 1.0);
|
||||||
output.gMetallicRoughness = float4(MetallicValue, RoughnessValue, 0.0, 1.0);
|
output.gMetallicRoughness = float4(MetallicValue, RoughnessValue, 0.0, 1.0);
|
||||||
|
|
||||||
|
@ -131,7 +132,7 @@ PixelOutput AlbedoPS(PixelInput input)
|
||||||
PixelOutput output;
|
PixelOutput output;
|
||||||
|
|
||||||
output.gPosition = float4(input.PositionWorld, 1.0);
|
output.gPosition = float4(input.PositionWorld, 1.0);
|
||||||
output.gNormal = float4(normalize(input.NormalWorld), 1.0);
|
output.gNormal = float4(normalize(input.NormalWorld), IsSprite);
|
||||||
output.gAlbedo = SAMPLE_TEXTURE(AlbedoTexture, input.TexCoord);
|
output.gAlbedo = SAMPLE_TEXTURE(AlbedoTexture, input.TexCoord);
|
||||||
output.gMetallicRoughness = float4(MetallicValue, RoughnessValue, 0.0, 1.0);
|
output.gMetallicRoughness = float4(MetallicValue, RoughnessValue, 0.0, 1.0);
|
||||||
|
|
||||||
|
@ -145,7 +146,7 @@ PixelOutput MetallicRoughnessPS(PixelInput input)
|
||||||
PixelOutput output;
|
PixelOutput output;
|
||||||
|
|
||||||
output.gPosition = float4(input.PositionWorld, 1.0);
|
output.gPosition = float4(input.PositionWorld, 1.0);
|
||||||
output.gNormal = float4(normalize(input.NormalWorld), 1.0);
|
output.gNormal = float4(normalize(input.NormalWorld), IsSprite);
|
||||||
output.gAlbedo = float4(AlbedoValue, 1.0);
|
output.gAlbedo = float4(AlbedoValue, 1.0);
|
||||||
output.gMetallicRoughness = SAMPLE_TEXTURE(MetallicRoughnessTexture, input.TexCoord);
|
output.gMetallicRoughness = SAMPLE_TEXTURE(MetallicRoughnessTexture, input.TexCoord);
|
||||||
|
|
||||||
|
@ -157,7 +158,7 @@ PixelOutput NormalPS(PixelInput input)
|
||||||
PixelOutput output;
|
PixelOutput output;
|
||||||
|
|
||||||
output.gPosition = float4(input.PositionWorld, 1.0);
|
output.gPosition = float4(input.PositionWorld, 1.0);
|
||||||
output.gNormal = float4(GetNormalFromMap(input.PositionWorld, input.TexCoord, input.NormalWorld), 1.0);
|
output.gNormal = float4(GetNormalFromMap(input.PositionWorld, input.TexCoord, input.NormalWorld), IsSprite);
|
||||||
output.gAlbedo = float4(AlbedoValue, 1.0);
|
output.gAlbedo = float4(AlbedoValue, 1.0);
|
||||||
output.gMetallicRoughness = float4(MetallicValue, RoughnessValue, 0.0, 1.0);
|
output.gMetallicRoughness = float4(MetallicValue, RoughnessValue, 0.0, 1.0);
|
||||||
|
|
||||||
|
@ -169,7 +170,7 @@ PixelOutput AlbedoMetallicRoughnessPS(PixelInput input)
|
||||||
PixelOutput output;
|
PixelOutput output;
|
||||||
|
|
||||||
output.gPosition = float4(input.PositionWorld, 1.0);
|
output.gPosition = float4(input.PositionWorld, 1.0);
|
||||||
output.gNormal = float4(normalize(input.NormalWorld), 1.0);
|
output.gNormal = float4(normalize(input.NormalWorld), IsSprite);
|
||||||
output.gAlbedo = SAMPLE_TEXTURE(AlbedoTexture, input.TexCoord);
|
output.gAlbedo = SAMPLE_TEXTURE(AlbedoTexture, input.TexCoord);
|
||||||
output.gMetallicRoughness = SAMPLE_TEXTURE(MetallicRoughnessTexture, input.TexCoord);
|
output.gMetallicRoughness = SAMPLE_TEXTURE(MetallicRoughnessTexture, input.TexCoord);
|
||||||
|
|
||||||
|
@ -183,7 +184,7 @@ PixelOutput AlbedoNormalPS(PixelInput input)
|
||||||
PixelOutput output;
|
PixelOutput output;
|
||||||
|
|
||||||
output.gPosition = float4(input.PositionWorld, 1.0);
|
output.gPosition = float4(input.PositionWorld, 1.0);
|
||||||
output.gNormal = float4(GetNormalFromMap(input.PositionWorld, input.TexCoord, input.NormalWorld), 1.0);
|
output.gNormal = float4(GetNormalFromMap(input.PositionWorld, input.TexCoord, input.NormalWorld), IsSprite);
|
||||||
output.gAlbedo = SAMPLE_TEXTURE(AlbedoTexture, input.TexCoord);
|
output.gAlbedo = SAMPLE_TEXTURE(AlbedoTexture, input.TexCoord);
|
||||||
output.gMetallicRoughness = float4(MetallicValue, RoughnessValue, 0.0, 1.0);
|
output.gMetallicRoughness = float4(MetallicValue, RoughnessValue, 0.0, 1.0);
|
||||||
|
|
||||||
|
@ -197,7 +198,7 @@ PixelOutput MetallicRoughnessNormalPS(PixelInput input)
|
||||||
PixelOutput output;
|
PixelOutput output;
|
||||||
|
|
||||||
output.gPosition = float4(input.PositionWorld, 1.0);
|
output.gPosition = float4(input.PositionWorld, 1.0);
|
||||||
output.gNormal = float4(GetNormalFromMap(input.PositionWorld, input.TexCoord, input.NormalWorld), 1.0);
|
output.gNormal = float4(GetNormalFromMap(input.PositionWorld, input.TexCoord, input.NormalWorld), IsSprite);
|
||||||
output.gAlbedo = float4(AlbedoValue, 1.0);
|
output.gAlbedo = float4(AlbedoValue, 1.0);
|
||||||
output.gMetallicRoughness = SAMPLE_TEXTURE(MetallicRoughnessTexture, input.TexCoord);
|
output.gMetallicRoughness = SAMPLE_TEXTURE(MetallicRoughnessTexture, input.TexCoord);
|
||||||
|
|
||||||
|
@ -209,7 +210,7 @@ PixelOutput AlbedoMetallicRoughnessNormalMapPS(PixelInput input)
|
||||||
PixelOutput output;
|
PixelOutput output;
|
||||||
|
|
||||||
output.gPosition = float4(input.PositionWorld, 1.0);
|
output.gPosition = float4(input.PositionWorld, 1.0);
|
||||||
output.gNormal = float4(GetNormalFromMap(input.PositionWorld, input.TexCoord, input.NormalWorld), 1.0);
|
output.gNormal = float4(GetNormalFromMap(input.PositionWorld, input.TexCoord, input.NormalWorld), IsSprite);
|
||||||
output.gAlbedo = SAMPLE_TEXTURE(AlbedoTexture, input.TexCoord);
|
output.gAlbedo = SAMPLE_TEXTURE(AlbedoTexture, input.TexCoord);
|
||||||
output.gMetallicRoughness = SAMPLE_TEXTURE(MetallicRoughnessTexture, input.TexCoord);
|
output.gMetallicRoughness = SAMPLE_TEXTURE(MetallicRoughnessTexture, input.TexCoord);
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@ 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
|
||||||
|
@ -80,17 +82,23 @@ float4 main_ps(PixelInput input) : SV_TARGET0
|
||||||
float2 texCoord = 0.5f * float2(input.ScreenPosition.x,-input.ScreenPosition.y) + 0.5f;
|
float2 texCoord = 0.5f * float2(input.ScreenPosition.x,-input.ScreenPosition.y) + 0.5f;
|
||||||
|
|
||||||
float3 worldPosition = SAMPLE_TEXTURE(gPosition, texCoord).rgb;
|
float3 worldPosition = SAMPLE_TEXTURE(gPosition, texCoord).rgb;
|
||||||
float3 normal = SAMPLE_TEXTURE(gNormal, texCoord).xyz;
|
float4 normalSample = SAMPLE_TEXTURE(gNormal, texCoord);
|
||||||
|
float3 normal = normalSample.xyz;
|
||||||
|
float isSprite = normalSample.a;
|
||||||
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);
|
||||||
|
objectZNormal.xz *= -1;
|
||||||
|
float3 invertedZNormalWorld = mul(objectZNormal, World);
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -207,6 +207,8 @@ namespace Kav
|
||||||
GraphicsDevice.BlendState = BlendState.AlphaBlend;
|
GraphicsDevice.BlendState = BlendState.AlphaBlend;
|
||||||
|
|
||||||
Deferred_GBufferEffect.HardwareInstancingEnabled = false;
|
Deferred_GBufferEffect.HardwareInstancingEnabled = false;
|
||||||
|
Deferred_GBufferEffect.IsSprite = true;
|
||||||
|
|
||||||
Deferred_GBufferEffect.View = camera.View;
|
Deferred_GBufferEffect.View = camera.View;
|
||||||
Deferred_GBufferEffect.Projection = camera.Projection;
|
Deferred_GBufferEffect.Projection = camera.Projection;
|
||||||
|
|
||||||
|
@ -418,6 +420,7 @@ namespace Kav
|
||||||
GraphicsDevice.BlendState = BlendState.Opaque;
|
GraphicsDevice.BlendState = BlendState.Opaque;
|
||||||
|
|
||||||
Deferred_GBufferEffect.HardwareInstancingEnabled = true;
|
Deferred_GBufferEffect.HardwareInstancingEnabled = true;
|
||||||
|
Deferred_GBufferEffect.IsSprite = false;
|
||||||
|
|
||||||
Deferred_GBufferEffect.Albedo = drawable.Albedo;
|
Deferred_GBufferEffect.Albedo = drawable.Albedo;
|
||||||
Deferred_GBufferEffect.Metallic = drawable.Metallic;
|
Deferred_GBufferEffect.Metallic = drawable.Metallic;
|
||||||
|
@ -465,6 +468,7 @@ namespace Kav
|
||||||
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
|
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
|
||||||
GraphicsDevice.BlendState = BlendState.Opaque;
|
GraphicsDevice.BlendState = BlendState.Opaque;
|
||||||
|
|
||||||
|
Deferred_GBufferEffect.IsSprite = false;
|
||||||
Deferred_GBufferEffect.HardwareInstancingEnabled = false;
|
Deferred_GBufferEffect.HardwareInstancingEnabled = false;
|
||||||
Deferred_GBufferEffect.View = camera.View;
|
Deferred_GBufferEffect.View = camera.View;
|
||||||
Deferred_GBufferEffect.Projection = camera.Projection;
|
Deferred_GBufferEffect.Projection = camera.Projection;
|
||||||
|
|
Loading…
Reference in New Issue