source: java/client_3D/static/shared/res/shaders/bumpy.cgfx @ 1122

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

added sources of the 3D client for the Framsticks server

File size: 2.2 KB
Line 
1#include "res/shaders/lights.cg"
2float4x4 mvp : ModelViewProjection;
3float4x4 mv : ModelView;
4float4x4 mvit : ModelViewIT;
5
6
7sampler2D diffuse <string fileName = "stone.jpg";> = sampler_state {
8  minFilter = Linear;
9  magFilter = Linear;
10  wrapS = Repeat;
11  wrapT = Repeat;
12};
13sampler2D normal<string fileName = "normal.tga";> = sampler_state {
14  generateMipMap = true;
15  minFilter = Linear;
16  magFilter = Linear;
17  wrapS = Repeat;
18  wrapT = Repeat;
19};
20
21float4 vertex(uniform float4x4 modelViewProj,
22              uniform float4x4 modelView,
23              uniform float4x4 modelViewIT,
24              float4 P : POSITION,
25              float4 N : NORMAL,
26              float2 uvIn : TEXCOORD0,
27                 in float4 Cin : COLOR0,
28              out float4 CC : COLOR0,
29              out float3 Pcam : TEXCOORD1,
30              out float3 Ncam : TEXCOORD2,
31              out float2 uv : TEXCOORD0) : POSITION
32{
33    CC.xyz =  normalize(N.xyz);
34    Pcam = mul(modelView, P).xyz;
35    Ncam = mul(modelViewIT, N).xyz;
36    //float3x3 rotation = (float3x3)modelView;
37    //Ncam.xyz = mul(rotation,N.xyz);
38   
39    uv = uvIn;
40    return mul(modelViewProj, P);
41}
42
43float3 expand(float3 v) { return (v-0.5)*2; }
44
45float4 light(   float4 col: COLOR0,
46                  in float3 texcoord,
47                  float3 Pcam : TEXCOORD1,
48                  float3 Ncam : TEXCOORD2) : COLOR
49{
50    float3 tan = normalize(col.xyz);
51    float3 wo = normalize(-Pcam);
52    float3 result;// = ambient;
53    float3 Nn = normalize(Ncam);
54   float3 biNorm = normalize(cross(tan,Nn));
55    float3x3 toTexture = transpose(float3x3(tan,biNorm,Nn));
56
57        Nn = mul(toTexture,expand(tex2D(normal,texcoord)));
58
59   
60         float3 scolor = float3(1.0,1.0,1.0);
61        float3 Ln = normalize(float3(0,0,-1)-Pcam);
62        float3 lcolor = float3(1,1,1);
63        float3 Hn = normalize(wo + Ln);
64        float ldn = dot(Ln,Nn);
65        float hdn = dot(Hn,Nn);
66        float4 litV = lit(ldn, hdn, 32);
67           
68    result = tex2D(diffuse ,texcoord)*litV.y;
69    return float4(result, 1.);
70}
71
72technique stone <string target = "both";>
73{
74        pass p0
75        {
76                VertexProgram = compile arbvp1 vertex(mvp, mv, mvit);
77                FragmentProgram = compile arbfp1 light();
78       
79        }
80}
Note: See TracBrowser for help on using the repository browser.