forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlight.sha
More file actions
44 lines (39 loc) · 1.51 KB
/
light.sha
File metadata and controls
44 lines (39 loc) · 1.51 KB
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
//Cg
//
//Cg profile arbvp1 arbfp1
void vshader(float4 vtx_position : POSITION,
out float4 l_position : POSITION,
out float4 l_pos : TEXCOORD0,
uniform float4x4 mat_modelproj,
uniform float4x4 trans_model_to_clip)
{
l_position=mul(mat_modelproj, vtx_position);
l_pos=mul(trans_model_to_clip, vtx_position);
l_pos.z = l_pos.w;
}
void fshader(float4 l_pos: TEXCOORD0,
uniform sampler2D k_texnormal : TEXUNIT0,
uniform sampler2D k_texalbedo : TEXUNIT1,
uniform sampler2D k_texdepth : TEXUNIT2,
uniform float4 texpad_texnormal,
uniform float4 k_proj,
uniform float4 vspos_model,
uniform float4 k_lightcolor,
uniform float4 row0_model_to_view,
out float4 o_color: COLOR)
{
float3 screen = l_pos.xyz / l_pos.w;
float2 texcoords = float2(screen.xy) * texpad_texnormal.xy + texpad_texnormal.xy;
float4 albedo = tex2D(k_texalbedo, texcoords);
float4 normal = tex2D(k_texnormal, texcoords);
float depth = tex2D(k_texdepth, texcoords);
float3 view = (screen.xzy * k_proj.xyz) / (depth + k_proj.w);
float3 lightvec = float3(vspos_model) - view;
float lightdist = length(lightvec);
float3 lightdir = lightvec / lightdist;
float scaledist = (lightdist / row0_model_to_view.x);
float falloff = saturate(1.0 - scaledist);
float brite = falloff * falloff * dot(lightdir, float3(normal));
o_color = albedo * k_lightcolor * brite;
o_color.a = 1;
}