//#define VARIANCE_SHADOW_MAPPING #define MAX_LIGHT 2 #define MAX_CAU_CASTER 2 #define HIGH_QUALITY struct Shaded_OUT { float4 vPos : POSITION; float4 wNormal : TEXCOORD0; float4 wPos : TEXCOORD1; }; Shaded_OUT MorphedSphere_VS(float4 position : POSITION, float4 normal : NORMAL, float2 texCoord : TEXCOORD0, uniform float4x4 WorldViewProj, uniform float4x4 World, uniform float4x4 WorldInv, uniform float t) { Shaded_OUT OUT; float dist = sin(t + position.x * position.y * 5.0 + position.z) * 0.3; float3 dist2 = sin(t + position.x * position.y * 5.0 + position.z + float3(0.005,0.005,0.001)) * 0.3; float3 pos2 = (position + float3(0.001,0.001,0.001)); pos2 += normalize(pos2) * dist; position.xyz += normalize(position.xyz) * dist; normal.xyz = cross(cross(normalize(pos2 - position.xyz), normal.xyz), normalize(pos2 - position.xyz)); if(length(normal.xyz < 0.01)) normal = position; OUT.vPos = mul(WorldViewProj, position); OUT.wPos = mul(World, position); OUT.wNormal = mul(normal, WorldInv); return OUT; } struct CPos_OUT { float4 VPos : POSITION; float4 CPos : TEXCOORD0; }; #ifdef HIGH_QUALITY CPos_OUT MorphedSphereSM_VS(float4 position : POSITION, uniform float4x4 WorldViewProj, uniform float4x4 WorldView, uniform float t) { CPos_OUT OUT; float dist = sin(t + position.x * position.y * 5.0 + position.z) * 0.3; position.xyz += normalize(position.xyz) * dist; OUT.VPos = mul(WorldViewProj, position); OUT.CPos = mul(WorldView, position); return OUT; } float4 MorphedSphereSM_PS(CPos_OUT IN, uniform float farPlane) : COLOR { float dist = length(IN.CPos.xyz) / farPlane; return float4(dist, dist * dist, 1, dist); } #else struct VPos_OUT { float4 VPos : POSITION; float4 VPosition : TEXCOORD0; }; VPos_OUT MorphedSphereSM_VS(float4 position : POSITION, uniform float4x4 WorldViewProj, uniform float t) { VPos_OUT OUT; float dist = sin(t + position.x * position.y * 5.0 + position.z) * 0.3; position.xyz += normalize(position.xyz) * dist; OUT.VPos = OUT.VPosition = mul(WorldViewProj, position); return OUT; } float4 MorphedSphereSM_PS(VPos_OUT IN) : COLOR { float4 pos = IN.VPosition / IN.VPosition.w; return float4(pos.z, 0, 0, 1); } #endif CPos_OUT MorphedSphereCDepth_VS(float4 position : POSITION, uniform float4x4 WorldViewProj, uniform float4x4 WorldView, uniform float t) { CPos_OUT OUT; float dist = sin(t + position.x * position.y * 5.0 + position.z) * 0.3; position.xyz += normalize(position.xyz) * dist; OUT.VPos = mul(WorldViewProj, position); OUT.CPos = mul(WorldView, position); return OUT; } #include "stationIllum.hlsl" uniform sampler2D colorTexture : register(s0); uniform sampler2D obscuranceTexture : register(s1); uniform sampler2D PathMap : register(s2); uniform sampler2D WeightIndexMap : register(s3); uniform sampler2D WeightMap : register(s4); uniform samplerCUBE ShadowMap1Point : register(s5); uniform samplerCUBE ShadowMap2Point : register(s6); uniform sampler2D ShadowMap1 : register(s5); uniform sampler2D ShadowMap2 : register(s6); uniform samplerCUBE CausticCubeMap : register(s7); uniform samplerCUBE CausticCasterDepthMap : register(s8); uniform float4x4 WorldViewProj; uniform float4x4 World; uniform float4x4 WorldI; uniform float3 wCamPos; uniform float4 wLightPos1; uniform float4 wLightPos2; uniform float4 lightRange1; uniform float4 lightRange2; uniform float lightPower1; uniform float lightPower2; uniform float4 lightColor1; uniform float4 lightColor2; uniform float3 wLightDir1; uniform float3 wLightDir2; uniform float4x4 LightViewProj1; uniform float4x4 LightViewProj2; uniform float4x4 LightView1; uniform float4x4 LightView2; uniform float lightFarPlane1; uniform float lightFarPlane2; uniform float specularity; uniform float4 specularColor; uniform float causticReceiver; uniform float3 causticCasterCenter1; uniform float causticAttenuationRange1; struct STATION_BASE_VSOUT { float4 hPos : POSITION; float2 texCoord : TEXCOORD0; float3 wView : TEXCOORD1; float3 wNormal : TEXCOORD2; float3 wPos : TEXCOORD3; float4 lightVPos1 : TEXCOORD4; float4 lightVPos2 : TEXCOORD5; float3 lightCPos1 : TEXCOORD6; float3 lightCPos2 : TEXCOORD7; }; STATION_BASE_VSOUT StationBase_VS(float4 position :POSITION, float3 normal :NORMAL, float2 texCoord : TEXCOORD0 ) { STATION_BASE_VSOUT OUT = (STATION_BASE_VSOUT) 0; OUT.texCoord = texCoord; OUT.hPos = mul(WorldViewProj, position); OUT.wPos = mul(World, position); OUT.wView = wCamPos - OUT.wPos; OUT.wNormal = normalize(mul(float4(normal, 1),WorldI)).xyz; OUT.lightVPos1 = mul(LightViewProj1, float4(OUT.wPos,1)); OUT.lightVPos2 = mul(LightViewProj2, float4(OUT.wPos,1)); #ifdef HIGH_QUALITY OUT.lightCPos1 = mul(LightView1, float4(OUT.wPos,1)).xyz; OUT.lightCPos2 = mul(LightView2, float4(OUT.wPos,1)).xyz; #endif return OUT; } float4 StationBase_PS(STATION_BASE_VSOUT IN):COLOR0 { float4 Color = 0; float3 N = normalize(IN.wNormal); float dist = length(IN.wView); float3 V = IN.wView / dist; // read textures float4 diffuseColor = tex2D(colorTexture, IN.texCoord); float4 obscurancescolor = tex2D(obscuranceTexture, IN.texCoord); //float4 combinedColor = diffuseColor * obscurancescolor; float4 combinedColor = diffuseColor; //---------------------------------------------------------------------------------------------------------------- //light1 //light dir float3 L; float4 col; float3 lightCPos = 0; float4 lightVPos = 0; float shadow; //if( dot(lightRange1, lightRange1) != 0) { L = wLightPos1.xyz - IN.wPos; //illumination col = Illumination(N, L, V, lightColor1 * lightPower1, lightRange1, normalize(wLightDir1), combinedColor, specularity, specularColor); lightVPos = IN.lightVPos1; lightCPos = IN.lightCPos1; shadow = shadowMap(ShadowMap1, lightVPos, lightCPos, lightFarPlane1); Color += col * shadow; } //---------------------------------------------------------------------------------------------------------------- //light2 if( dot(lightRange2, lightRange2) != 0 ) { //light dir L = wLightPos2.xyz - IN.wPos; //illumination col = Illumination(N, L, V, lightColor2 * lightPower2, lightRange2, normalize(wLightDir2), combinedColor, specularity, specularColor); lightVPos = IN.lightVPos2; lightCPos = IN.lightCPos2; shadow = shadowMap(ShadowMap2, lightVPos, lightCPos, lightFarPlane2); Color += col * shadow; } //do Path Map to gather indirect illumination float4 indirect = PathMapIndirect(PathMap, WeightIndexMap, WeightMap, IN.texCoord); indirect *= diffuseColor; Color = Color + indirect * 1.5; //Color = Color + diffuseColor * 0.1; if(causticReceiver) { //Color *= 0.00000000001; Color.rgb += diffuseColor.rgb * Caustics(CausticCubeMap, CausticCasterDepthMap, IN.wPos - causticCasterCenter1, causticAttenuationRange1); } //Color.a = dist; return Color; }