1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#ifndef TASTT_LIGHTING
#define TASTT_LIGHTING
#include "AutoLight.cginc"
#include "UnityPBSLighting.cginc"
#include "ray_march.cginc"
#include "pbr.cginc"
#include "poi.cginc"
#include "stt_generated.cginc"
#include "stt_text.cginc"
void getVertexLightColor(inout v2f i)
{
#if defined(VERTEXLIGHT_ON)
float3 light_pos = float3(unity_4LightPosX0.x, unity_4LightPosY0.x,
unity_4LightPosZ0.x);
float3 light_vec = light_pos - i.worldPos;
float3 light_dir = normalize(light_vec);
float ndotl = DotClamped(i.normal, light_dir);
// Light fills an expanding sphere with surface area 4 * pi * r^2.
// By conservation of energy, this means that at distance r, light intensity
// is proportional to 1/(r^2).
float attenuation = 1 / (1 + dot(light_vec, light_vec) * unity_4LightAtten0.x);
i.vertexLightColor = unity_LightColor[0].rgb * ndotl * attenuation;
i.vertexLightColor = Shade4PointLights(
unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
unity_LightColor[0].rgb,
unity_LightColor[1].rgb,
unity_LightColor[2].rgb,
unity_LightColor[3].rgb,
unity_4LightAtten0, i.worldPos, i.normal
);
#endif
}
v2f vert(appdata v)
{
v2f o;
o.position = UnityObjectToClipPos(v.position);
o.worldPos = mul(unity_ObjectToWorld, v.position);
o.normal = UnityObjectToWorldNormal(v.normal);
o.uv = v.uv;
getVertexLightColor(o);
return o;
}
fixed4 frag(v2f i, out float depth : SV_DepthLessEqual) : SV_Target
{
depth = -1000.0;
return stt_ray_march(i, depth);
}
#endif // TASTT_LIGHTING
|