source: GTP/trunk/App/Demos/Illum/Shark3D/version164x12u/IllumDemo/src/res/levelutil/shader/prog/d3d9_hlsl/gtp_cau_photonmap_d3d9_hlsl_ps3x0.s3d_shadercode @ 2196

Revision 2196, 2.5 KB checked in by szirmay, 17 years ago (diff)
Line 
1///////////////////////////////////////////////////////////////////////////////
2//
3//      ##  ######
4//       ######  ###
5//  ## ###############        Shark 3D Engine (www.shark3d.com)
6//   ########## # # #
7//    ########                Copyright (c) 1996-2006 Spinor GmbH.
8//   ######### # # #          All rights reserved.
9//  ##   ##########
10//      ##
11//
12///////////////////////////////////////////////////////////////////////////////
13
14
15#define NITERATION 5
16
17struct PS_INPUT
18{
19    float3 worldV     : TEXCOORD0;
20    float3 WNormal   : TEXCOORD1;
21    float3 CUBEPos   : TEXCOORD2;
22    float3 lastCenter :TEXCOORD3;
23};
24
25sampler distanceSamp: register(s0);
26
27
28half3 Hit(samplerCUBE tex, half3 R, half3 p0)
29{
30        float rl = texCUBE(tex, R).r;
31        float dp = rl - dot(p0, R);
32        float3 p = p0 + R * dp;
33        float ppp = length(p) / texCUBE(tex, p).r;
34        float dun = 0, dov = 0, pun = ppp, pov = ppp;
35        if (ppp < 1) dun = dp; else dov = dp;
36        float dl = max( dp + rl * (1 - ppp), 0);
37        float3 RR = p0 + R * dl;
38
39        for(int i = 0; i < NITERATION; i++) {
40                float ddl;
41                float llp = length(RR) / texCUBE(tex, RR).r;
42                if (llp < 1) {
43                        dun = dl; pun = llp;
44                        ddl = (dov == 0) ? rl * (1 - llp) :
45                                (dl - dov) * (1 - llp)/(llp - pov);
46                } else {
47                        dov = dl; pov = llp;
48                        ddl = (dun == 0) ? rl * (1 - llp) :
49                                (dl - dun) * (1 - llp)/(llp - pun);
50                }
51                dl = max(dl + ddl, 0);
52                RR = p0 + R * dl;
53        }
54        return RR;
55}
56
57
58
59///////////////////////////////////////////////////////////////////////////////
60// Pixelshader
61// Profile: 3x0
62
63
64float4 main(PS_INPUT input): COLOR0
65{
66 const float g_RefractFactor = 0.95;
67
68 // direction vector from light to shaded point in world space
69 float3 V = normalize(input.worldV);
70 // vertex normal in world space
71 float3 N = normalize(input.WNormal);
72 // refraction direction
73 float3 R = refract(V, N, g_RefractFactor);
74 // vertex position in cubemap space
75 float3 X = input.CUBEPos;
76 float3 dir = Hit(distanceSamp, R, X);
77 //dir = input.lastCenter;
78 //dir = N;
79 //return float4(input.lastCenter,1);
80// return texCUBE(distanceSamp,X).r;
81 return float4(dir,1);
82}
83
84///////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.