sprite_light_experimental #7
|
@ -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"];
|
||||||
|
|
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.
BIN
Effects/FXB/DiffuseLitSpriteEffect.fxb (Stored with Git LFS)
BIN
Effects/FXB/DiffuseLitSpriteEffect.fxb (Stored with Git LFS)
Binary file not shown.
BIN
Effects/FXB/PaletteCrushEffect.fxb (Stored with Git LFS)
BIN
Effects/FXB/PaletteCrushEffect.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);
|
||||||
|
|
||||||
|
|
|
@ -80,10 +80,24 @@ 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;
|
||||||
|
|
||||||
|
if (isSprite == 1.0)
|
||||||
|
{
|
||||||
|
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,
|
||||||
|
@ -91,6 +105,7 @@ float4 main_ps(PixelInput input) : SV_TARGET0
|
||||||
metallicRoughness.r,
|
metallicRoughness.r,
|
||||||
metallicRoughness.g
|
metallicRoughness.g
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Technique DeferredPBR_Point
|
Technique DeferredPBR_Point
|
||||||
|
|
|
@ -98,6 +98,9 @@ float4 LightColor(float3 worldPosition, float3 worldNormal)
|
||||||
float4 WithoutNormalMap(PixelShaderInput input) : COLOR0
|
float4 WithoutNormalMap(PixelShaderInput input) : COLOR0
|
||||||
{
|
{
|
||||||
float4 tex = SAMPLE_TEXTURE(Texture, input.TexCoord);
|
float4 tex = SAMPLE_TEXTURE(Texture, input.TexCoord);
|
||||||
|
|
||||||
|
if (tex.a == 0.0) { discard; }
|
||||||
|
|
||||||
float3 normalWS = normalize(input.NormalWS);
|
float3 normalWS = normalize(input.NormalWS);
|
||||||
|
|
||||||
return tex * LightColor(input.PositionWS, normalWS);
|
return tex * LightColor(input.PositionWS, normalWS);
|
||||||
|
@ -106,6 +109,9 @@ float4 WithoutNormalMap(PixelShaderInput input) : COLOR0
|
||||||
float4 WithNormalMap(PixelShaderInput input) : COLOR0
|
float4 WithNormalMap(PixelShaderInput input) : COLOR0
|
||||||
{
|
{
|
||||||
float4 tex = SAMPLE_TEXTURE(Texture, input.TexCoord);
|
float4 tex = SAMPLE_TEXTURE(Texture, input.TexCoord);
|
||||||
|
|
||||||
|
if (tex.a == 0.0) { discard; }
|
||||||
|
|
||||||
float3 normalWS = GetNormalFromMap(input.PositionWS, input.TexCoord, input.NormalWS);
|
float3 normalWS = GetNormalFromMap(input.PositionWS, input.TexCoord, input.NormalWS);
|
||||||
|
|
||||||
return tex * LightColor(input.PositionWS, normalWS);
|
return tex * LightColor(input.PositionWS, normalWS);
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#include "Macros.fxh"
|
#include "Macros.fxh"
|
||||||
|
|
||||||
#define FLT_MAX 3.402823466e+38
|
|
||||||
|
|
||||||
DECLARE_TEXTURE(Texture, 0);
|
DECLARE_TEXTURE(Texture, 0);
|
||||||
DECLARE_TEXTURE(Palette, 1);
|
DECLARE_TEXTURE(Palette, 1);
|
||||||
|
|
||||||
|
@ -40,11 +38,12 @@ float4 main_ps(PixelInput input) : SV_TARGET0
|
||||||
float3 sampled_color = sampled.rgb;
|
float3 sampled_color = sampled.rgb;
|
||||||
|
|
||||||
float3 closest_color = float3(0, 0, 0);
|
float3 closest_color = float3(0, 0, 0);
|
||||||
float closest_dist = FLT_MAX;
|
float closest_dist = 100000;
|
||||||
|
|
||||||
for (int i = 0; i < PaletteWidth; i++)
|
for (int i = 0; i < PaletteWidth; i++)
|
||||||
{
|
{
|
||||||
float3 palette_color = SAMPLE_TEXTURE(Palette, float2(i / (float)PaletteWidth, 0));
|
float texX = (i / (float)PaletteWidth);
|
||||||
|
float3 palette_color = SAMPLE_TEXTURE(Palette, float2(texX, 0));
|
||||||
float dist = distance(palette_color, sampled_color);
|
float dist = distance(palette_color, sampled_color);
|
||||||
if (dist < closest_dist)
|
if (dist < closest_dist)
|
||||||
{
|
{
|
||||||
|
|
24
Renderer.cs
24
Renderer.cs
|
@ -199,14 +199,17 @@ namespace Kav
|
||||||
public void RenderMeshSpriteGBuffer(
|
public void RenderMeshSpriteGBuffer(
|
||||||
RenderTargetBinding[] gBuffer,
|
RenderTargetBinding[] gBuffer,
|
||||||
PerspectiveCamera camera,
|
PerspectiveCamera camera,
|
||||||
IEnumerable<MeshSpriteDrawData> meshSpriteDrawDatas
|
IEnumerable<MeshSpriteDrawData> meshSpriteDrawDatas,
|
||||||
|
DepthStencilState depthStencilState
|
||||||
) {
|
) {
|
||||||
GraphicsDevice.SetRenderTargets(gBuffer);
|
GraphicsDevice.SetRenderTargets(gBuffer);
|
||||||
GraphicsDevice.RasterizerState = RasterizerState.CullNone;
|
GraphicsDevice.RasterizerState = RasterizerState.CullNone;
|
||||||
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
|
GraphicsDevice.DepthStencilState = depthStencilState;
|
||||||
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;
|
||||||
|
|
||||||
|
@ -375,6 +378,21 @@ namespace Kav
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RenderDepthIndexed<T>(
|
||||||
|
RenderTarget2D renderTarget,
|
||||||
|
PerspectiveCamera camera,
|
||||||
|
T drawable,
|
||||||
|
DepthStencilState depthStencilState
|
||||||
|
) where T : IIndexDrawable {
|
||||||
|
GraphicsDevice.SetRenderTarget(renderTarget);
|
||||||
|
GraphicsDevice.DepthStencilState = depthStencilState;
|
||||||
|
|
||||||
|
SimpleDepthEffect.View = camera.View;
|
||||||
|
SimpleDepthEffect.Projection = camera.Projection;
|
||||||
|
|
||||||
|
RenderIndexed(GraphicsDevice, drawable, SimpleDepthEffect);
|
||||||
|
}
|
||||||
|
|
||||||
public void RenderSkybox(
|
public void RenderSkybox(
|
||||||
RenderTarget2D renderTarget,
|
RenderTarget2D renderTarget,
|
||||||
PerspectiveCamera camera,
|
PerspectiveCamera camera,
|
||||||
|
@ -418,6 +436,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 +484,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