home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Geek Games #12
/
GEGA012.iso
/
eroticos
/
dreamstrippergdidemoinstall.exe
/
DreamStripper.msi
/
_8A941BDB14F779B8105FDFAA799C6946
/
_8C0B520907B14ACDA0FC7848EF03590F
< prev
next >
Wrap
Text File
|
2005-05-20
|
31KB
|
1,055 lines
/*********************************************************************
//*
//*Copyright (c) 2001-2005, Ensign Games Ltd. All rights reserved.
//*
//*********************************************************************/
//vertex shader consants
float4x4 WorldViewProj : WORLDVIEWPROJ : register(vs, c0);
float4x4 World : WORLD : register(vs, c4);
float4 MorphWeights : MORPHWEIGHTS : register(vs, c8);
float3 ModelSpaceCamera : MODELSPACECAMERA : register(vs, c9);
float3 ModelSpaceLight1 : MODELSPACELIGHT1 : register(vs, c10);
float3 ModelSpaceLight2 : MODELSPACELIGHT2 : register(vs, c11);
float2 InverseLightRange1 : INVERSELIGHTRANGE1: register(vs, c12);
float2 InverseLightRange2 : INVERSELIGHTRANGE2: register(vs, c13);
float4x4 ShadowMapTexProj1 : SHADOWMAPTEXPROJ1 : register(vs, c14);//used to project the shadow map
float4x4 ShadowMapTexProj2 : SHADOWMAPTEXPROJ2 : register(vs, c18);//used to project the shadow map
float4x4 LightMapTexProj1 : LIGHTMAPTEXPROJ1 : register(vs, c22);//used to project the light map
float4x4 LightMapTexProj2 : LIGHTMAPTEXPROJ2 : register(vs, c26);//used to project the light map
float ShadowMapDepthBias : SHADOWMAPDEPTHBIAS: register(vs, c30);
float3 LightDirection1 : LIGHTDIRECTION1 : register(vs, c31);
float3 LightDirection2 : LIGHTDIRECTION2 : register(vs, c32);
#if defined(GPU_SKINNING)
float4x4 WorldPoseArray[BONE_ARRAY_SIZE] : WORLDPOSEARRAY : register(vs, c40);
#endif
//pixel shader constants
float4 DiffuseMaterial : DIFFUSE : register(ps, c0);
float4 SpecularMaterial : SPECULAR : register(ps, c1);
float4 AmbientLight : AMBIENT : register(ps, c2);
float Fade : FADE : register(ps, c3);
float4 LightColor1 : LIGHTCOLOR1 : register(ps, c4);
float4 LightColor2 : LIGHTCOLOR2 : register(ps, c5);
float SpecularPower : SPECULARPOWER : register(ps, c6);
float SpecularScale : SPECULARSCALE : register(ps, c7);
float2 KajiyaKayPowers : KAJIYAKAYPOWERS : register(ps, c8);
float2 KajiyaKayOffsets : KAJIYAKAYOFFSETS : register(ps, c9);
float4 KajiyaKayColor1 : KAJIYAKAYCOLOR1 : register(ps, c10);
float4 KajiyaKayColor2 : KAJIYAKAYCOLOR2 : register(ps, c11);
float PassMultiplier : PASSMULTIPLIER : register(ps, c12);
//constants for both
float BumpFactor : BUMPFACTOR : register(vs, c33) : register(ps, c13);
sampler DiffuseMap : register(s0);
sampler LightMap : register(s1);
sampler NormalMap : register(s2);
sampler ShadowMap : register(s3);
sampler ShadowMap2 : register(s4);
#define BlurMap ShadowMap
//for shadow mapping
#define ShadowLookupMap NormalMap
const bool g_bUseNormalMap = true;
const bool g_bSpecular = true;
const bool g_bShadowed = true;
const bool g_bKajiyaKay = false;
const float g_fShadowMapResolution = 2.0f;
//standard input for this effect
struct VS_INPUT
{
float3 Position : POSITION;
#if defined(GPU_SKINNING)
float4 BlendWeight : BLENDWEIGHT;
#if defined(INDEXED_GPU_SKINNING) == false
int4 BlendIndices : BLENDINDICES;
#endif
#endif
float3 Normal : NORMAL;
#if defined (NORMAL_MAP)
float3 Tangent : TANGENT;
#endif
#if defined (VERTEX_COLORS)
float4 Color0 : COLOR0;
#endif
float2 TexCoord : TEXCOORD0;
#if defined(SECOND_TEXCOORDS)
float2 TexCoord1 : TEXCOORD1;
#endif
#if defined(INDEXED_GPU_SKINNING)
int4 BlendIndices : BLENDINDICES;
#endif
#if MORPH_TARGET >= 1
float3 Position1 : POSITION1;
float3 Normal1 : NORMAL1;
#endif
#if MORPH_TARGET >= 2
float3 Position2 : POSITION2;
float3 Normal2 : NORMAL2;
#endif
#if MORPH_TARGET >= 3
float3 Position3 : POSITION3;
float3 Normal3 : NORMAL3;
#endif
#if MORPH_TARGET >= 4
float3 Position4 : POSITION4;
float3 Normal4 : NORMAL4;
#endif
};
//declaration to be read by the engine
VS_INPUT VertexDeclaration;
struct VS_OUTPUT_LIGHT
{
float4 Position : POSITION;
float4 TexCoord : TEXCOORD0;//xy is pass through, zw is transformed by uv stuff
float4 VertexToCamera : TEXCOORD1;
float4 LightMapTexCoord : TEXCOORD2;//holds light map texcoords
float4 ShadowMapTexCoord : TEXCOORD3;//holds light map and shadow map texcoords
float3x3 TangentToModelSpace: TEXCOORD4;
float4 VertexToLight1 : TEXCOORD7;//4th component holds depth
float4 VertexToLight2 : COLOR0;//4th component holds depth
float4 Halfway : COLOR1;//4th component holds VdotH
//major packing:
//Halfway2 is in VertexToCamera.w, LightMapTexCoord.z, ShadowMapTexCoord.z
};
////////////////////////////////////////////////////////////////
//VERTEX SHADER helper functions
////////////////////////////////////////////////////////////////
#if defined(GPU_SKINNING)
float4 vsDoSkinning(in VS_INPUT In)
{
float4 Position = mul(float4(In.Position,1), WorldPoseArray[In.BlendIndices.x]) * In.BlendWeight.x;
Position += mul(float4(In.Position,1), WorldPoseArray[In.BlendIndices.y]) * In.BlendWeight.y;
Position += mul(float4(In.Position,1), WorldPoseArray[In.BlendIndices.z]) * In.BlendWeight.z;
Position += mul(float4(In.Position,1), WorldPoseArray[In.BlendIndices.w]) * In.BlendWeight.w;
Position /= Position.w;
return Position;
}
#endif
float4 vsGetLocalPosition(in VS_INPUT In)
{
#if MORPH_TARGET >= 1
In.Position += In.Position1 * MorphWeights.x;
#endif
#if MORPH_TARGET >= 2
In.Position += In.Position2 * MorphWeights.y;
#endif
#if MORPH_TARGET >= 3
In.Position += In.Position3 * MorphWeights.z;
#endif
#if MORPH_TARGET >= 4
In.Position += In.Position4 * MorphWeights.w;
#endif
//transform to clip space and calculate world space position
#if defined(GPU_SKINNING)
return vsDoSkinning(In);
#else
return float4(In.Position,1);
#endif
}
float4 vsDoPositionTransform(in VS_INPUT In, out float4 Position, uniform bool bCalculateLocalPosition = false, uniform bool bCalculateWorldPosition = false)
{
float4 LocalPosition = 0;
#if MORPH_TARGET >= 1
In.Position += In.Position1 * MorphWeights.x;
#endif
#if MORPH_TARGET >= 2
In.Position += In.Position2 * MorphWeights.y;
#endif
#if MORPH_TARGET >= 3
In.Position += In.Position3 * MorphWeights.z;
#endif
#if MORPH_TARGET >= 4
In.Position += In.Position4 * MorphWeights.w;
#endif
//transform to clip space and calculate world space position
#if defined(GPU_SKINNING)
Position = vsDoSkinning(In);
if(bCalculateLocalPosition)
LocalPosition = Position;
if(bCalculateWorldPosition)
LocalPosition = mul(Position, World);
Position = mul(Position, WorldViewProj);
#else
Position = mul(float4(In.Position,1), WorldViewProj);
if(bCalculateLocalPosition)
LocalPosition = float4(In.Position,1);
if(bCalculateWorldPosition)
LocalPosition = mul(float4(In.Position,1), World);
#endif
return LocalPosition;
}
void vsGetTangentSpace(in VS_INPUT In, out float3x3 TSMatrix)
{
#if MORPH_TARGET >= 1
In.Normal += In.Normal1 * MorphWeights.x;
#endif
#if MORPH_TARGET >= 2
In.Normal += In.Normal2 * MorphWeights.y;
#endif
#if MORPH_TARGET >= 3
In.Normal += In.Normal3 * MorphWeights.z;
#endif
#if MORPH_TARGET >= 4
In.Normal += In.Normal4 * MorphWeights.w;
#endif
#if defined(NORMAL_MAP)
#if defined(GPU_SKINNING)
TSMatrix[2] = mul(float4(In.Normal,0), WorldPoseArray[In.BlendIndices.x]).xyz * In.BlendWeight.x;
TSMatrix[2] += mul(float4(In.Normal,0), WorldPoseArray[In.BlendIndices.y]).xyz * In.BlendWeight.y;
TSMatrix[2] += mul(float4(In.Normal,0), WorldPoseArray[In.BlendIndices.z]).xyz * In.BlendWeight.z;
TSMatrix[2] += mul(float4(In.Normal,0), WorldPoseArray[In.BlendIndices.w]).xyz * In.BlendWeight.w;
TSMatrix[2] = normalize(TSMatrix[2]);
#if MORPH_TARGET >= 1
In.Tangent = In.Tangent - dot(In.Tangent, In.Normal)*In.Normal;
#endif
TSMatrix[0] = mul(float4(In.Tangent,0), WorldPoseArray[In.BlendIndices.x]).xyz * In.BlendWeight.x;
TSMatrix[0] += mul(float4(In.Tangent,0), WorldPoseArray[In.BlendIndices.y]).xyz * In.BlendWeight.y;
TSMatrix[0] += mul(float4(In.Tangent,0), WorldPoseArray[In.BlendIndices.z]).xyz * In.BlendWeight.z;
TSMatrix[0] += mul(float4(In.Tangent,0), WorldPoseArray[In.BlendIndices.w]).xyz * In.BlendWeight.w;
TSMatrix[0] = normalize(TSMatrix[0]);
TSMatrix[1] = normalize(cross(TSMatrix[0], TSMatrix[2]));
#else
TSMatrix[2] = In.Normal;
TSMatrix[0] = In.Tangent;
TSMatrix[1] = normalize(cross(TSMatrix[0], TSMatrix[2]));
#endif
TSMatrix[0] *= BumpFactor;
TSMatrix[1] *= BumpFactor;
#else
#if defined(GPU_SKINNING)
TSMatrix[0] = mul(float4(In.Normal,0), WorldPoseArray[In.BlendIndices.x]).xyz * In.BlendWeight.x;
TSMatrix[0] += mul(float4(In.Normal,0), WorldPoseArray[In.BlendIndices.y]).xyz * In.BlendWeight.y;
TSMatrix[0] += mul(float4(In.Normal,0), WorldPoseArray[In.BlendIndices.z]).xyz * In.BlendWeight.z;
TSMatrix[0] += mul(float4(In.Normal,0), WorldPoseArray[In.BlendIndices.w]).xyz * In.BlendWeight.w;
TSMatrix[0] = normalize(TSMatrix[0]);
#else
TSMatrix[0] = In.Normal;
#endif
TSMatrix[1] = 0;
TSMatrix[2] = 0;
#endif
}
float3 vsGetNormal(in VS_INPUT In)
{
float3 Normal;
#if MORPH_TARGET >= 1
In.Normal += In.Normal1 * MorphWeights.x;
#endif
#if MORPH_TARGET >= 2
In.Normal += In.Normal2 * MorphWeights.y;
#endif
#if MORPH_TARGET >= 3
In.Normal += In.Normal3 * MorphWeights.z;
#endif
#if MORPH_TARGET >= 4
In.Normal += In.Normal4 * MorphWeights.w;
#endif
#if defined(GPU_SKINNING)
Normal = mul(float4(In.Normal,0), WorldPoseArray[In.BlendIndices.x]).xyz * In.BlendWeight.x;
Normal += mul(float4(In.Normal,0), WorldPoseArray[In.BlendIndices.y]).xyz * In.BlendWeight.y;
Normal += mul(float4(In.Normal,0), WorldPoseArray[In.BlendIndices.z]).xyz * In.BlendWeight.z;
Normal += mul(float4(In.Normal,0), WorldPoseArray[In.BlendIndices.w]).xyz * In.BlendWeight.w;
Normal = normalize(Normal);
#else
Normal = In.Normal;
#endif
return Normal;
}
////////////////////////////////////////////////////////////////
//PIXEL SHADER helper functions
////////////////////////////////////////////////////////////////
float psGetShadowCoefficient(uniform sampler ShadowMapSampler, in float fDepth, in float4 ShadowTexCoord, uniform float2 texmapscale, uniform bool bLessSamples = false)
{
float fShadowCoefficient = 0.0f;
#if defined(FLOATING_POINT_SHADOW_MAP)
float x,y;
float2 Center = ShadowTexCoord.xy / ShadowTexCoord.w;
for(y = -0.5f; y <= 0.6f; y += 1.0f)
{
for(x = -0.5f; x <= 0.6f; x += 1.0f)
{
float fShadowDepth = tex2D(ShadowMapSampler, Center + float2(x,y)*texmapscale);
if(fDepth <= fShadowDepth)//the pixel is closest to the light
fShadowCoefficient += 0.25f;
}
}
#elif defined(SHADOW_MAP_LOOKUP)
const float2 unpack= float2(0.125f, 1.0f);
float x,y;
float2 Center = ShadowTexCoord.xy / ShadowTexCoord.w;
float2 fShadowDepthPacked = tex2D(ShadowMapSampler, Center + float2(0.0f,0.5f)*texmapscale).rg;
float fShadowDepth = dot(fShadowDepthPacked.rg, unpack);
if(fDepth <= fShadowDepth)//the pixel is closest to the light
fShadowCoefficient += 0.333333333f;
fShadowDepthPacked = tex2D(ShadowMapSampler, Center + float2(-0.4f,-0.5f)*texmapscale).rg;
fShadowDepth = dot(fShadowDepthPacked.rg, unpack);
if(fDepth <= fShadowDepth)//the pixel is closest to the light
fShadowCoefficient += 0.333333333f;
fShadowDepthPacked = tex2D(ShadowMapSampler, Center + float2(0.4f,-0.5f)*texmapscale).rg;
fShadowDepth = dot(fShadowDepthPacked.rg, unpack);
if(fDepth <= fShadowDepth)//the pixel is closest to the light
fShadowCoefficient += 0.333333333f;
#endif
return fShadowCoefficient;
}
////////////////////////////////////////////////////////////////
//Ambient pass shaders
////////////////////////////////////////////////////////////////
struct VS_OUTPUT_AMBIENT
{
float4 Position : POSITION;
float2 TexCoord : TEXCOORD0;
#if defined (VERTEX_COLORS)
float4 Color0 : COLOR0;
#endif
};
VS_OUTPUT_AMBIENT VS(VS_INPUT In)
{
VS_OUTPUT_AMBIENT Out = (VS_OUTPUT_AMBIENT)0;
vsDoPositionTransform(In, Out.Position);
Out.TexCoord.xy = In.TexCoord;
#if defined (VERTEX_COLORS)
Out.Color0 = In.Color0;
#endif
return Out;
}
float4 PS(VS_OUTPUT_AMBIENT In) : COLOR
{
float4 Out = DiffuseMaterial;
#if defined(DIFFUSE_MAP)
Out = tex2D(DiffuseMap, In.TexCoord.xy);
#endif
#if defined (VERTEX_COLORS)
Out.xyz *= AmbientLight.xyz + In.Color0.xyz;
#else
Out.xyz *= AmbientLight;
#endif
return Out;
}
//////////////////////////////////////////////////////////////////
//Depth Encoding shaders
//////////////////////////////////////////////////////////////////
struct VS_OUTPUT_SHADOWMAP
{
float4 Position : POSITION;
float2 Depth : TEXCOORD0;
};
VS_OUTPUT_SHADOWMAP vs_shadowmap(VS_INPUT In)
{
VS_OUTPUT_SHADOWMAP Out = (VS_OUTPUT_SHADOWMAP)0;
float4 LocalPosition = vsDoPositionTransform(In, Out.Position, true);
float3 VertexToLight = ModelSpaceCamera - LocalPosition.xyz;
Out.Depth = (length(VertexToLight) - InverseLightRange1.y) * InverseLightRange1.x;
return Out;
}
float4 ps_shadowmap(VS_OUTPUT_SHADOWMAP In) : COLOR
{
#if defined(SHADOW_MAP_LOOKUP)
float4 Out = 1.0f;
Out.xyz = tex1D(ShadowLookupMap, In.Depth);
return Out;
#else
return In.Depth.x;
#endif
}
//////////////////////////////////////////////////////////////////
//light with spotlight
//////////////////////////////////////////////////////////////////
VS_OUTPUT_LIGHT vs_spotlight(VS_INPUT In,
uniform bool bOutputTextureSpace,
uniform bool bUseTangentSpace,
uniform bool bShadowed,
uniform bool bTwoLights = false)
{
VS_OUTPUT_LIGHT Out = (VS_OUTPUT_LIGHT)0;
float4 LocalPosition;
#if defined(BLUR_SHADOWS) && defined(SECOND_TEXCOORDS)
Out.TexCoord.zw = In.TexCoord1.xy;
#else
Out.TexCoord.zw = In.TexCoord.xy;
#endif
if(bOutputTextureSpace)
{
Out.Position.xy = 1.0f - Out.TexCoord.zw * 2.0f;
Out.Position.x *= -1.0f;
Out.Position.z = 0.0f;
Out.Position.w = 1.0f;
//calculate world position
LocalPosition = vsGetLocalPosition(In);
}
else
{
LocalPosition = vsDoPositionTransform(In, Out.Position, true);
}
Out.TexCoord.xy = In.TexCoord;
//calculate the VertexToLight vector
Out.VertexToLight1.xyz = ModelSpaceLight1 - LocalPosition.xyz;
if(bTwoLights)
Out.VertexToLight2.xyz = ModelSpaceLight2 - LocalPosition.xyz;
float4 WorldPosition = mul(LocalPosition, World);
Out.VertexToLight1.w = (length(Out.VertexToLight1.xyz) - InverseLightRange1.y) * InverseLightRange1.x;
Out.VertexToLight1.w += ShadowMapDepthBias;
Out.VertexToLight1.w = min(0.98f, Out.VertexToLight1.w);
if(bTwoLights)
Out.VertexToLight2.w = (length(Out.VertexToLight2.xyz) - InverseLightRange2.y) * InverseLightRange2.x;
if(bShadowed)
{
//Calculate Shadow map Texture Coordinates
Out.ShadowMapTexCoord = mul(WorldPosition,ShadowMapTexProj1);
if(bOutputTextureSpace && bTwoLights)
{
Out.LightMapTexCoord = mul(WorldPosition,ShadowMapTexProj2);
}
}
if(!bOutputTextureSpace)
{
//calculate light map texture coordinates
Out.LightMapTexCoord = mul(WorldPosition,LightMapTexProj1);
if(bTwoLights)
Out.ShadowMapTexCoord = mul(WorldPosition,LightMapTexProj2);
}
Out.VertexToCamera.xyz = normalize(ModelSpaceCamera - LocalPosition.xyz);
if(bUseTangentSpace)
vsGetTangentSpace(In, Out.TangentToModelSpace);
else
Out.TangentToModelSpace[0] = vsGetNormal(In);
Out.VertexToLight1.xyz = normalize(Out.VertexToLight1.xyz);
if(dot(LightDirection1, -Out.VertexToLight1.xyz) < 0.5f)
Out.VertexToLight1.w = 10.0f;
if(bTwoLights)
Out.VertexToLight2.xyz = normalize(Out.VertexToLight2.xyz);
Out.Halfway.xyz = normalize(Out.VertexToLight1.xyz + Out.VertexToCamera.xyz);
Out.Halfway.w = dot(Out.Halfway.xyz, Out.VertexToCamera.xyz);
Out.Halfway += 1.0f;
Out.Halfway *= 0.5f;
if(bTwoLights)
{
//packing hack
//Halfway2 is in VertexToCamera.w, LightMapTexCoord.z, ShadowMapTexCoord.z
float3 Halfway2 = normalize(Out.VertexToLight2.xyz + Out.VertexToCamera.xyz);
Out.VertexToCamera.w = Halfway2.x;
Out.LightMapTexCoord.z = Halfway2.y;
Out.ShadowMapTexCoord.z = Halfway2.z;
Out.VertexToLight2.xyz += 1.0f;
Out.VertexToLight2.xyz *= 0.5f;
}
#if defined (VERTEX_COLORS)
Out.VertexToLight2 = In.Color0;
#endif
return Out;
}
float4 ps_spotlight(VS_OUTPUT_LIGHT In,
uniform bool bLight,
uniform bool bReadTextureSpaceLight,
uniform bool bShadow,
uniform bool bReadTextureSpaceShadow,
uniform bool bNormalMapped,
uniform bool bUseDiffuseColor,
uniform bool bSpecular,
uniform bool bKajiyaKay = false,
uniform bool bOutputTextureSpace = false,
uniform bool bTwoLights = false
) : COLOR
{
float4 Out = 1;
float4 Diffuse1 = 1.0f;
float4 Diffuse2 = 0.0f;
float4 Specular1 = 0.0f;
float4 Specular2 = 0.0f;
float3 Ambient = AmbientLight.xyz;
float3 VertexColor = PassMultiplier;
if(bUseDiffuseColor)
{
#if defined(DIFFUSE_MAP)
Out = tex2D(DiffuseMap, In.TexCoord);
#else
Out = DiffuseMaterial;
#endif
Ambient *= Out.xyz;
#if defined (VERTEX_COLORS)
VertexColor *= Out.xyz * In.VertexToLight2.xyz;
#endif
}
float NdotL = 0;
float3 Normal = 0;
float3 Light1 = 1.0f;
float3 Light2 = 0.0f;
if(bLight)
{
if(bTwoLights)
{
In.VertexToLight2.xyz *= 2.0f;
In.VertexToLight2.xyz -= 1.0f;
}
#if defined (NORMAL_MAP)
if(bNormalMapped)
{
Normal = 2.0f * tex2D(NormalMap, In.TexCoord) - 1.0f;
Normal = mul(Normal, In.TangentToModelSpace);
}
else
{
Normal = In.TangentToModelSpace[0];
}
#else
Normal = In.TangentToModelSpace[0];
#endif
Normal = normalize(Normal);
//Diffuse Lighting
if(bReadTextureSpaceLight)
{
float4 TextureSpace = tex2D(BlurMap, In.TexCoord.zw);
if(bTwoLights)
{
Diffuse1.xyz = TextureSpace.y;
Diffuse2.xyz = TextureSpace.z;
}
else
{
Diffuse1.xyz = TextureSpace.x;
}
}
else
{
Diffuse1.xyz = saturate(dot(In.VertexToLight1.xyz, Normal));
if(bTwoLights)
{
Diffuse2.xyz = saturate(dot(In.VertexToLight2.xyz, Normal));
}
}
if(!bOutputTextureSpace)
{
Light1 = tex2Dproj(LightMap, In.LightMapTexCoord);
Diffuse1.xyz *= Light1;
if(bTwoLights)
{
Light2 = tex2Dproj(LightMap, In.ShadowMapTexCoord);
Diffuse2.xyz *= Light2;
}
}
//Specular Ligthing
if(bSpecular)
{
float SpecularMultiplier = SpecularScale;
#if defined(NORMAL_MAP)
SpecularMultiplier *= tex2D(NormalMap, In.TexCoord).a;
#else
SpecularMultiplier *= SpecularMaterial;
#endif
if(bTwoLights)//only happens with the blurred ones
{
float2 NdotLs = saturate(dot(Normal, In.VertexToLight1.xyz));
NdotLs.y = dot(Normal, In.VertexToLight2.xyz);
float3 ReflectedLight = 2 * NdotLs.x * Normal - In.VertexToLight1.xyz;
float2 RdotVs = saturate(dot(ReflectedLight,In.VertexToCamera.xyz));
ReflectedLight = 2 * NdotLs.y * Normal - In.VertexToLight2.xyz;
RdotVs.y = saturate(dot(ReflectedLight,In.VertexToCamera.xyz));
RdotVs = SpecularMultiplier* saturate(pow(RdotVs, SpecularPower));
Specular1 = RdotVs.x;
Specular2 = RdotVs.y;
}
else if(bKajiyaKay)
{
float3 Halfway = In.Halfway * 2.0f - 1.0f;
//In.Halfway -= 1.0f;
float3 Binormal1 = In.TangentToModelSpace[1]/BumpFactor + Normal * KajiyaKayOffsets.x*tex2D(NormalMap, In.TexCoord).a;
float3 Binormal2 = In.TangentToModelSpace[1]/BumpFactor + Normal * KajiyaKayOffsets.y*tex2D(NormalMap, In.TexCoord).a;
float2 BdotHs = float2(dot(Binormal1, Halfway),dot(Binormal2, Halfway));
float2 sinBHs = sqrt(1.0f - BdotHs*BdotHs);
float2 dirAttens = smoothstep(-1.0f, 0.0f, BdotHs);
float2 Speculars = dirAttens * pow(sinBHs, KajiyaKayPowers);
Specular1 = Speculars.x * KajiyaKayColor1;
Specular1 += Speculars.y * KajiyaKayColor2;
Specular1 *= Diffuse1;
}
else
{
float3 ReflectedLight = 2 * dot(Normal, In.VertexToLight1.xyz) * Normal - In.VertexToLight1.xyz;
float RdotV = saturate(dot(ReflectedLight,In.VertexToCamera.xyz));
RdotV = SpecularMultiplier* saturate(pow(RdotV, SpecularPower));
Specular1 = RdotV;
}
if(bReadTextureSpaceLight)
{
Specular1.xyz *= Diffuse1.xyz;
if(bTwoLights)
Specular2.xyz *= Diffuse2.xyz;
}
else if(!bKajiyaKay)
{
Specular1.xyz *= Light1;
if(bTwoLights)
Specular2.xyz *= Light2;
}
}
}
if(bShadow)
{
if(bReadTextureSpaceShadow)//shadow is blurred
{
float4 Shadow = tex2D(BlurMap, In.TexCoord.zw);
if(bTwoLights)
{
Diffuse1.xyz *= Shadow.y;
Specular1.xyz *= Shadow.y;
Diffuse2.xyz *= Shadow.z;
Specular2.xyz *= Shadow.z;
}
else
{
Diffuse1.xyz *= Shadow.x;
Specular1.xyz *= Shadow.x;
}
}
else
{
float2 texmapscale = (1.0f/g_fShadowMapResolution, 1.0f/g_fShadowMapResolution);
if(bOutputTextureSpace)
{
#if defined(BLUR_DIFFUSE)
Out.xyz = 0.0f;
if(bTwoLights)
{
Out.y = Diffuse1.x * psGetShadowCoefficient(ShadowMap, In.VertexToLight1.w, In.ShadowMapTexCoord, texmapscale, bSpecular);
Out.z = Diffuse2.x * psGetShadowCoefficient(ShadowMap2, In.VertexToLight2.w, In.LightMapTexCoord, texmapscale, bSpecular);
}
else
{
Out.x = Diffuse1.x * psGetShadowCoefficient(ShadowMap, In.VertexToLight1.w, In.ShadowMapTexCoord, texmapscale, bSpecular);
}
Out.a = 1.0f;
#elif defined(BLUR_SHADOWS)
Out.xyz = 0.0f;
if(bTwoLights)
{
Out.y = psGetShadowCoefficient(ShadowMap, In.VertexToLight1.w, In.ShadowMapTexCoord, texmapscale, bSpecular);
Out.z = psGetShadowCoefficient(ShadowMap2, In.VertexToLight2.w, In.LightMapTexCoord, texmapscale, bSpecular);
}
else
{
Out.x = psGetShadowCoefficient(ShadowMap, In.VertexToLight1.w, In.ShadowMapTexCoord, texmapscale, bSpecular);
}
Out.a = 1.0f;
#endif
}
else
{
float Shadow = psGetShadowCoefficient(ShadowMap, In.VertexToLight1.w, In.ShadowMapTexCoord, texmapscale, bSpecular);
Diffuse1.xyz *= Shadow;
Specular1 *= Shadow;
}
}
}
else
{
if(bOutputTextureSpace)
{
#if defined(BLUR_DIFFUSE)
Out.xyz = 0.0f;
if(bTwoLights)
{
Out.y = Diffuse1.x;
Out.z = Diffuse2.x;
}
else
{
Out.x = Diffuse1.x;
}
Out.a = 1.0f;
#endif
}
Out.a += 0.00001f;
}
if(bLight && bOutputTextureSpace == false)
{
if(bTwoLights)
{
Out *= Diffuse1 * LightColor1 + Diffuse2 * LightColor2;
if(bSpecular)
{
Out += Specular1 + Specular2;
}
}
else
{
Out *= Diffuse1 * LightColor1;
if(bSpecular)
{
Out += Specular1;
}
}
Out.xyz += Ambient;
#if defined (VERTEX_COLORS)
Out.xyz += VertexColor;
#endif
if(!bKajiyaKay)
{
Out.a *= Fade;
}
}
return Out;
}
///////////////////////////////////////////////////////////////////
//Techniques
///////////////////////////////////////////////////////////////////
technique Normal
{
pass Ambient
{
VertexShader = compile vs_1_1 VS();
PixelShader = compile ps_2_0 PS();
MagFilter[0] = Linear;
MinFilter[0] = Linear;
MipFilter[0] = Linear;
FillMode = Solid;
}
pass DepthEncode
{
VertexShader = compile vs_1_1 vs_shadowmap();
PixelShader = compile ps_2_0 ps_shadowmap();
AddressU[2] = clamp;//shadowlookup
AddressV[2] = clamp;
MagFilter[2] = Linear;
MinFilter[2] = Linear;
MipFilter[2] = Linear;
FillMode = Solid;
AlphaTestEnable = false;
AlphaFunc = Always;
AlphaBlendEnable = false;
SrcBlend = One;
DestBlend = Zero;
BlendOp = Add;
}
pass SpotLight
{
VertexShader = compile vs_2_0 vs_spotlight(false, g_bUseNormalMap, true);
PixelShader = compile ps_2_0 ps_spotlight(true, false, g_bShadowed, false, g_bUseNormalMap, true, g_bSpecular, g_bKajiyaKay);
MagFilter[0] = Linear;//diffuse map
MinFilter[0] = Linear;
MipFilter[0] = Linear;
MagFilter[1] = Linear;//light map
MinFilter[1] = Linear;
MipFilter[1] = Linear;
MagFilter[2] = Linear;//normal map
MinFilter[2] = Linear;
MipFilter[2] = Linear;
MagFilter[3] = Linear;//shadow map
MinFilter[3] = Linear;
MipFilter[3] = Linear;
MagFilter[4] = Linear;//shadow map
MinFilter[4] = Linear;
MipFilter[4] = Linear;
AddressU[1] = clamp;
AddressV[1] = clamp;
AddressU[3] = clamp;
AddressV[3] = clamp;
AddressU[4] = clamp;
AddressV[4] = clamp;
FillMode = solid;
}
#if defined (BLUR_DIFFUSE) || defined (BLUR_SHADOWS)
pass SpotLightBlur
{
#if defined (BLUR_DIFFUSE)
//already have texture space map
//only need the texture space if doing specular
VertexShader = compile vs_2_0 vs_spotlight(false, g_bSpecular, true);
#else
VertexShader = compile vs_2_0 vs_spotlight(false, g_bUseNormalMap, true);
#endif
#if defined (BLUR_DIFFUSE)
PixelShader = compile ps_2_0 ps_spotlight(true, true, false, false, g_bUseNormalMap, true, g_bSpecular, false);
#elif defined (BLUR_SHADOWS)
PixelShader = compile ps_2_0 ps_spotlight(true, false, true, true, g_bUseNormalMap, true, g_bSpecular, false);
#else
PixelShader = compile ps_2_0 ps_spotlight(true, false, g_bShadowed, false, g_bUseNormalMap, true, g_bSpecular, g_bKajiyaKay);
#endif
MagFilter[0] = Linear;//diffuse map
MinFilter[0] = Linear;
MipFilter[0] = Linear;
MagFilter[1] = Linear;//light map
MinFilter[1] = Linear;
MipFilter[1] = Linear;
MagFilter[2] = Linear;//normal map
MinFilter[2] = Linear;
MipFilter[2] = Linear;
MagFilter[3] = Linear;//shadow map
MinFilter[3] = Linear;
MipFilter[3] = Linear;
MagFilter[4] = Linear;//shadow map
MinFilter[4] = Linear;
MipFilter[4] = Linear;
AddressU[1] = clamp;
AddressV[1] = clamp;
AddressU[3] = clamp;
AddressV[3] = clamp;
AddressU[4] = clamp;
AddressV[4] = clamp;
FillMode = solid;
}
pass SpotLightBlur2
{
#if defined (BLUR_DIFFUSE)
//already have texture space map
//only need the texture space if doing specular
VertexShader = compile vs_2_0 vs_spotlight(false, g_bSpecular, true, true);
#else
VertexShader = compile vs_2_0 vs_spotlight(false, g_bUseNormalMap, true, true);
#endif
#if defined (BLUR_DIFFUSE)
PixelShader = compile ps_2_0 ps_spotlight(true, true, false, false, g_bUseNormalMap, true, g_bSpecular, g_bKajiyaKay, false, true);
#elif defined (BLUR_SHADOWS)
PixelShader = compile ps_2_0 ps_spotlight(true, false, true, true, g_bUseNormalMap, true, g_bSpecular, g_bKajiyaKay, false, true);
#else
PixelShader = compile ps_2_0 ps_spotlight(true, false, g_bShadowed, false, g_bUseNormalMap, true, g_bSpecular, g_bKajiyaKay);
#endif
MagFilter[0] = Linear;//diffuse map
MinFilter[0] = Linear;
MipFilter[0] = Linear;
MagFilter[1] = Linear;//light map
MinFilter[1] = Linear;
MipFilter[1] = Linear;
MagFilter[2] = Linear;//normal map
MinFilter[2] = Linear;
MipFilter[2] = Linear;
MagFilter[3] = Linear;//shadow map
MinFilter[3] = Linear;
MipFilter[3] = Linear;
MagFilter[4] = Linear;//shadow map
MinFilter[4] = Linear;
MipFilter[4] = Linear;
AddressU[1] = clamp;
AddressV[1] = clamp;
AddressU[3] = clamp;
AddressV[3] = clamp;
AddressU[4] = clamp;
AddressV[4] = clamp;
FillMode = Solid;
}
pass TextureSpaceLighting
{
VertexShader = compile vs_2_0 vs_spotlight(true, false, true);
#if defined (BLUR_DIFFUSE)
PixelShader = compile ps_2_0 ps_spotlight(true, false, g_bShadowed, false, false, false, false, false, true);
#else
PixelShader = compile ps_2_0 ps_spotlight(false, false, true, false, false, false, false,false, true);
#endif
MagFilter[0] = Linear;//diffuse map
MinFilter[0] = Linear;
MipFilter[0] = Linear;
MagFilter[1] = Linear;//light map
MinFilter[1] = Linear;
MipFilter[1] = Linear;
AddressU[1] = Clamp;
AddressV[1] = Clamp;
MagFilter[2] = Linear;//normal map
MinFilter[2] = Linear;
MipFilter[2] = Linear;
MagFilter[3] = Linear;//shadow map
MinFilter[3] = Linear;
MipFilter[3] = Linear;
AddressU[3] = Clamp;
AddressV[3] = Clamp;
MagFilter[4] = Linear;//blurred map
MinFilter[4] = Linear;
MipFilter[4] = Linear;
AddressU[4] = Clamp;
AddressV[4] = Clamp;
ZEnable = false;
ZFunc = Always;
FillMode = Solid;
ZWriteEnable = false;
AlphaTestEnable = false;
AlphaFunc = Always;
AlphaBlendEnable = true;
SrcBlend = One;
DestBlend = One;
BlendOp = Add;
}
pass TextureSpaceLighting2
{
VertexShader = compile vs_2_0 vs_spotlight(true, false, true, true);
#if defined (BLUR_DIFFUSE)
PixelShader = compile ps_2_0 ps_spotlight(true, false, g_bShadowed, false, false, false, false,false, true, true);
#else
PixelShader = compile ps_2_0 ps_spotlight(false, false, true, false, false, false, false,false, true, true);
#endif
MagFilter[0] = Linear;//diffuse map
MinFilter[0] = Linear;
MipFilter[0] = Linear;
MagFilter[1] = Linear;//light map
MinFilter[1] = Linear;
MipFilter[1] = Linear;
AddressU[1] = Clamp;
AddressV[1] = Clamp;
MagFilter[2] = Linear;//normal map
MinFilter[2] = Linear;
MipFilter[2] = Linear;
MagFilter[3] = Linear;//shadow map
MinFilter[3] = Linear;
MipFilter[3] = Linear;
AddressU[3] = Clamp;
AddressV[3] = Clamp;
MagFilter[4] = Linear;//shadow map
MinFilter[4] = Linear;
MipFilter[4] = Linear;
AddressU[4] = Clamp;
AddressV[4] = Clamp;
ZEnable = false;
ZFunc = Always;
FillMode = Solid;
ZWriteEnable = false;
AlphaTestEnable = false;
AlphaFunc = Always;
AlphaBlendEnable = true;
SrcBlend = One;
DestBlend = One;
BlendOp = Add;
}
#endif
}