source: GTP/branches/IllumWPdeliver2008dec/IlluminationWP/demos/OgreDemos/media/MORIA/sword.hlsl @ 3255

Revision 3255, 3.5 KB checked in by szirmay, 15 years ago (diff)
Line 
1#include "illum.hlsl"
2
3float4 readCubeMap(samplerCUBE cm, float3 coord)               
4{
5        float4 color = texCUBE( cm, float3(coord.xy, - coord.z) );
6        color.a = 1;
7        return color;
8}
9
10struct Sword_VS_OUT
11{
12 float4 hPos : POSITION;
13 float2 texCoord : TEXCOORD0;
14 float3 wView             : TEXCOORD2;
15 float3 wTangent          : TEXCOORD3;
16 float3 wBinormal         : TEXCOORD4;
17 float3 wNormal                   : TEXCOORD5;
18 float3 wPos    : TEXCOORD1; 
19};
20
21uniform float4x4 WorldViewProj;
22uniform float4x4 World;
23uniform float4x4 WorldI;
24
25uniform float3 wCamPos;
26
27uniform float4 wLightPos1;
28uniform float4 wLightPos2;
29uniform float4 lightRange1;
30uniform float4 lightRange2;
31uniform float lightPower1;
32uniform float lightPower2;
33uniform float4 lightColor1;
34uniform float4 lightColor2;
35                                               
36uniform float4x4 LightView1;
37uniform float4x4 LightView2;
38uniform float lightFarPlane1;
39uniform float lightFarPlane2;
40
41uniform float specularity;
42uniform float4 specularColor;
43
44
45Sword_VS_OUT Sword_VS(float4 position :POSITION,
46                                                                                float3 normal :NORMAL,
47                                                                                float2 texCoord : TEXCOORD0,
48                                                                                float3 tangent   : TEXCOORD1)
49{
50        Sword_VS_OUT OUT = (Sword_VS_OUT) 0;
51       
52        OUT.texCoord = texCoord;
53                       
54        OUT.hPos = mul(WorldViewProj, position);
55        OUT.wPos = mul(World, position).xyz;
56       
57        OUT.wView = wCamPos - OUT.wPos;
58       
59        OUT.wTangent = normalize(mul(float4(tangent, 1),WorldI)).xyz;
60        OUT.wNormal = normalize(mul(float4(normal, 1),WorldI)).xyz;             
61        OUT.wBinormal = cross(OUT.wTangent, OUT.wNormal).xyz;           
62               
63        return OUT;
64}
65
66struct ShadedTex_OUT
67{
68 float4 vPos : POSITION;
69 float4 texCoord : TEXCOORD0;
70 float4 wNormal : TEXCOORD1;
71 float4 wPos    : TEXCOORD2; 
72};
73
74float4 Sword_Metal_PS(  ShadedTex_OUT IN,
75                                                uniform samplerCUBE CubeMap : register(s0),
76                                                uniform sampler2D colorTexture : register(s1),
77                                                uniform float3 lastCenter):COLOR0
78{       
79        if(!tex2D(colorTexture, IN.texCoord).a)
80                discard;
81       
82        float3 F0 = tex2D(colorTexture, IN.texCoord).rgb;
83               
84        float4 Color;
85        float3 N = normalize(IN.wNormal.xyz);
86        float3 RR;     
87        float3 V = normalize(IN.wPos.xyz - wCamPos);
88        float3 R = reflect( V, N);
89               
90        Color = readCubeMap(CubeMap, R);
91       
92        float ctheta_in = dot(N, R);
93        float ctheta_out = dot(N, -V);
94
95        float3 F = 0;
96       
97        float3 H = normalize(R - V);    // felezõvektor
98        float cbeta  = dot(H,R);               
99        F = F0 + (1 - F0) * pow(1 - cbeta, 5);
100       
101               
102        return Color * float4(F,1);             
103}
104
105float4 Sword_Handle_PS(  Sword_VS_OUT IN,
106                                                                        uniform sampler2D colorTexture : register(s0),
107                                                                        uniform sampler2D bumpTexture : register(s1),
108                                                                        uniform samplerCUBE ShadowMap1Point : register(s2),
109                                                                        uniform samplerCUBE ShadowMap2Point : register(s3),
110                                                                        uniform float3 cameraPos,
111                                                                        uniform float3 lastCenter):COLOR0
112{               
113        float4 Color = 0;
114        float3 N = IN.wNormal;//NormalMap(IN.wTangent, IN.wBinormal, IN.wNormal, IN.texCoord, bumpTexture);
115        float3 V = normalize(IN.wView);
116               
117        float3 L;
118        float4 col;
119        float3 lightCPos;
120        float shadow;
121
122        float4 diffuseColor = tex2D(colorTexture, IN.texCoord);
123       
124//if(dot(lightColor1, lightColor1) != 0)
125//{
126        L = wLightPos1.xyz - IN.wPos * wLightPos1.w;
127        //illumination
128        col = Illumination(N, L, V, lightColor1 * lightPower1, lightRange1, diffuseColor, specularity, specularColor);
129        //shadowing     
130        lightCPos = mul(LightView1, float4(IN.wPos, 1)).xyz;
131        shadow = shadowPoint(ShadowMap1Point, lightCPos, lightFarPlane1);
132        Color += col;// * shadow;
133
134        Color += diffuseColor * lightPower1 * 0.001;
135       
136        return Color;   
137}
Note: See TracBrowser for help on using the repository browser.