OK, so I’m trying to accomplish a custom shadowmap rendering algorithm (purely for learning purposes atm)
What I’ve got so far is a setup that renders a grayscale depth texture from a camera.
What I would like to do next is render the depth texture from the same camera, but have depth relative to an arbitrary point in 3D space (my light source, for example).
First of all, how can I accomplish this? I’m using the following as a replacement shader to render the depth:
Shader "Hidden/RenderDepth" {
SubShader {
Tags { "RenderType"="Opaque" }
Pass {
Fog { Mode Off }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 depth : TEXCOORD0;
};
v2f vert (appdata_base v) {
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
UNITY_TRANSFER_DEPTH(o.depth);
return o;
}
half4 frag(v2f i) : COLOR {
UNITY_OUTPUT_DEPTH(i.depth);
}
ENDCG
}
}
}
Second of all, how can I then take these two render textures and actually compute the final shadows? I imagine I would combine these into another shader, which checks each pixel of the camera-space depth map, somehow transforms it relative to the light-space depth map, and does a simple greater-than check to see whether a pixel should be in shadow, but I have no idea how to actually transform a texture coordinate from one texture to the other (I need my camera-space depth map to be in perspective and my light-space depth map to be orthographic, btw)
Thanks for your help in advance.