source: java/client_3D/static/shared/res/shaders/refraction.cgfx @ 1101

Last change on this file since 1101 was 65, checked in by Maciej Komosinski, 14 years ago

added sources of the 3D client for the Framsticks server

File size: 2.6 KB
Line 
1float4x4 mvp : ModelViewProjection;
2float4x4 mv : ModelView;
3float4x4 mvit : ModelViewIT;
4float3 refFactor = float3(1.1,1.3,1.5);
5float fresOffset = 0.1;
6float fresScale = 0.3;
7float fresPower = 0.2;
8
9samplerCUBE skybox : SKYBOX;
10string jointGeo = "cylinder.obj";
11sampler2D normal<string fileName = "normal.tga";> = sampler_state {
12  generateMipMap = true;
13  minFilter = Linear;
14  magFilter = Linear;
15  wrapS = Repeat;
16  wrapT = Repeat;
17};
18
19float3 expand(float3 v) { return (v-0.5)*2; }
20float4 vertex(uniform float4x4 modelViewProj,
21              uniform float4x4 modelView,
22              uniform float4x4 modelViewIT,
23              float4 P : POSITION,
24              float4 N : NORMAL,
25              float2 uvIn : TEXCOORD0,
26                 in float4 Cin : COLOR0,
27
28              out float3 CC : COLOR0,
29                          out float2 uv : TEXCOORD0,
30              out float3 Pcam : TEXCOORD1,
31              out float3 Ncam : TEXCOORD2) : POSITION
32{
33    CC.xyz =  normalize(N.xyz);
34    uv = uvIn;
35    Pcam = mul(modelView, P).xyz;
36    Ncam = mul(modelViewIT, N).xyz;
37    return mul(modelViewProj, P);
38}
39
40
41float4 light(   uniform float4 col,
42                  in float3 texcoord,
43                  float3 Pcam : TEXCOORD1,
44                  float3 Ncam : TEXCOORD2) : COLOR
45{
46        float3 tan = normalize(col.xyz);
47    float3 wo = normalize(-Pcam);
48    float3 result;// = ambient;
49    float3 Nn = normalize(Ncam);
50    float3 Nn2 = Nn;
51float3 biNorm = normalize(cross(tan,Nn));
52    float3x3 toTexture = transpose(float3x3(tan,biNorm,Nn));
53
54        Nn = mul(toTexture,expand(tex2D(normal,texcoord)));
55        Nn = normalize(Nn+2*Nn2);
56
57   float3 r, tred, tblue, tgreen;   
58   r = reflect(Pcam,Nn);
59   tred = refract(Pcam,Nn,refFactor.r);
60   tgreen = refract(Pcam,Nn,refFactor.g);
61   tblue = refract(Pcam,Nn,refFactor.b);
62   
63   r = texCUBE(skybox,r.rgb).rgb;
64   col.r = texCUBE(skybox,tred).r;
65   col.g = texCUBE(skybox,tred).g;
66   col.b = texCUBE(skybox,tred).b;
67   float fres = fresOffset + fresScale * pow(1 + dot(normalize(Pcam), Nn),
68                                        fresPower );
69   //col.rgb = r.rgb;
70   return float4(lerp(col.rgb, r.rgb, fres).rgb,1);                                     
71   //return col;
72}
73
74technique red <string target = "joints";>
75{
76        pass p0
77        {
78                VertexProgram = compile arbvp1 vertex(mvp, mv, mvit);
79                FragmentProgram = compile arbfp1 light(float4(1.0, 0.0 ,0.0 ,1.0));
80       
81        }
82}
83
84technique red <string target = "parts";>
85{
86        pass p0
87        {
88                VertexProgram = compile arbvp1 vertex(mvp, mv, mvit);
89                FragmentProgram = compile arbfp1 light(float4(0.0, 1.0 ,0.0 ,1.0));
90       
91        }
92}
Note: See TracBrowser for help on using the repository browser.