//----------------------------------------------------------------------------------------- // Completed solution // HLSL Hands-On Workshop, GDC 2005 // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------------------- // Some generic definitions to simplify shader code - Morv //!MP! I use this in shadows.h, so I can use the same header file for C code //MP! with hierarchical z-testing, this is no longer LE of all platforms // Some max-specific definitions //////////////////////////////////////////////////////////////////////////////////////////////////// // constants in HLSL //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// // these are VERTEX SHADER constants //////////////////////////////////////////////////////////////////////////////////////////////////// // 15..26 used by generic constant table, and facial morphing weights float4 PA_StartColour : register(c9); float4 PA_EndColour : register(c10); float4 PA_StartMMEndMMSize : register(c11); float4 PA_Velocity_Alpha_Rotation_Min_AspectRatio : register(c14); float4 PA_Velocity_Alpha_Rotation_Max_Gravity : register(c15); float PA_DrawAsBillboard : register(c16); float4 SpreadNumParticlesAnimationCountLoopSystem : register(c18); float4 PA_MidMinMaxEndMinMaxVelocity : register(c19); float4 PA_EmissionArea : register(c21); float4 PA_ExpiryTime : register(c23); float4 PA_AnimationFrames : register(c24); float4 PA_Wind : register(c26); float4 ParticleFadeValue : register(c28); float4 Radiosity_YCbCr [3] : register(c36); float4 TrapezoidalShadowEpsilon : register(c39); float4 LightIndexScalar : register(c40); float4 LightIndexOffset : register(c41); float4 Foliage_Animation_Scalars : register(c42); float4 Foliage_Animation_Offsets : register(c43); float4 LeafUnitSquare [4] : register(c44); float4 FontXYScalarOffset : register(c48); float4 FontUVScalarOffset : register(c49); float4 VCMainLightDirection : register(c50); float4 CubeShadowMap_LightPosition : register(c51); float4 FarFogPlane : register(c52); float4 CharacterInertiaAndVertexScale : register(c53); float4 DualBumpLODBias : register(c54); float4 VertexBonePaletteTexture : register(c55); float4x4 ShadowMapMatrix : register(c56); float4x4 WorldViewProjection : register(c60); float4x4 WorldMatrix : register(c64); float4x4 ViewMatrix : register(c68); float4x4 ViewProj : register(c72); float4x4 TextureTransform : register(c76); float4 ScreenRes [2] : register(c80); float4 ParticleRoot : register(c88); float4 TimeIntoEffect : register(c89); float4 RadiosityInfluence : register(c90); float4 TexCoordScaleLODBlur : register(c91); // used by the cube variance shadow map blending float4x4 ProjMatrix : register(c92); float4 Bones [96] : register(c150); float4 RicsFontShaderConstants : register(c100); float4 BillboardTextureCoords [60] : register(c100); float4 CameraRightAxis : register(c160); float4 CameraUpAxis : register(c161); float4 InstancingData : register(c162); float4 TreePos : register(c163); float4 TreeRot : register(c164); float4 TreeScale : register(c165); float4x4 WindMatrices [7] : register(c180); float4 WindSettings : register(c208); float4 SpeedTreeLightSettings : register(c209); float4 CameraAngles : register(c210); float4 SelfShadowMotion : register(c211); float4 LeafAngles [20] : register(c216); float4x4 BillboardNormals : register(c236); float4x4 BillboardBinormals : register(c240); float4x4 BillboardTangents : register(c244); float4 BillboardSpecialAzimuth : register(c248); float4 FoliageSettings : register(c249); float4 PS3StaticLightData [33 * 2] : register(c352); //////////////////////////////////////////////////////////////////////////////////////////////////// // these are PIXEL SHADER constants //////////////////////////////////////////////////////////////////////////////////////////////////// float4 FogColour : register(c0); float4 SpecularPower : register(c2); float4 MainLightInvColor : register(c7); // inverse direction light color - to show off bump maps float4 DualBumpNormalErrorThreshold : register(c8); float4 ShadowBias : register(c9); float4 MainLightDirection : register(c10); float4 MainLightColor : register(c11); float4 VarianceShadowMap_Setup : register(c12); float4 VarianceShadowMap_EdgeDelta : register(c13); float4 ShadowMapDimensions : register(c14); // 15..26 used by generic constant table float4 RadiosityCSC : register(c29); float4 RayleighMieConstants : register(c30); float BodySolidity : register(c31); float4 PostProcessing_BloomScalarOffset : register(c32); float4 PostProcessing_OverlaySettings : register(c33); float4 PostProcessing_Distortion : register(c34); // xy=distortion range, z=LOD range, w=luminance range float4 PostProcessing_TintScalar : register(c35); float4 PostProcessing_TintOffset : register(c36); float4 FilterOptions : register(c37); float4 DirectionalLightingIntensities : register(c38); float4 FogEquation [2] : register(c39); float4 HDR_Constants : register(c41); float4 AmbientDiffuse : register(c42); float4 DirectLightingInfluence : register(c43); float4 DynamicLightData [12] : register(c44); // 12 used (ie 4 lights, 1 extra just in case...), followed by static data float4 DynamicLight0_Data : register(c44); float4 DynamicLight1_Data : register(c47); float4 DynamicLight2_Data : register(c50); float4 DynamicLight3_Data : register(c53); float4 StaticLightData [96] : register(c56); float4 AmbientScalar : register(c142); // used by dynamic objects to offset the ambient values float4 AmbientOffset : register(c143); // ... half4 PostProcessing_TintEq [4] : register(c150); float4 DOFFocalPointSpread : register(c154); float4 DOFReverseZPerspective : register(c155); float4 DOFKernelConstants : register(c156); float4 MotionBlurMovement : register(c157); float4 MotionBlurConstants : register(c158); float4x4 MotionBlurCurrInvViewProjection : register(c160); float4x4 MotionBlurPrevViewProjection : register(c164); float4 RayleighMieScatteringWavelengthsQuad : register(c168); // wavelengths used by rayleigh/mie to the 4th, ie "lambda^4" float4 CloudTextureDef0 : register(c169); // scrolling float4 CloudTextureDef1 : register(c170); // scrolling float4 CloudTextureDef2 : register(c171); // scrolling float4 CloudTextureDef3 : register(c172); // rotating float4 CloudBlendParams : register(c173); // blend params float4 RayleighMieSunPosition : register(c174); // blend params float4 RayleighMieRGBTranslation [3] : register(c175); // translates RGB -> whichever color float4 ShadowParameters : register(c179); // scalar, offset //////////////////////////////////////////////////////////////////////////////////////////////////// bool CubicShadowReceive : register(b0); bool RadiosityGatheringInProgress : register(b1); //////////////////////////////////////////////////////////////////////////////////////////////////// // these are VERTEX AND PIXEL SHADER constants //////////////////////////////////////////////////////////////////////////////////////////////////// float4 ConstantColour : register(c1); // !MP! do not rely on this; it's part of the old lighting system and will disappear after this milestone float4 TimeAndRainLevel : register(c3); // in .x float4 RainLevel : register(c3); // in .y float4 CameraPosition : register(c5); // 15..26 used by generic constant table //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// // Generic constants (loaded into a table at c15, but the shaders that use them don't know that) //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // radiosity backface hack //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// float lfInputFaceDirection = 0.f; // less than ideal - this will internally be 'overwritten', if a variable of this name exists locally float4 BlankReverseSideDuringRadiosityGathering( float lfFaceDirection, float4 lOutputColor) { //not necessary any longer i think return lOutputColor; return lOutputColor; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // snow //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// float3 SnowValue (float3 input_colour, float world_space_normal_y) { return lerp (input_colour, float3 (1, 1, 1), saturate (world_space_normal_y - 0.5f) * (TimeAndRainLevel.z)); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // transformed vertex z position to pixel depth calculation : used for soft sprites //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// float VertexToPixelDepth(float PositionZ) // PositionZ = mul(float4(world_pos, 1), ViewProj).z; { return DOFReverseZPerspective.x / (PositionZ * DOFReverseZPerspective.y - DOFReverseZPerspective.z); // m32/(o*m23-m22) } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // color range tweak //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// static const float g_overbright = 32; // Ivan: experimentally shown that hdr range of 99% of the scene is 0..4 //static const float MAX_HDR_RANGE = 3.5f; // test stuff //half4 RGBHighlightRange( half4 c, float mv ) //{ // half scale = max( c.x, max( c.y, c.z ) ); // // if( scale > mv ) // { // c = half4( 1, 0, 0, 1 ); // } // // return c; //} // classic rgbs //half4 RGB_to_RGBS( half4 c ) //{ // half scale = max( c.x, max( c.y, c.z ) ); // // half3 rgb = c.xyz / scale; // half a = saturate( scale / MAX_HDR_RANGE ); // // return half4( rgb, a ); //} // classic rgbs //half4 RGBS_to_RGB( half4 c ) //{ // return half4( c.xyz * c.a * MAX_HDR_RANGE, c.a ); //} // classic exponential //half4 RGB_to_ScaledRGB( half4 c ) //{ // return half4( c.xyz / MAX_HDR_RANGE, c.a ); //} // classic exponential //half4 ScaledRGB_to_RGB( half4 c ) //{ // return half4( c.xyz * MAX_HDR_RANGE, c.a ); //} // classic exponential // TODO: use halfs throughout for better compilation //half4 RGB_to_PPP( half4 c ) //{ // return half4( sqrt( ( half3( c.xyz ) / half( MAX_HDR_RANGE ) ) ), c.a ); //} // classic exponential //half4 PPP_to_RGB( half4 c ) //{ // return half4( c.xyz * c.xyz * MAX_HDR_RANGE, c.a ); //} //float4 RGBA_to_SonyRGBS( float4 ) static const float fLinearRange = 2.f; // scales the output color float4 HDRColorCorrected(float4 lColor) { float3 corrected = lColor.xyz / fLinearRange; return float4( corrected, lColor.a ); } // scales the output color float4 HDRColorCorrected0(float4 lColor) { return float4( lColor.xyz / fLinearRange, lColor.a ); } // scales the output color half4 HDRColorCorrected(half4 lColor) { half3 corrected = lColor.xyz / (half)fLinearRange; return half4( corrected, lColor.a ); } float4 HDRColorReverted(float4 lColor) { float multiply = lColor.a == 0 ? g_overbright : 1; return float4( lColor.xyz * fLinearRange * multiply, 1.f ); } half4 HDRColorReverted(half4 lColor) { half multiply = lColor.a == 0 ? (half)g_overbright : 1; return half4( lColor.xyz * (half)fLinearRange * multiply, 1.f ); } float4 HDRForceReversion(float4 lColor) { return lColor; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // normal = tangent X normal //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// float3 CreateBinormal( float3 lNormal, float3 lTangent) { //!MP! i actually thought it was the other way around, but this produces consistent results return cross(lTangent,lNormal); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // color space conversion //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // performs color space conversion float3 ConvertYCbCr2RGB( float3 lYCbCr) { float3x4 lNewMatrix; // Keef - Casting to float3x4 doesn't work with Cg for some reason lNewMatrix._m00_m01_m02_m03 = Radiosity_YCbCr[0]; lNewMatrix._m10_m11_m12_m13 = Radiosity_YCbCr[1]; lNewMatrix._m20_m21_m22_m23 = Radiosity_YCbCr[2]; //!MP! the PS3 should use this version as well return max(0,mul(lNewMatrix,float4(lYCbCr,1))); } // we use YCbCr rather than YUV due to YUV's limited range float3 DecompressYCbCr844( int2 lYCbCr) { // get Y:8,Cb:4,Cr:4 from the zw components (Cb,Cr are packed into the second byte) float lfY = lYCbCr.x; float lfCr = lYCbCr.y*0.0625f; //1/16 float lfCb = floor(lfCr); lfCr = lfCr-lfCb; float4 lfYCbCr1 = float4(lfY,lfCb,lfCr,1); // Keef - Casting to float3x4 doesn't work with Cg for some reason float3x4 lNewMatrix; lNewMatrix._m00_m01_m02_m03 = Radiosity_YCbCr[0]; lNewMatrix._m10_m11_m12_m13 = Radiosity_YCbCr[1]; lNewMatrix._m20_m21_m22_m23 = Radiosity_YCbCr[2]; float3 lRGB = saturate(mul(lNewMatrix,lfYCbCr1)); return lRGB; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // character UV scalar - centralized, as editing only the standard shaders mess up the shadows //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //The 360 FXLite differs from the PC FX interfaces in one important area. //The textures can only be shared on the PC and the 360 can only share and read samplers. //So when you need to define and use a texture and sampler use the macros below. // Max MapChannels make me cry //----------------------------------------------------------------------------------------- // Variables //----------------------------------------------------------------------------------------- float4x4 World : World; // World or Model matrix float4x4 WorldIMatrix : WorldI; // World Inverse or Model Inverse matrix float4x4 mvpMatrix : WorldViewProj; // Model*View*Projection float4x4 worldViewMatrix : WorldView; float4x4 View: View; float4x4 Projection: Projection; float4x4 viewInverseMatrix : ViewI; float4 ambientColor : Ambient < string UIName = "Ambient"; > = { 0.1, 0.1, 0.1, 1.0}; float4 diffuseColor : Diffuse < string UIName = "Diffuse"; > = { 0.9, 0.9, 0.9, 1.0}; float4 DirectionalLight : Direction < string UIName = "Light Direction"; string Object = "TargetLight"; int RefID = 0; > = {-0.577, -0.577, 0.577,1.0}; float SpecularStyleLerp = 0.15f; // layer 1 int tiling1 < string UIType = "IntegerSpinner"; string UIName = "Tiling 1"; int UIMin = 1; int UIMax = 128; > = {32}; float Specularity1 < string UIType = "FloatSpinner"; string UIName = "Specularity"; float UIMin = 0.0f; float UIMax = 1.0f; float UIStep = 0.1f; > = {0.5}; int SpecularPower1 < string UIType = "IntegerSpinner"; string UIName = "Specular Power"; int UIMin = 1; int UIMax = 100; > = {100}; texture diffuseTexture1 : DiffuseMap < string name = "c:\\Morv\\Land\\L01.tga"; string UIName = "Diffuse 1"; int Texcoord = 0; // int MapChannel = 1; >; texture TangentMap1 : NormalMap < string name = "c:\\Morv\\Land\\_test_normal01.tga"; string UIName = "Normap 1"; int Texcoord = 0; // int MapChannel = 1; >; float bumpHeight1 < string UIType = "FloatSpinner"; string UIName = "Bump Height 1"; float UIMin = 0.0f; float UIMax = 2.0f; > = { 1.5}; texture alphaMap1 : AlphaMap < string name = "c:\\Morv\\Land\\!BLANK.tga"; string UIName = "Alpha 1"; int Texcoord = 1; // int MapChannel = 3; >; // layer 2 int tiling2 < string UIType = "IntegerSpinner"; string UIName = "Tiling 2"; int UIMin = 1; int UIMax = 128; > = { 32}; float Specularity2 < string UIType = "FloatSpinner"; string UIName = "Specularity"; float UIMin = 0.0f; float UIMax = 1.0f; float UIStep = 0.1f; > = {0.5}; int SpecularPower2 < string UIType = "IntegerSpinner"; string UIName = "Specular Power"; int UIMin = 1; int UIMax = 100; > = {100}; texture diffuseTexture2 : DiffuseMap < string name = "c:\\Morv\\Land\\L02.tga"; string UIName = "Diffuse 2"; int Texcoord = 0; // int MapChannel = 1; >; texture TangentMap2 : NormalMap < string name = "c:\\Morv\\Land\\_test_normal02.tga"; string UIName = "Normap 2"; int Texcoord = 0; // int MapChannel = 1; >; float bumpHeight2 < string UIType = "FloatSpinner"; string UIName = "Bump Height 2"; float UIMin = 0.0f; float UIMax = 2.0f; > = { 1.5}; texture alphaMap2 : AlphaMap < string name = "c:\\Morv\\Land\\L02_mask.tga"; string UIName = "Alpha 2"; int Texcoord = 1; // int MapChannel = 3; >; // layer 3 int tiling3 < string UIType = "IntegerSpinner"; string UIName = "Tiling 3"; int UIMin = 1; int UIMax = 128; > = { 32}; float Specularity3 < string UIType = "FloatSpinner"; string UIName = "Specularity"; float UIMin = 0.0f; float UIMax = 1.0f; float UIStep = 0.1f; > = {0.5}; int SpecularPower3 < string UIType = "IntegerSpinner"; string UIName = "Specular Power"; int UIMin = 1; int UIMax = 100; > = {100}; texture diffuseTexture3 : DiffuseMap < string name = "c:\\Morv\\Land\\L03.tga"; string UIName = "Diffuse 3"; int Texcoord = 0; // int MapChannel = 1; >; texture TangentMap3 : NormalMap < string name = "c:\\Morv\\Land\\_test_normal03.tga"; string UIName = "Normap 3"; int Texcoord = 0; // int MapChannel = 1; >; float bumpHeight3 < string UIType = "FloatSpinner"; string UIName = "Bump Height 3"; float UIMin = 0.0f; float UIMax = 2.0f; > = { 1.5}; texture alphaMap3 : AlphaMap < string name = "c:\\Morv\\Land\\L03_mask.tga"; string UIName = "Alpha 3"; int Texcoord = 1; // int MapChannel = 3; >; // layer 4 int tiling4 < string UIType = "IntegerSpinner"; string UIName = "Tiling 4"; int UIMin = 1; int UIMax = 128; > = { 32}; float Specularity4 < string UIType = "FloatSpinner"; string UIName = "Specularity"; float UIMin = 0.0f; float UIMax = 1.0f; float UIStep = 0.1f; > = {0.5}; int SpecularPower4 < string UIType = "IntegerSpinner"; string UIName = "Specular Power"; int UIMin = 1; int UIMax = 100; > = {100}; texture diffuseTexture4 : DiffuseMap < string name = "c:\\Morv\\Land\\L04.tga"; string UIName = "Diffuse 4"; int Texcoord = 0; // int MapChannel = 1; >; texture TangentMap4 : NormalMap < string name = "c:\\Morv\\Land\\_test_normal04.tga"; string UIName = "Normap 4"; int Texcoord = 0; // int MapChannel = 1; >; float bumpHeight4 < string UIType = "FloatSpinner"; string UIName = "Bump Height 4"; float UIMin = 0.0f; float UIMax = 2.0f; > = { 1.5}; texture alphaMap4 : AlphaMap < string name = "c:\\Morv\\Land\\L04_mask.tga"; string UIName = "Alpha 4"; int Texcoord = 1; // int MapChannel = 3; >; // end of layers // samplers sampler2D diffuseSampler1 = sampler_state { Texture = ; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; }; sampler2D tangentSampler1 = sampler_state { Texture = ; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; }; sampler2D alphaSampler1 = sampler_state { Texture = ; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; }; sampler2D diffuseSampler2 = sampler_state { Texture = ; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; }; sampler2D tangentSampler2 = sampler_state { Texture = ; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; }; sampler2D alphaSampler2 = sampler_state { Texture = ; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; }; sampler2D diffuseSampler3 = sampler_state { Texture = ; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; }; sampler2D tangentSampler3 = sampler_state { Texture = ; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; }; sampler2D alphaSampler3 = sampler_state { Texture = ; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; }; sampler2D diffuseSampler4 = sampler_state { Texture = ; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; }; sampler2D tangentSampler4 = sampler_state { Texture = ; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; }; sampler2D alphaSampler4 = sampler_state { Texture = ; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; }; //----------------------------------------------------------------------------------------- // VertexShader I/O //----------------------------------------------------------------------------------------- struct VSInput { float4 Position : POSITION; float3 Normal : NORMAL; float3 Tangent : TANGENT; float3 Binormal : BINORMAL; float2 TexCoords : TEXCOORD0; }; struct VSOutput { float4 Position : POSITION; float2 TexCoords : TEXCOORD0; float2 TexCoordsHi : TEXCOORD1; float3 Normal : TEXCOORD2; float3 Tangent : TEXCOORD3; float3 Binormal : TEXCOORD4; float3 PositionForPixelShader : TEXCOORD5; }; struct PSInput { float2 TexCoords : TEXCOORD0; float2 TexCoordsHi : TEXCOORD1; float3 Normal : TEXCOORD2; float3 Tangent : TEXCOORD3; float3 Binormal : TEXCOORD4; float3 Position : TEXCOORD5; }; //----------------------------------------------------------------------------------------- // Vertex Shader //----------------------------------------------------------------------------------------- VSOutput VS( VSInput input, uniform float TexRepeatCount) { VSOutput output; // Transform to clip space by multiplying by the basic transform matrices. // An additional rotation is performed to illustrate vertex animation. float4 worldPosition = mul(input.Position, World); output.PositionForPixelShader = worldPosition; output.Position = mul(worldPosition, mul(View, Projection)); // Move the incoming normal and tangent into world space and compute the binormal. // These three axes will be used by the pixel shader to move the normal map from // tangent space to world space. output.Normal = normalize (mul(input.Normal, World)); output.Tangent = normalize (mul(input.Tangent, World)); output.Binormal = normalize (input.Binormal); //cross(output.Normal, output.Tangent); // Pass texture coordinates on to the pixel shader output.TexCoords = input.TexCoords; output.TexCoordsHi = input.TexCoords * TexRepeatCount; return output; } //----------------------------------------------------------------------------------------- // Pixel Shader //----------------------------------------------------------------------------------------- float4 PS (PSInput input, uniform sampler2D DiffuseMap, uniform sampler2D NormalMap, uniform float4 bumpHeight, uniform sampler2D AlphaMap, uniform float4 tiling, uniform float Specularity, uniform float SpecularPower ) : COLOR { float4x4 ViewInv = viewInverseMatrix; float3 CameraPosition = mul(float4(0,0,0,1), ViewInv); float3 LightDir = normalize (float4 (DirectionalLight.xyz, 0)); float3 EyeVector = normalize( input.Position - CameraPosition ); // Look up the normal from the NormalMap texture, and unbias the result float3 Normal; Normal = tex2D(NormalMap, input.TexCoordsHi); Normal = (Normal * 2) - 1; Normal.rg /= 2.0f; // R and G are quite hard to get subtle! Normal.rg *= bumpHeight; // Move the normal from tangent space to world space float3x3 tangentFrame = {-input.Binormal, -input.Tangent, -input.Normal}; Normal = normalize (mul(Normal, tangentFrame)); // Start with N dot L lighting float light = saturate( dot( -Normal, LightDir) ); float3 color = diffuseColor * (light + ambientColor); // Modulate against the diffuse texture color float4 diffuse = tex2D(DiffuseMap, input.TexCoordsHi); color *= diffuse.rgb; float3 EyeReflect = -reflect(EyeVector, Normal); // float3 environment = texCUBE(EnvironmentMapSampler, EyeReflect); float EyeReflectRatio = 1;//diffuse.a; // color += EyeReflectRatio * environment; // Add a specular highlight float3 vHalf = normalize( EyeVector + -LightDir ); float PhongSpecular = saturate(dot(vHalf, Normal)); float BlinnSpecular = saturate(dot(EyeReflect ,-LightDir )); float specular= lerp(PhongSpecular, BlinnSpecular, SpecularStyleLerp ); color += EyeReflectRatio * diffuseColor * (pow(specular, SpecularPower) * Specularity); float alpha = tex2D (AlphaMap, input.TexCoords).r; // Set alpha to 1.0 and return return float4(color, alpha); } technique TangentSpace_2_0 { pass p0 { ZEnable = true; ZWriteEnable = true; CullMode = None; AlphaBlendEnable = true; SrcBlend = srcalpha; DestBlend = invsrcalpha; VertexShader = compile vs_2_0 VS(tiling1); PixelShader = compile ps_2_0 PS(diffuseSampler1,tangentSampler1,bumpHeight1,alphaSampler1,tiling1, Specularity1, SpecularPower1); } pass p1 { ZEnable = true; ZWriteEnable = true; CullMode = None; VertexShader = compile vs_2_0 VS(tiling2); PixelShader = compile ps_2_0 PS(diffuseSampler2,tangentSampler2,bumpHeight2,alphaSampler2,tiling2, Specularity2, SpecularPower2); } pass p2 { ZEnable = true; ZWriteEnable = true; CullMode = None; VertexShader = compile vs_2_0 VS(tiling3); PixelShader = compile ps_2_0 PS(diffuseSampler3,tangentSampler3,bumpHeight3,alphaSampler3,tiling3, Specularity3, SpecularPower3); } pass p3 { ZEnable = true; ZWriteEnable = true; CullMode = None; VertexShader = compile vs_2_0 VS(tiling4); PixelShader = compile ps_2_0 PS(diffuseSampler4,tangentSampler4,bumpHeight4,alphaSampler4,tiling4, Specularity4, SpecularPower4); } }