Hello! I’m currently writing a Unity shader to replicate a setup for a particular form of stylized lighting we have working in Blender. I’ve written a lot of shaders in the past outside of Unity (GLSL/HLSL) and what I seem to be struggling with is getting Unity to feed information into the shader; seems there’s a lot of preconditions which need to be met and I’m sure I’m just missing one.
With “o.lightDir = abs(normalize(ObjSpaceLightDir(v.vertex)));” uncommented I would expect to see the object colored with the normal to the most influential light, but it’s just black. I’ve seen in the past people getting a zero from ObjSpaceLightDir when LightMode is not ForwardBase, but I believe I have configured that correctly. Do recent Unity versions have any other things I need to change for this to work?
Shader is as follows:
Shader "Custom/Inked"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
Pass
{
Tags { "LightMode"="ForwardBase" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct v2f
{
float4 vertex : SV_POSITION;
float3 lightDir : TEXCOORD1;
};
fixed4 _Color;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
// This works perfectly.
// o.lightDir = v.normal;
// This just gives me a black object.
//o.lightDir = abs(normalize(ObjSpaceLightDir(v.vertex)));
return o;
}
fixed4 frag(v2f i) : SV_Target
{
return fixed4(i.lightDir, 1);
}
ENDCG
}
}
}
