1 | #include "res/shaders/lights.cg"
|
---|
2 | float4x4 mvp : ModelViewProjection;
|
---|
3 | float4x4 mv : ModelView;
|
---|
4 | float4x4 mvit : ModelViewIT;
|
---|
5 |
|
---|
6 |
|
---|
7 | sampler2D greenTex <string fileName = "green2.png";> = sampler_state {
|
---|
8 | minFilter = Linear;
|
---|
9 | magFilter = Linear;
|
---|
10 | wrapS = Repeat;
|
---|
11 | wrapT = Repeat;
|
---|
12 | };
|
---|
13 | sampler2D green2Tex<string fileName = "green4.png";> = sampler_state {
|
---|
14 | generateMipMap = true;
|
---|
15 | minFilter = Linear;
|
---|
16 | magFilter = Linear;
|
---|
17 | wrapS = Repeat;
|
---|
18 | wrapT = Repeat;
|
---|
19 | };
|
---|
20 |
|
---|
21 |
|
---|
22 | float4 vertex(uniform float offset,
|
---|
23 | float4 P : POSITION,
|
---|
24 | float4 N : NORMAL,
|
---|
25 | float2 uvIn : TEXCOORD0,
|
---|
26 | in float4 Cin : COLOR0,
|
---|
27 | out float4 CC : COLOR0,
|
---|
28 | out float3 Pcam : TEXCOORD1,
|
---|
29 | out float3 Ncam : TEXCOORD2,
|
---|
30 | out float2 uv : TEXCOORD0) : POSITION
|
---|
31 | {
|
---|
32 | CC.xyz = normalize(N.xyz);
|
---|
33 | float4 vert = P + N*offset;
|
---|
34 | Pcam = mul(mv, vert).xyz;
|
---|
35 | Ncam = mul(mvit, N).xyz;
|
---|
36 | uv = uvIn;
|
---|
37 | return mul(mvp, vert);
|
---|
38 | }
|
---|
39 |
|
---|
40 | float4 line( float4 col: COLOR0,
|
---|
41 | in float3 texcoord,
|
---|
42 | float3 Pcam : TEXCOORD1,
|
---|
43 | float3 Ncam : TEXCOORD2) : COLOR
|
---|
44 | {
|
---|
45 | float3 tan = normalize(col.xyz);
|
---|
46 | float3 wo = normalize(-Pcam);
|
---|
47 | float3 Nn = normalize(Ncam);
|
---|
48 | float d = abs(dot(Nn,wo));
|
---|
49 | float3 result;
|
---|
50 | if (d < 0.3)
|
---|
51 | return float4(0,0,0,1);
|
---|
52 | else
|
---|
53 | discard;
|
---|
54 | }
|
---|
55 |
|
---|
56 | float4 light( uniform float4 col,
|
---|
57 | in float3 texcoord,
|
---|
58 | float3 Pcam : TEXCOORD1,
|
---|
59 | float3 Ncam : TEXCOORD2) : COLOR
|
---|
60 | {
|
---|
61 | float3 wo = normalize(-Pcam);
|
---|
62 | float4 result;// = ambient;
|
---|
63 | float3 Nn = normalize(Ncam);
|
---|
64 |
|
---|
65 | float4 scolor = float4(1.0,1.0,1.0,1.0);
|
---|
66 | float3 Ln = normalize(float3(0,0,-1)-Pcam);
|
---|
67 | float3 lcolor = float3(1,1,1);
|
---|
68 | float3 Hn = normalize(wo + Ln);
|
---|
69 | float ldn = dot(Ln,Nn);
|
---|
70 | float hdn = dot(Hn,Nn);
|
---|
71 | float4 litV = lit(ldn, hdn, 32);
|
---|
72 |
|
---|
73 | float ds,ss;
|
---|
74 | if (litV.y > 0.5)
|
---|
75 | ds = 1.0;
|
---|
76 | else
|
---|
77 | ds = 0.3;
|
---|
78 |
|
---|
79 | if (litV.z > 0.5)
|
---|
80 | ss = 1.0;
|
---|
81 | else
|
---|
82 | ss = 0.0;
|
---|
83 | float lineS = abs(dot(wo,Nn));
|
---|
84 | if (lineS < 0.3)
|
---|
85 | lineS = 0;
|
---|
86 | else
|
---|
87 | lineS = 1.0;
|
---|
88 | result = col*ds + scolor*ss;
|
---|
89 | result *= lineS;
|
---|
90 | return result;
|
---|
91 | }
|
---|
92 |
|
---|
93 | technique parts <string target = "both";>
|
---|
94 | {
|
---|
95 | pass p0
|
---|
96 | {
|
---|
97 | VertexProgram = compile arbvp1 vertex(0.0f);
|
---|
98 | FragmentProgram = compile arbfp1 light(float4(1.0,0.0,0.0,1.0));
|
---|
99 |
|
---|
100 | }
|
---|
101 | /*
|
---|
102 | pass p1
|
---|
103 | {
|
---|
104 | LineWidth = 5.0;
|
---|
105 | CullFaceEnable = true;
|
---|
106 | PolygonMode = int2(FrontAndBack,Line);
|
---|
107 | VertexProgram = compile arbvp1 vertex(0.01f);
|
---|
108 | FragmentProgram = compile arbfp1 line();
|
---|
109 |
|
---|
110 | }
|
---|
111 | */
|
---|
112 | } |
---|