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

Revision 2442, 4.1 KB checked in by szirmay, 17 years ago (diff)
RevLine 
[2368]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
[2373]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;
[2368]36
37uniform float specularity;
[2376]38uniform float4 specularColor;
[2368]39
40
41struct MORIA_HALL_BASE_VSOUT
42{
43        float4 hPos : POSITION;
44        float4 texCoord           : TEXCOORD0;
[2373]45        float4 texCoord2      : TEXCOORD1;
[2368]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,
[2373]57                                                                                float2 atlasTex  : TEXCOORD2,
[2368]58                                                                                float3 tangent   : TEXCOORD3,
[2386]59                                                                                uniform float normalCoord,
60                                                                                uniform float texture_repeat)
[2368]61{
62        MORIA_HALL_BASE_VSOUT OUT = (MORIA_HALL_BASE_VSOUT) 0;
63       
[2386]64        texCoord2.xy *= texture_repeat;
[2368]65        OUT.texCoord = float4(texCoord1.xy, texCoord2.xy);     
66        if(normalCoord == 0)
[2373]67                OUT.texCoord2.xy = texCoord1;
[2368]68        else
[2373]69                OUT.texCoord2.xy = texCoord2;
70       
71        OUT.texCoord2.zw = atlasTex;
[2368]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
[2373]85float4 MoriaHallBase_PS(MORIA_HALL_BASE_VSOUT IN):COLOR0
[2368]86{       
87        float4 Color = 0;
[2373]88        float3 N = NormalMap(IN.wTangent, IN.wBinormal, IN.wNormal, IN.texCoord2.xy, bumpMap);
[2398]89        float dist = length(IN.wView);
90        float3 V = IN.wView / dist;
[2368]91        // read textures
92        float4 diffuseColor = tex2D(tileTexture, IN.texCoord.zw) * tex2D(detailTexture, IN.texCoord.xy);
[2373]93       
94//----------------------------------------------------------------------------------------------------------------
95//light1               
[2368]96        //light dir
[2376]97float3 L;
98float4 col;
99float3 lightCPos;
100float shadow;
101
[2398]102//if(dot(lightColor1, lightColor1) != 0)
103//{
[2376]104        L = wLightPos1.xyz - IN.wPos * wLightPos1.w;
[2368]105        //illumination
[2376]106        col = Illumination(N, L, V, lightColor1 * lightPower1, lightRange1, diffuseColor, specularity, specularColor);
[2373]107        //shadowing     
[2376]108        lightCPos = mul(LightView1, float4(IN.wPos, 1)).xyz;
109        shadow = shadowPoint(ShadowMap1Point, lightCPos, lightFarPlane1);
[2442]110        //shadow = 1;
[2368]111        Color += col * shadow; 
[2398]112       
113        //Color = col;
114//}
[2373]115
116//----------------------------------------------------------------------------------------------------------------
117//light2                       
[2376]118/*if(dot(lightColor2, lightColor2) != 0)
119{
[2373]120        //light dir
121        L = wLightPos2.xyz - IN.wPos * wLightPos2.w;
122        //illumination
[2376]123        col = Illumination(N, L, V, lightColor2 * lightPower2, lightRange2, diffuseColor, specularity, specularColor);
[2373]124        //shadowing     
125        lightCPos = mul(LightView2, float4(IN.wPos, 1)).xyz;
126        shadow = shadowPoint(ShadowMap2Point, lightCPos, lightFarPlane2);
127        Color += col * shadow; 
[2376]128}*/
[2368]129       
130        //do Path Map to gather indirect illumination
[2373]131       
[2422]132        float4 indirect = PathMapIndirect(PathMap, WeightIndexMap, WeightMap, IN.texCoord2.zw) * 1.2;
133        indirect *= diffuseColor;
[2442]134        //Color = Color + indirect*2.0;
[2373]135       
[2422]136        //Color += lightPower1 * diffuseColor * 0.0005;
[2417]137       
[2368]138        //gather caustics for all casters
139        //return diffuseColor;
[2398]140        Color.a = dist;
[2368]141        return Color;
142}
Note: See TracBrowser for help on using the repository browser.