#define CG_BUILD #define CG_PS3_BUILD #define POINTLIGHT_0 #define SPOTLIGHT_0 /* Diffuse Colour: Non-lit, no samplers Conor Lenihan 15 February 2007 */ #define FLAT_SHC //----------------------------------------------------------------------------------------------- /* Base: This is used to make the rest of the files platform indepenant Conor Lenihan 23 October 2006 */ #define BASE_SHH //-----------Change variable formats to make platform independant---------- //Floats #define FLOAT float #define FLOAT2 float2 #define FLOAT3 float3 #define FLOAT4 float4 #define FLOAT3x3 float3x3 #define FLOAT4x3 float4x3 #define FLOAT3x4 float3x4 #define FLOAT4x4 float4x4 //Halves #define HALF half #define HALF2 half2 #define HALF3 half3 #define HALF4 half4 #define HALF3x3 half3x3 #define HALF4x3 half4x3 #define HALF3x4 half3x4 #define HALF4x4 half4x4 //int #define INT int #define INT2 int2 #define INT3 int3 #define INT4 int4 //Others #define BOOL bool #define STRING string #define TEXTURE texture #define SAMPLER2D sampler2D #define SAMPLERCUBE samplerCUBE //#define OUT out //-----------Change Technique formats to make platform independant---------- #define VERTEXCOMPILE arbvp1 #define PIXELCOMPILE arbfp1 #define VERTEXPROGRAM VertexProgram #define PIXELPROGRAM FragmentProgram #define HLSL_OR_PS3_BUILD FLOAT3 GetBlack() { return FLOAT3(0,0,0); } FLOAT3 GetWhite() { return FLOAT3(1,1,1); } //-----------Change Function formats to make platform independant---------- //This is here to prevent a bug where HLSL need to do //its multiplication by (1r4c * 4r4c) where the CG and //GLSL do it (4r4c * 4r1c). This should result in the //same thing appearing on screen FLOAT4 MULTIPLY(FLOAT4x4 myMatrix, FLOAT4 myVector) { return mul(myVector, myMatrix); } FLOAT4x4 MULTIPLY(FLOAT4x4 myMatrix1, FLOAT4x4 myMatrix2) { return mul(myMatrix2, myMatrix1); } //----------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------- /* DiffuseColour: Diffuse colour and alpha Barry Northern 14 March 2007 */ #define DIFFUSECOLOUR_SHH //Default diffuse colour to apply FLOAT3 DiffuseColor : DIFFUSECOLOUR < STRING UIName = "Diffuse Color"; STRING UIWidget = "Color"; > = {1.0f, 1.0f, 1.0f}; FLOAT DiffuseAlpha : DIFFUSEALPHA < STRING UIName = "Diffuse Alpha"; STRING UIWidget = "slider"; FLOAT UIMin = 0.0f; FLOAT UIMax = 1.0f; FLOAT UIStep = 0.01f; > = 1.0f; FLOAT3 GetDiffuse() { return DiffuseColor; } FLOAT GetDiffuseAlpha(FLOAT v) { return (DiffuseAlpha * v); } FLOAT3 CalcDiffuse(FLOAT diffuseCoeff, FLOAT3 lightColor, FLOAT3 InputColour) { FLOAT3 finalDiffuse = diffuseCoeff * lightColor * InputColour; return finalDiffuse; } FLOAT3 CalcInputColour(FLOAT3 col1, FLOAT3 col2) { return (col1 * col2); } //----------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------- /* Diffuse: Calculates diffuse D = Dintensity * Dcolor * Dcoefficent Conor Lenihan 23 October 2006 */ #define DIFFUSE_SHH //Includes //----------------------------------------------------------------------------------------------- /* Base: This is used to make the rest of the files platform indepenant Conor Lenihan 23 October 2006 */ //----------------------------------------------------------------------------------------------- FLOAT Kd : DIFFUSEINFLUENCE < STRING UIName = "Diffuse Influence"; STRING UIWidget = "slider"; FLOAT UIMin = 0.0; FLOAT UIMax = 8; FLOAT UIStep = 0.1; > = 1; //Default texture to apply to object TEXTURE DiffuseTexture < STRING ResourceName = "Drummer_d.dds"; STRING ResourceType = "2D"; >; //Default 2D sampler to apply to object SAMPLER2D DiffuseSampler = sampler_state { Texture = ; MagFilter = Linear; MinFilter = LinearMipMapLinear; AddressU = WRAP; AddressV = WRAP; }; //----------------------------------------------------------------------------------------------- /* DiffuseColour: Diffuse colour and alpha Barry Northern 14 March 2007 */ //----------------------------------------------------------------------------------------------- //Calculates diffuse if you want to use the default Sampler FLOAT3 CalcDiffuse(FLOAT diffuseCoeff, FLOAT3 lightColor, FLOAT2 diffuseTexCoord) { FLOAT3 diffuseCol = diffuseCoeff * lightColor * DiffuseColor; FLOAT3 texDiffuse = tex2D(DiffuseSampler, diffuseTexCoord).xyz; FLOAT3 finalDiffuse = diffuseCol * texDiffuse; return finalDiffuse; } FLOAT3 GetDiffuse(FLOAT2 texCoord) { FLOAT3 texDiffuse = tex2D(DiffuseSampler, texCoord).xyz; FLOAT3 finalDiffuse = DiffuseColor * texDiffuse; return finalDiffuse; } FLOAT GetDiffuseAlpha (FLOAT2 texCoord, FLOAT v) { FLOAT texAlph = tex2D(DiffuseSampler, texCoord).w; FLOAT finalAlpha = (DiffuseAlpha * texAlph) * v; return finalAlpha; } //----------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------- /* STRUCT Struture for a 1UV texcoord Conor Lenihan 14 February 2007 */ #define STRUCT_0UV_N_T_B_SHH //Includes //----------------------------------------------------------------------------------------------- /* Base: This is used to make the rest of the files platform indepenant Conor Lenihan 23 October 2006 */ //----------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------- /* WORLDVIEWPROJ_SHH Conor Lenihan 14 February 2007 */ #define WORLDVIEWPROJ_SHH //Includes //----------------------------------------------------------------------------------------------- /* Base: This is used to make the rest of the files platform indepenant Conor Lenihan 23 October 2006 */ //----------------------------------------------------------------------------------------------- FLOAT4x4 WorldViewProjXf : WorldViewProjection; FLOAT4x4 GetWorldViewProj () { return WorldViewProjXf; } //------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------- /* Vertex shaders for normals Conor Lenihan 14 February 2007 */ #define WORLDVIEWPOSITION //Includes //----------------------------------------------------------------------------------------------- /* Base: This is used to make the rest of the files platform indepenant Conor Lenihan 23 October 2006 */ //----------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------- /* WORLDVIEWPROJ_SHH Conor Lenihan 14 February 2007 */ //------------------------------------------------------------------------------------------------- FLOAT4 CalcWorldViewPosition(FLOAT3 position) { return MULTIPLY(WorldViewProjXf, FLOAT4(position,1.0f)); } //------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------- /* ViewInverse - Semantics connected to game, used to get the matrix of the camera Conor Lenihan 17 January 2007 */ #define VIEWINVERSE_SHH //Includes //----------------------------------------------------------------------------------------------- /* Base: This is used to make the rest of the files platform indepenant Conor Lenihan 23 October 2006 */ //----------------------------------------------------------------------------------------------- FLOAT4x4 ViewInvXf : ViewInverse; FLOAT4x4 GetViewInverse () { return ViewInvXf; } FLOAT3 GetViewInversePosition () { return ViewInvXf[3].xyz; } //------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------- /* WORLDTRANSPOSE Conor Lenihan 14 February 2007 */ #define WORLDTRANSPOSE_SHH //Includes //----------------------------------------------------------------------------------------------- /* Base: This is used to make the rest of the files platform indepenant Conor Lenihan 23 October 2006 */ //----------------------------------------------------------------------------------------------- FLOAT4x4 WorldXf : World; FLOAT4x4 GetWorldTransform () { return WorldXf; } //------------------------------------------------------------------------------------------------- #define FOG_SHH //----------------------------------------------------------------------------------------------- /* Base: This is used to make the rest of the files platform indepenant Conor Lenihan 23 October 2006 */ //----------------------------------------------------------------------------------------------- #define FOG_ENABLED FLOAT Fog_Start : FOGSTART < STRING UIName = "Fog Start"; STRING UIWidget = "Fog Start"; > = 0.0f; FLOAT Fog_End : FOGEND < STRING UIName = "Fog End"; STRING UIWidget = "Fog End"; > = 100000.0f; FLOAT4 Fog : FOGCOLOR < STRING UIName = "Fog"; STRING UIWidget = "Fog"; > = {1.0f, 1.0f, 1.0f, 0.0f}; // Fog that is white but no Density FLOAT CalculateExp2FogRatio (FLOAT distanceToCamera) { FLOAT distanceInFog = clamp((Fog_End - distanceToCamera) / (Fog_End - Fog_Start), 0.0, 1.0); FLOAT density = (1.0f - distanceInFog) * Fog.w; return density; } FLOAT3 BlendFogAndLight (FLOAT3 currentColour, FLOAT fogRatio) { return currentColour; } //////////////////////////////////////////////////// /// structures ///////////////////////////////////// //////////////////////////////////////////////////// struct VertexInput { FLOAT4 Position : POSITION; FLOAT4 Colour : COLOR0; }; struct PixelInput { FLOAT4 HPosition : POSITION; FLOAT4 Colour : COLOR0; }; PixelInput VertexToPixelInput(VertexInput IN) { PixelInput OUT = (PixelInput)0; OUT.HPosition = CalcWorldViewPosition(IN.Position.xyz); OUT.Colour.xyz = IN.Colour.xyz; OUT.Colour.w = IN.Colour.w; return OUT; } //------------------------------------------------------------------------------------------------- ////////////////////////////////////////////////////////// // shader code /////////////////////////////////////////// ////////////////////////////////////////////////////////// //Vertex Shader PixelInput mainVS(VertexInput IN) { PixelInput OUT = VertexToPixelInput(IN); return OUT; } //Pixel Shader FLOAT3 mainCommon(PixelInput IN) { FLOAT3 col = CalcInputColour(GetDiffuse(), IN.Colour.xyz); col.xyz *= Kd; return col.xyz; } #define BASEPIXELSHADERS_SHH //----------------------------------------------------------------------------------------------- /* Base: This is used to make the rest of the files platform indepenant Conor Lenihan 23 October 2006 */ //----------------------------------------------------------------------------------------------- FLOAT4 main(PixelInput IN) : COLOR { FLOAT3 baseColour = mainCommon(IN); FLOAT3 finalColour = BlendFogAndLight(baseColour, IN.Colour.w); return FLOAT4(finalColour, 1.0f); } #define BASEADDITIVEPIXELSHADERS_SHH //----------------------------------------------------------------------------------------------- /* Base: This is used to make the rest of the files platform indepenant Conor Lenihan 23 October 2006 */ //----------------------------------------------------------------------------------------------- FLOAT4 mainAdditive(PixelInput IN) : COLOR { FLOAT3 baseColour = mainCommon(IN); return FLOAT4(baseColour, 1.0f); } #define BASEALPHAPIXELSHADERS_SHH //----------------------------------------------------------------------------------------------- /* Base: This is used to make the rest of the files platform indepenant Conor Lenihan 23 October 2006 */ //----------------------------------------------------------------------------------------------- FLOAT4 mainAlpha(PixelInput IN) : COLOR { FLOAT3 baseColour = mainCommon(IN); FLOAT3 litColour = BlendFogAndLight(baseColour, IN.Colour.w); FLOAT diffuesAlpha = GetDiffuseAlpha(IN.Colour.w); FLOAT4 finalColour = FLOAT4(litColour, diffuesAlpha); return finalColour; } #define ZWRITE_SHH //----------------------------------------------------------------------------------------------- /* Base: This is used to make the rest of the files platform indepenant Conor Lenihan 23 October 2006 */ //----------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------- /* Vertex shaders for normals Conor Lenihan 14 February 2007 */ //------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------- /* WORLDTRANSPOSE Conor Lenihan 14 February 2007 */ //------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------- /* DiffuseColour: Diffuse colour and alpha Barry Northern 14 March 2007 */ //----------------------------------------------------------------------------------------------- struct zWriteVertexInput { FLOAT3 Position : POSITION; }; struct zWritePixelInput { FLOAT4 HPosition : POSITION; }; zWritePixelInput zWriteVertex(zWriteVertexInput IN) { zWritePixelInput OUT = (zWritePixelInput)0; OUT.HPosition = CalcWorldViewPosition(MULTIPLY(GetWorldTransform(), FLOAT4(IN.Position, 1.0)).xyz); return OUT; } FLOAT4 zWritePixel(zWritePixelInput IN) : COLOR { return FLOAT4(0.0f, 0.0f, 0.0f, GetDiffuseAlpha(1.0f)); } ///////////////////////////////////////////////////// // TECHNIQUES ///////////////////////////////////////// /////////////////////////////////////////////////////// technique Flat { pass p0 { //Basic opaque solid technique DepthTestEnable = true; DepthFunc = LessEqual; AlphaTestEnable = false; BlendEnable = false; CullFaceEnable = true; FrontFace = CCW; VERTEXPROGRAM = compile VERTEXCOMPILE mainVS(); PIXELPROGRAM = compile PIXELCOMPILE main(); } } technique Flat_Additive { pass p0 { //Additive Shader DepthTestEnable = true; DepthFunc = LessEqual; DepthMask = false; AlphaTestEnable = true; AlphaFunc = float2(Greater, 0); BlendEnable = true; BlendFunc = int2(SrcColor,One); CullFaceEnable = true; FrontFace = CCW; VERTEXPROGRAM = compile VERTEXCOMPILE mainVS(); PIXELPROGRAM = compile PIXELCOMPILE mainAdditive(); } } technique Flat_Additive_NoCull_NoZWrite { pass p0 { //Additive Shader DepthTestEnable = true; DepthMask = false; DepthFunc = LessEqual; AlphaTestEnable = true; AlphaFunc = float2(Greater, 0); BlendEnable = true; BlendFunc = int2(SrcColor,One); CullFaceEnable = false; FrontFace = CCW; VERTEXPROGRAM = compile VERTEXCOMPILE mainVS(); PIXELPROGRAM = compile PIXELCOMPILE mainAdditive(); } } technique Flat_Alpha { pass p0 { //Alpha technique DepthMask = false; DepthTestEnable = true; DepthFunc = LessEqual; AlphaTestEnable = true; AlphaFunc = float2(Greater, 0); BlendEnable = true; BlendFunc = int2(SrcAlpha,OneMinusSrcAlpha); CullFaceEnable = true; FrontFace = CCW; VERTEXPROGRAM = compile VERTEXCOMPILE mainVS(); PIXELPROGRAM = compile PIXELCOMPILE mainAlpha(); } } technique Flat_ZWrite_Alpha { pass p0 { //Alpha technique DepthMask = false; DepthTestEnable = true; DepthFunc = LessEqual; AlphaTestEnable = true; AlphaFunc = float2(Greater, 0); BlendEnable = true; BlendFunc = int2(SrcAlpha,OneMinusSrcAlpha); CullFaceEnable = true; FrontFace = CCW; VERTEXPROGRAM = compile VERTEXCOMPILE mainVS(); PIXELPROGRAM = compile PIXELCOMPILE mainAlpha(); } pass p1 { //Alpha technique ColorWriteEnable = 0; DepthTestEnable = true; DepthFunc = LessEqual; AlphaTestEnable = true; AlphaFunc = float2(Greater, 0); BlendEnable = true; BlendFunc = int2(SrcAlpha,OneMinusSrcAlpha); CullFaceEnable = true; FrontFace = CCW; VERTEXPROGRAM = compile VERTEXCOMPILE zWriteVertex(); PIXELPROGRAM = compile PIXELCOMPILE zWritePixel(); } } technique Flat_NoCull { pass p0 { //Basic opaque solid technique DepthTestEnable = true; DepthFunc = LessEqual; AlphaTestEnable = false; BlendEnable = false; CullFaceEnable = false; FrontFace = CCW; VERTEXPROGRAM = compile VERTEXCOMPILE mainVS(); PIXELPROGRAM = compile PIXELCOMPILE main(); } } technique Flat_NoCull_Additive { pass p0 { //Additive Shader DepthTestEnable = true; DepthFunc = LessEqual; DepthMask = false; AlphaTestEnable = true; AlphaFunc = float2(Greater, 0); BlendEnable = true; BlendFunc = int2(SrcColor,One); CullFaceEnable = false; FrontFace = CCW; VERTEXPROGRAM = compile VERTEXCOMPILE mainVS(); PIXELPROGRAM = compile PIXELCOMPILE mainAdditive(); } } technique Flat_NoCull_Alpha { pass p0 { //Alpha technique DepthMask = false; DepthTestEnable = true; DepthFunc = LessEqual; AlphaTestEnable = true; AlphaFunc = float2(Greater, 0); BlendEnable = true; BlendFunc = int2(SrcAlpha,OneMinusSrcAlpha); CullFaceEnable = false; FrontFace = CCW; VERTEXPROGRAM = compile VERTEXCOMPILE mainVS(); PIXELPROGRAM = compile PIXELCOMPILE mainAlpha(); } } technique Flat_NoCull_ZWrite_Alpha { pass p0 { //Alpha technique DepthMask = false; DepthTestEnable = true; DepthFunc = LessEqual; AlphaTestEnable = true; AlphaFunc = float2(Greater, 0); BlendEnable = true; BlendFunc = int2(SrcAlpha,OneMinusSrcAlpha); CullFaceEnable = false; FrontFace = CCW; VERTEXPROGRAM = compile VERTEXCOMPILE mainVS(); PIXELPROGRAM = compile PIXELCOMPILE mainAlpha(); } pass p1 { //Alpha technique ColorWriteEnable = 0; DepthTestEnable = true; DepthFunc = LessEqual; AlphaTestEnable = true; AlphaFunc = float2(Greater, 0); BlendEnable = true; BlendFunc = int2(SrcAlpha,OneMinusSrcAlpha); CullFaceEnable = false; FrontFace = CCW; VERTEXPROGRAM = compile VERTEXCOMPILE zWriteVertex(); PIXELPROGRAM = compile PIXELCOMPILE zWritePixel(); } } technique Flat_Hud { pass p0 { //Hud Opaque DepthMask = false; DepthTestEnable = false; BlendEnable = false; BlendFunc = int2(SrcAlpha,DstAlpha); AlphaTestEnable = true; AlphaFunc = float2(Greater, 0); CullFaceEnable = true; FrontFace = CCW; VERTEXPROGRAM = compile VERTEXCOMPILE mainVS(); PIXELPROGRAM = compile PIXELCOMPILE main(); } } technique Flat_Hud_Alpha { pass p0 { //Hud Alpha DepthTestEnable = false; BlendEnable = true; BlendFunc = int2(SrcAlpha,OneMinusSrcAlpha); AlphaTestEnable = true; AlphaFunc = float2(Greater, 0); CullFaceEnable = true; FrontFace = CCW; VERTEXPROGRAM = compile VERTEXCOMPILE mainVS(); PIXELPROGRAM = compile PIXELCOMPILE mainAlpha(); } }