I was busy with a outline shader. I'll just post the whole thing below, but this is the line that causes the crash
color.rgb = lerp( color.rgb, g_vLineColor, edge );
MODES
{
Default();
Forward();
}
COMMON
{
#include "postprocess/shared.hlsl"
}
struct VertexInput
{
float3 vPositionOs : POSITION < Semantic( PosXyz ); >;
float2 vTexCoord : TEXCOORD0 < Semantic( LowPrecisionUv ); >;
};
struct PixelInput
{
float2 uv : TEXCOORD0;
#if ( PROGRAM == VFX_PROGRAM_VS )
float4 vPositionPs : SV_Position;
#endif
#if ( PROGRAM == VFX_PROGRAM_PS )
float4 vPositionSs : SV_Position;
#endif
};
VS
{
PixelInput MainVs( VertexInput i )
{
PixelInput o;
o.vPositionPs = float4( i.vPositionOs.xy, 0.0f, 1.0f );
o.uv = i.vTexCoord;
return o;
}
}
PS
{
#include "postprocess/common.hlsl"
#include "common/classes/Normals.hlsl"
Texture2D g_tColorBuffer < Attribute( "ColorBuffer" ); SrgbRead( true ); >;
float g_flLineWidth < Attribute("LineWidth"); Default(1.0); > ;
float g_flNormalThreshold < Attribute("NormalThreshold"); Default(0.3); > ;
float3 g_vLineColor < Attribute("LineColor"); Default3(0.05, 0.03, 0.08); > ;
float4 MainPs( PixelInput i ) : SV_Target0
{
float2 uv = CalculateViewportUv( i.vPositionSs.xy );
float4 color = g_tColorBuffer.Sample( g_sBilinearMirror, uv );
float2 pixel = i.vPositionSs.xy - g_vViewportOffset.xy;
float w = g_flLineWidth;
float3 n = Normals::Sample(pixel);
float3 nl = Normals::Sample(pixel + float2(-w, 0));
float3 nr = Normals::Sample(pixel + float2(w, 0));
float3 nd = Normals::Sample(pixel + float2(0, -w));
float3 nu = Normals::Sample(pixel + float2(0, w));
float turn = (1.0 - dot(n, nl)) + (1.0 - dot(n, nr))
+ (1.0 - dot(n, nd)) + (1.0 - dot(n, nu));
float edge = smoothstep(g_flNormalThreshold, g_flNormalThreshold * 2.0, turn);
color.rgb = lerp( color.rgb, g_vLineColor, edge );
return color;
}
}
edited:Here is the c# code I had to apply the post process effect.
public sealed class ToonPost : BasePostProcess<ToonPost>
{
static Material Shader = Material.FromShader( "shaders/toonpost.shader" );
public override void Render()
{
var blit = BlitMode.WithBackbuffer( Shader, Stage.AfterPostProcess, 100, false );
Blit( blit, "ToonPost" );
}
}
edited:I removed the Normals::Sample() and that seems to have fixed it for me. Best guess is the normal data gets lost at that stage of the pipeline or something