source: GTP/trunk/App/Demos/Illum/Ogre/Media/MORIA/MoriaHallBase.hlsl @ 2422

Revision 2422, 4.1 KB checked in by szirmay, 17 years ago (diff)
Line 
1//#define VARIANCE_SHADOW_MAPPING
2
3#define MAX_LIGHT 2
4#define MAX_CAU_CASTER 2
5
6#include "illum.hlsl"
7
8uniform sampler2D tileTexture : register(s0);
9uniform sampler2D detailTexture : register(s1);
10uniform sampler2D bumpMap : register(s2);
11uniform sampler2D PathMap : register(s3);
12uniform sampler2D WeightIndexMap : register(s4);
13uniform sampler2D WeightMap : register(s5);
14uniform samplerCUBE ShadowMap1Point : register(s6);
15uniform samplerCUBE ShadowMap2Point : register(s7);
16
17uniform float4x4 WorldViewProj;
18uniform float4x4 World;
19uniform float4x4 WorldI;
20
21uniform float3 wCamPos;
22
23uniform float4 wLightPos1;
24uniform float4 wLightPos2;
25uniform float4 lightRange1;
26uniform float4 lightRange2;
27uniform float lightPower1;
28uniform float lightPower2;
29uniform float4 lightColor1;
30uniform float4 lightColor2;
31                                               
32uniform float4x4 LightView1;
33uniform float4x4 LightView2;
34uniform float lightFarPlane1;
35uniform float lightFarPlane2;
36
37uniform float specularity;
38uniform float4 specularColor;
39
40
41struct MORIA_HALL_BASE_VSOUT
42{
43        float4 hPos : POSITION;
44        float4 texCoord           : TEXCOORD0;
45        float4 texCoord2      : TEXCOORD1;
46        float3 wView              : TEXCOORD2;
47        float3 wTangent           : TEXCOORD3;
48        float3 wBinormal          : TEXCOORD4;
49        float3 wNormal            : TEXCOORD5;
50        float3 wPos                       : TEXCOORD6; 
51};
52
53MORIA_HALL_BASE_VSOUT MoriaHallBase_VS(float4 position :POSITION,
54                                                                                float3 normal :NORMAL,
55                                                                                float2 texCoord1 : TEXCOORD0,
56                                                                                float2 texCoord2 : TEXCOORD1,
57                                                                                float2 atlasTex  : TEXCOORD2,
58                                                                                float3 tangent   : TEXCOORD3,
59                                                                                uniform float normalCoord,
60                                                                                uniform float texture_repeat)
61{
62        MORIA_HALL_BASE_VSOUT OUT = (MORIA_HALL_BASE_VSOUT) 0;
63       
64        texCoord2.xy *= texture_repeat;
65        OUT.texCoord = float4(texCoord1.xy, texCoord2.xy);     
66        if(normalCoord == 0)
67                OUT.texCoord2.xy = texCoord1;
68        else
69                OUT.texCoord2.xy = texCoord2;
70       
71        OUT.texCoord2.zw = atlasTex;
72               
73        OUT.hPos = mul(WorldViewProj, position);
74        OUT.wPos = mul(World, position);
75       
76        OUT.wView = wCamPos - OUT.wPos;
77       
78        OUT.wTangent = normalize(mul(float4(tangent, 1),WorldI)).xyz;
79        OUT.wNormal = normalize(mul(float4(normal, 1),WorldI)).xyz;             
80        OUT.wBinormal = cross(OUT.wTangent, OUT.wNormal).xyz;           
81               
82        return OUT;
83}
84
85float4 MoriaHallBase_PS(MORIA_HALL_BASE_VSOUT IN):COLOR0
86{       
87        float4 Color = 0;
88        float3 N = NormalMap(IN.wTangent, IN.wBinormal, IN.wNormal, IN.texCoord2.xy, bumpMap);
89        float dist = length(IN.wView);
90        float3 V = IN.wView / dist;
91        // read textures
92        float4 diffuseColor = tex2D(tileTexture, IN.texCoord.zw) * tex2D(detailTexture, IN.texCoord.xy);
93       
94//----------------------------------------------------------------------------------------------------------------
95//light1               
96        //light dir
97float3 L;
98float4 col;
99float3 lightCPos;
100float shadow;
101
102//if(dot(lightColor1, lightColor1) != 0)
103//{
104        L = wLightPos1.xyz - IN.wPos * wLightPos1.w;
105        //illumination
106        col = Illumination(N, L, V, lightColor1 * lightPower1, lightRange1, diffuseColor, specularity, specularColor);
107        //shadowing     
108        lightCPos = mul(LightView1, float4(IN.wPos, 1)).xyz;
109        shadow = shadowPoint(ShadowMap1Point, lightCPos, lightFarPlane1);
110        Color += col * shadow; 
111       
112        //Color = col;
113//}
114
115//----------------------------------------------------------------------------------------------------------------
116//light2                       
117/*if(dot(lightColor2, lightColor2) != 0)
118{
119        //light dir
120        L = wLightPos2.xyz - IN.wPos * wLightPos2.w;
121        //illumination
122        col = Illumination(N, L, V, lightColor2 * lightPower2, lightRange2, diffuseColor, specularity, specularColor);
123        //shadowing     
124        lightCPos = mul(LightView2, float4(IN.wPos, 1)).xyz;
125        shadow = shadowPoint(ShadowMap2Point, lightCPos, lightFarPlane2);
126        Color += col * shadow; 
127}*/
128       
129        //do Path Map to gather indirect illumination
130       
131        float4 indirect = PathMapIndirect(PathMap, WeightIndexMap, WeightMap, IN.texCoord2.zw) * 1.2;
132        indirect *= diffuseColor;
133        //Color = Color + indirect * 1.5;
134       
135        //Color += lightPower1 * diffuseColor * 0.0005;
136       
137        //gather caustics for all casters
138        //return diffuseColor;
139        Color.a = dist;
140        return Color;
141}
Note: See TracBrowser for help on using the repository browser.