add instanced linear depth effect + fix platforms
parent
367e2795ae
commit
0c576668cb
Binary file not shown.
|
@ -0,0 +1,55 @@
|
||||||
|
#include "Macros.fxh"
|
||||||
|
|
||||||
|
BEGIN_CONSTANTS
|
||||||
|
|
||||||
|
float4x4 ViewProjection _vs(c4) _cb(c4);
|
||||||
|
|
||||||
|
float3 LightPosition _ps(c0) _cb(c8);
|
||||||
|
float FarPlane _ps(c1) _cb(c9);
|
||||||
|
|
||||||
|
END_CONSTANTS
|
||||||
|
|
||||||
|
struct VertexShaderInput
|
||||||
|
{
|
||||||
|
float4 Position : POSITION;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VertexShaderOutput
|
||||||
|
{
|
||||||
|
float4 Position : SV_Position;
|
||||||
|
float3 PositionWorld : TEXCOORD0;
|
||||||
|
};
|
||||||
|
|
||||||
|
VertexShaderOutput instanced_vs(VertexShaderInput input, float3 Translation : TEXCOORD2)
|
||||||
|
{
|
||||||
|
VertexShaderOutput output;
|
||||||
|
|
||||||
|
float4x4 world = float4x4(
|
||||||
|
float4(1, 0, 0, 0),
|
||||||
|
float4(0, 1, 0, 0),
|
||||||
|
float4(0, 0, 1, 0),
|
||||||
|
float4(Translation.x, Translation.y, Translation.z, 1)
|
||||||
|
);
|
||||||
|
|
||||||
|
float4x4 worldViewProjection = mul(world, ViewProjection);
|
||||||
|
output.Position = mul(input.Position, worldViewProjection);
|
||||||
|
output.Position.x *= -1; // otherwise cube map render will be horizontally flipped
|
||||||
|
output.PositionWorld = mul(input.Position, world);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
float4 main_ps(VertexShaderOutput input) : SV_TARGET0
|
||||||
|
{
|
||||||
|
float lightDistance = length(input.PositionWorld - LightPosition);
|
||||||
|
lightDistance /= FarPlane;
|
||||||
|
return float4(lightDistance, 0.0, 0.0, 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Technique SimpleDepth
|
||||||
|
{
|
||||||
|
Pass
|
||||||
|
{
|
||||||
|
VertexShader = compile vs_3_0 instanced_vs();
|
||||||
|
PixelShader = compile ps_3_0 main_ps();
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,7 +20,7 @@ VertexShaderOutput instanced_vs(VertexShaderInput input, float3 Translation : TE
|
||||||
float4(0, 1, 0, 0),
|
float4(0, 1, 0, 0),
|
||||||
float4(0, 0, 1, 0),
|
float4(0, 0, 1, 0),
|
||||||
float4(Translation.x, Translation.y, Translation.z, 1)
|
float4(Translation.x, Translation.y, Translation.z, 1)
|
||||||
);
|
);
|
||||||
|
|
||||||
float4x4 worldViewProjection = mul(world, ViewProjection);
|
float4x4 worldViewProjection = mul(world, ViewProjection);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
|
namespace Kav
|
||||||
|
{
|
||||||
|
public class LinearDepthEffectInstanced : Effect
|
||||||
|
{
|
||||||
|
EffectParameter viewProjectionParam;
|
||||||
|
EffectParameter lightPositionParam;
|
||||||
|
EffectParameter farPlaneParam;
|
||||||
|
|
||||||
|
EffectDirtyFlags dirtyFlags = EffectDirtyFlags.All;
|
||||||
|
|
||||||
|
Matrix view;
|
||||||
|
Matrix projection;
|
||||||
|
|
||||||
|
public Vector3 LightPosition { get; set; }
|
||||||
|
public float FarPlane { get; set; }
|
||||||
|
|
||||||
|
public Matrix View
|
||||||
|
{
|
||||||
|
get { return view; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
view = value;
|
||||||
|
dirtyFlags |= EffectDirtyFlags.ViewProj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Matrix Projection
|
||||||
|
{
|
||||||
|
get { return projection; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
projection = value;
|
||||||
|
dirtyFlags |= EffectDirtyFlags.ViewProj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinearDepthEffectInstanced(GraphicsDevice graphicsDevice) : base(graphicsDevice, Resources.LinearDepthEffectInstanced)
|
||||||
|
{
|
||||||
|
CacheEffectParameters();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnApply()
|
||||||
|
{
|
||||||
|
if ((dirtyFlags & EffectDirtyFlags.ViewProj) != 0)
|
||||||
|
{
|
||||||
|
Matrix.Multiply(ref view, ref projection, out Matrix viewProjection);
|
||||||
|
viewProjectionParam.SetValue(viewProjection);
|
||||||
|
|
||||||
|
dirtyFlags &= ~EffectDirtyFlags.ViewProj;
|
||||||
|
}
|
||||||
|
|
||||||
|
lightPositionParam.SetValue(LightPosition);
|
||||||
|
farPlaneParam.SetValue(FarPlane);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CacheEffectParameters()
|
||||||
|
{
|
||||||
|
viewProjectionParam = Parameters["ViewProjection"];
|
||||||
|
|
||||||
|
lightPositionParam = Parameters["LightPosition"];
|
||||||
|
farPlaneParam = Parameters["FarPlane"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -49,6 +49,9 @@
|
||||||
<EmbeddedResource Include="Effects\FXB\LinearDepthEffect.fxb">
|
<EmbeddedResource Include="Effects\FXB\LinearDepthEffect.fxb">
|
||||||
<LogicalName>Kav.Resources.LinearDepthEffect.fxb</LogicalName>
|
<LogicalName>Kav.Resources.LinearDepthEffect.fxb</LogicalName>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="Effects\FXB\LinearDepthEffectInstanced.fxb">
|
||||||
|
<LogicalName>Kav.Resources.LinearDepthEffectInstanced.fxb</LogicalName>
|
||||||
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Include="Effects\FXB\SkyboxEffect.fxb">
|
<EmbeddedResource Include="Effects\FXB\SkyboxEffect.fxb">
|
||||||
<LogicalName>Kav.Resources.SkyboxEffect.fxb</LogicalName>
|
<LogicalName>Kav.Resources.SkyboxEffect.fxb</LogicalName>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<Copyright>Evan Hemsley 2020</Copyright>
|
<Copyright>Evan Hemsley 2020</Copyright>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<AssemblyName>Kav</AssemblyName>
|
<AssemblyName>Kav</AssemblyName>
|
||||||
<Platforms>x64</Platforms>
|
<Platforms>x64;x86</Platforms>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -49,6 +49,9 @@
|
||||||
<EmbeddedResource Include="Effects\FXB\LinearDepthEffect.fxb">
|
<EmbeddedResource Include="Effects\FXB\LinearDepthEffect.fxb">
|
||||||
<LogicalName>Kav.Resources.LinearDepthEffect.fxb</LogicalName>
|
<LogicalName>Kav.Resources.LinearDepthEffect.fxb</LogicalName>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="Effects\FXB\LinearDepthEffectInstanced.fxb">
|
||||||
|
<LogicalName>Kav.Resources.LinearDepthEffectInstanced.fxb</LogicalName>
|
||||||
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Include="Effects\FXB\SkyboxEffect.fxb">
|
<EmbeddedResource Include="Effects\FXB\SkyboxEffect.fxb">
|
||||||
<LogicalName>Kav.Resources.SkyboxEffect.fxb</LogicalName>
|
<LogicalName>Kav.Resources.SkyboxEffect.fxb</LogicalName>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
|
13
Resources.cs
13
Resources.cs
|
@ -135,6 +135,18 @@ namespace Kav
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte[] LinearDepthEffectInstanced
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (linearDepthEffectInstanced == null)
|
||||||
|
{
|
||||||
|
linearDepthEffectInstanced = GetResource("LinearDepthEffectInstanced.fxb");
|
||||||
|
}
|
||||||
|
return linearDepthEffectInstanced;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static byte[] SkyboxEffect
|
public static byte[] SkyboxEffect
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -182,6 +194,7 @@ namespace Kav
|
||||||
private static byte[] simpleDepthEffect;
|
private static byte[] simpleDepthEffect;
|
||||||
private static byte[] simpleDepthEffectInstanced;
|
private static byte[] simpleDepthEffectInstanced;
|
||||||
private static byte[] linearDepthEffect;
|
private static byte[] linearDepthEffect;
|
||||||
|
private static byte[] linearDepthEffectInstanced;
|
||||||
private static byte[] skyboxEffect;
|
private static byte[] skyboxEffect;
|
||||||
private static byte[] diffuseLitSpriteEffect;
|
private static byte[] diffuseLitSpriteEffect;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue