I was trying to write a custom function node but I’m getting syntax errors.
void Outline_float(float4 ScreenPos, float4 Color, Texture2D DepthNormalsTexture, SamplerState Sampler, float2 Texel, float SampleDistance, float Falloff, float SensitivityNormals, float SensitivityDepth, out float4 Out)
{
float ns_DecodeFloatRG (float2 enc) {
float2 kDecodeDot = float2(1.0, 1 / 255.0);
return dot(enc, kDecodeDot);
}
float checkSame(float2 centerNormal, float centerDepth, float4 theSample, float sensitivityNormals, float sensitivityDepth) {
float2 diff = abs(centerNormal - theSample.xy) * sensitivityNormals;
int isSameNormal = (diff.x + diff.y) < 0.1;
float sampleDepth = ns_DecodeFloatRG(theSample.zw);
float zdiff = abs(centerDepth - sampleDepth);
int isSameDepth = zdiff * sensitivityDepth < 0.99 * centerDepth;
return (isSameNormal * isSameDepth) ? 1.0 : 0.0;
}
float4 edgeColor() {
float sampleSizeX = Texel.x;
float sampleSizeY = Texel.y;
float2 screenUV = ScreenPos.xy;
float2 _uv2 = screenUV + float2(-sampleSizeX, +sampleSizeY) * SampleDistance;
float2 _uv3 = screenUV + float2(+sampleSizeX, -sampleSizeY) * SampleDistance;
float2 _uv4 = screenUV + float2(sampleSizeX, sampleSizeY) * SampleDistance;
float2 _uv5 = screenUV + float2(-sampleSizeX, -sampleSizeY) * SampleDistance;
float4 center = SAMPLE_TEXTURE2D(DepthNormalsTexture, Sampler, screenUV);
float4 sample1 = SAMPLE_TEXTURE2D(DepthNormalsTexture, Sampler, _uv2);
float4 sample2 = SAMPLE_TEXTURE2D(DepthNormalsTexture, Sampler, _uv3);
float4 sample3 = SAMPLE_TEXTURE2D(DepthNormalsTexture, Sampler, _uv4);
float4 sample4 = SAMPLE_TEXTURE2D(DepthNormalsTexture, Sampler, _uv5);
float edge = 1.0;
float2 centerNormal = center.xy;
float centerDepth = ns_DecodeFloatRG(center.zw);
float d = clamp(centerDepth * Falloff - 0.05, 0.0, 1.0);
float4 depthFade = float4(d, d, d, 1.0);
edge *= checkSame(centerNormal, centerDepth, sample1, sensitivityNormals, sensitivityDepth);
edge *= checkSame(centerNormal, centerDepth, sample2, sensitivityNormals, sensitivityDepth);
edge *= checkSame(centerNormal, centerDepth, sample3, sensitivityNormals, sensitivityDepth);
edge *= checkSame(centerNormal, centerDepth, sample4, sensitivityNormals, sensitivityDepth);
return edge * Color + (1.0 - edge) * (depthFade * Color);
}
Out = edgeColor();
}
I don’t see where my errors are…