THIS IS SOLVED (question below is not), normal was in object space and not world space -> ||I'm guessing I'm calculating the view direction wrong? I'm not sure any other way I should do it though
When remaking this pass of the shader in shader graph it appears to work perfectly fine (first image is written shader, second is shadergraph). I don't wanna use shader graph though because I'd like to have my outline and the normal render be in the same shader file
Code I believe to be relevant (full shader file is attached):
// in the "Normal Render" pass:
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 normal : NORMAL;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float3 normal : NORMAL;
float3 viewDir : TEXCOORD1;
};
// In vertex shader, o is v2f
o.normal = normalize(v.normal);
o.viewDir = UnityWorldSpaceViewDir(mul(unity_ObjectToWorld, v.vertex).xyz);
// in frag, i is v2f
float product = fresnel(i.normal, i.viewDir, _FresnelPower); // fresnel power is 1
return product;
float fresnel(float3 normal, float3 viewDir, float power)
{
return pow(1 - saturate(dot(normalize(normal), normalize(viewDir))), power);
}
```||
Also if possible, I'd like to know why the stencil appears to not work right, I'd like the outline to not overlap the normal render (3rd image shows this best). And everywhere I look I appear to be doing this correctly despite it not working correctly, unless I'm completely mistaken on how it should look
In outline pass:
```js
Stencil
{
Ref 2
Comp Less // Changing this does nothing, even when I change it to Never, it still renders
Pass Keep
}
In normal render pass:
Stencil
{
Ref 2
Comp Always
Pass Replace
}
(again if the above isn't sufficient the whole shader file is provided below)