View difference between Paste ID: prSbPxMJ and U2BfBpJT
SHOW: | | - or go back to the newest paste.
1
//Cg
2
3
4
#define NEAR 0.5
5
#define FAR 400
6
7
8
float unpackDepth(uniform float wnear, uniform float wfar, float s){
9
    // depth equations from http://www.codermind.com/articles/Depth-buffer-tutorial.html
10
    // Hopefully they are correct
11
    //(wfar - (wnear * wfar)/w) / (wfar - wnear) = s
12
    // w = (wnear * wfar)/(wfar - s*(wfar - wnear))
13
    return (wnear * wfar)/(wfar - s*(wfar - wnear));
14
}
15
16
17-
float vshader(float4 vtx_position : POSITION,
17+
void vshader(float4 vtx_position : POSITION,
18
             out float4 l_position : POSITION,
19
             out float2 l_texcoord : TEXCOORD0,
20
             out float2 l_texcoordD : TEXCOORD1,
21
             uniform float4 texpad_depth,
22
             uniform float4x4 mat_modelproj)
23
{
24
   l_position = mul(mat_modelproj, vtx_position);
25
   l_texcoord = vtx_position.xz;
26
   l_texcoordD = (vtx_position.xz * texpad_depth.xy) + texpad_depth.xy;
27
}
28
29
30-
float fshader(out float4 o_color: COLOR,
30+
void fshader(out float4 o_color: COLOR,
31
             float2 l_texcoord : TEXCOORD0,
32
             float2 l_texcoordD : TEXCOORD1,
33-
             float2 camera_fov_sin,
33+
             uniform float2 k_camera_fov_sin,
34
             uniform sampler2D k_depth : TEXUNIT0)
35
{
36
   float pixel_depth = tex2D(k_depth, l_texcoordD).r;
37
38
   float z_pos = unpackDepth(NEAR, FAR, pixel_depth);
39-
   float x_pos = (camera_fov_sin * l_texcoordD).x;
39+
   float x_pos = k_camera_fov_sin.x * l_texcoordD.x * pixel_depth;
40-
   float y_pos = (camera_fov_sin * l_texcoordD).y;
40+
   float y_pos = k_camera_fov_sin.y * l_texcoordD.y * pixel_depth;
41
42
   float3 pixel_pos = float3(x_pos, y_pos, z_pos);
43
44
   o_color.rgb = pixel_pos;
45
   o_color.a = 1;
46
}
47