home *** CD-ROM | disk | FTP | other *** search
- #ifdef ATI
- #define FLOAT float
- #define FLOAT2 float2
- #define FLOAT3 float3
- #define FLOAT4 float4
- #else
- #define FLOAT half
- #define FLOAT2 half2
- #define FLOAT3 half3
- #define FLOAT4 half4
- #endif
-
- //============================================================================
- // Declarations macro:
-
- #ifdef D3D
- #define IN_TNORMVEC float3 TNormal : BLENDWEIGHT;
- #endif
-
- #ifdef OPENGL
- #define IN_TNORMVEC float3 TNormal : NORMAL;
- #endif
-
- #define IN_P float4 Position : POSITION;
- #define IN_N float3 Normal : NORMAL;
- #ifdef D3D
- #define IN_TN float3 TNormal : BLENDWEIGHT;
- #endif
- #ifdef OPENGL
- #define IN_TN float3 TNormal : NORMAL;
- #endif
- #define IN_C0 float4 Color : COLOR0;
- #define IN_C1 float4 Color1 : COLOR1;
- #define IN_T0 float4 TexCoord0 : TEXCOORD0;
- #define IN_T1 float4 TexCoord1 : TEXCOORD1;
- #define IN_T2 float4 TexCoord2 : TEXCOORD2;
- #define IN_T3 float4 TexCoord3 : TEXCOORD3;
- #define IN_T4 float4 TexCoord4 : TEXCOORD4;
- #define IN_T5 float4 TexCoord5 : TEXCOORD5;
- #define IN_T6 float4 TexCoord6 : TEXCOORD6;
- #define IN_T7 float4 TexCoord7 : TEXCOORD7;
- #define IN_T8 float4 TexCoord8 : TEXCOORD8;
- #define IN_TANG \
- float3 Tangent : TEXCOORD2; \
- float3 Binormal : TEXCOORD3; \
- IN_TNORMVEC \
-
- #define TANG_MATR \
- float3x3 objToTangentSpace; \
- objToTangentSpace[0] = IN.Tangent; \
- objToTangentSpace[1] = IN.Binormal; \
- objToTangentSpace[2] = IN.TNormal; \
-
- //============================================================================
- // Vertex shader output
-
- #define OUT_P float4 HPosition : POSITION;
- #define OUT_C0 float4 Color : COLOR0;
- #define OUT_C0 float4 Color : COLOR0;
- #define OUT_C1 float4 Color1 : COLOR1;
- #define OUT_T0 float4 Tex0 : TEXCOORD0;
- #define OUT_T0_2 float2 Tex0 : TEXCOORD0;
- #define OUT_T1 float4 Tex1 : TEXCOORD1;
- #define OUT_T1_2 float2 Tex1 : TEXCOORD1;
- #define OUT_T2 float4 Tex2 : TEXCOORD2;
- #define OUT_T2_2 float2 Tex2 : TEXCOORD2;
- #define OUT_T3 float4 Tex3 : TEXCOORD3;
- #define OUT_T3_2 float2 Tex3 : TEXCOORD3;
- #define OUT_T4 float4 Tex4 : TEXCOORD4;
- #define OUT_T4_2 float2 Tex4 : TEXCOORD4;
- #define OUT_T5 float4 Tex5 : TEXCOORD5;
- #define OUT_T5_2 float2 Tex5 : TEXCOORD5;
- #define OUT_T6 float4 Tex6 : TEXCOORD6;
- #define OUT_T6_2 float2 Tex6 : TEXCOORD6;
- #define OUT_T7 float4 Tex7 : TEXCOORD7;
- #define OUT_T7_2 float2 Tex7 : TEXCOORD7;
-
- //============================================================================
-
- #define PROC_ATTENPIX lightVec * (AttenInfo.y * AttenInfo.z) + AttenInfo.z
- #define PROC_ATTENVERT (AttenInfo.x - 1/fiSqDist) * AttenInfo.y
-
- #define SECOND_STATE \
- SecondZEnable = true; \
- SecondZWriteEnable = false; \
- SecondSrcBlend = ONE; \
- SecondDestBlend = ONE; \
- SecondAlphaBlendEnable = true; \
-
- #define SECOND_STATE_AB \
- SecondZEnable = true; \
- SecondZWriteEnable = false; \
- SecondSrcBlend = SrcAlpha; \
- SecondDestBlend = InvSrcAlpha; \
- SecondAlphaBlendEnable = true; \
-
- //============================================================================
- // Pixel shader output
-
- struct pixout
- {
- float4 Color : COLOR0;
- # ifdef _MRT
- float4 Color1 : COLOR1;
- # endif
- # ifdef _DEPTH_OUT
- float Depth : DEPTH;
- # endif
- };
-
- //============================================================================
- // Constants
-
- // Vertex shader parameters
- #define VIEWPROJ_MATRIX uniform float4x4 ModelViewProj : register(c0)
- #define PROJ_MATRIX uniform float4x4 ProjMatrix : register(c0)
- #define LIGHT_POS uniform float4 LightPos : register(c4)
- #define CAMERA_POS uniform float4 CameraPos : register(c5)
- #define ATTEN uniform float4 AttenInfo : register(c6)
- #define BEND uniform float4 Bend : register(c7)
- #define TEX_MATRIX2x4 uniform float2x4 TexMatrix : register(c8)
- #define LIGHT_MATRIX uniform float4x4 LightMatrix : register(c10)
- #define CLIPPLANE uniform float4 ClipPlane : register(c14)
-
- // Pixel shader parameters
- #define AMBIENT uniform float4 Ambient : register(c0)
- #define DIFFUSE uniform float4 Diffuse : register(c1)
- #define SPECULAR uniform float4 Specular : register(c2)
-
- #define HDR_OVERBRIGHT 8
- #define HDR_EXP_OFFSET 64
- #define HDR_EXP_BASE 1.04
-
- //============================================================================
- // Global Constants
-
- #define VS_REG_FOG c29
- #define VS_REG_0_025_05_1 c28
-
- #define PS_REG_FOG_COLOR_1_1 c7
- #define PS_REG_FOG_COLOR_2_0 c31
-
- # ifdef _VS
- const FLOAT4 g_VSFog : register( VS_REG_FOG );
- // .x = 1.0f / (fogEnd - fogStart)
- // .y = fogEnd / (fogEnd - fogStart)
-
- const FLOAT4 g_VSConsts0 : register( VS_REG_0_025_05_1 );
- # endif
-
- # ifdef _PS
- const FLOAT4 g_PSFogColor_11 : register( PS_REG_FOG_COLOR_1_1 );
- # ifndef _PS_1_1
- const FLOAT4 g_PSFogColor_20 : register( PS_REG_FOG_COLOR_2_0 );
- # endif
- # endif
-
- //============================================================================
- // Functions
-
- FLOAT4 _pos_Common(float4x4 Matrix, FLOAT4 InPos)
- {
- # ifdef _VS
- return mul(Matrix, InPos);
- # else
- return float4(0,0,0,1);
- # endif
- }
- FLOAT4 _pos_NULL(float4x4 Matrix, FLOAT4 InPos)
- {
- return FLOAT4 (0,0,0,1);
- }
-
-
- FLOAT CalcFog(float4x4 Matrix, float4 vPos)
- {
- float fFog;
- # if defined(_FOG_LIN) && defined(_VS)
- float fCameraSpacePosZ = dot(Matrix[3], vPos);
- float fFog = saturate(g_VSFog.y - g_VSFog.x * fCameraSpacePosZ);
- # else
- fFog = 1;
- # endif
- return fFog;
- }
-
- FLOAT3 GetFogColor()
- {
- # ifdef _PS
- # ifdef _PS_1_1
- return g_PSFogColor_11.xyz;
- # else
- return g_PSFogColor_20.xyz;
- # endif
- # else
- return float3(1,1,1);
- # endif
- }
-
-
- // Common functions
- FLOAT4 EXPAND( FLOAT4 a )
- {
- FLOAT4 result;
- if (CGC)
- result = 2.h*(a - 0.5h);
- else
- result = a*2.h - 1.h;
- return result;
- }
- FLOAT3 EXPAND( FLOAT3 a )
- {
- FLOAT3 result;
- if (CGC)
- result = 2.h*(a - 0.5h);
- else
- result = a*2.h - 1.h;
- return result;
- }
- FLOAT EXPAND( FLOAT a )
- {
- FLOAT result;
- if (CGC)
- result = 2.h*(a - 0.5h);
- else
- result = a*2.h - 1.h;
- return result;
- }
-
- FLOAT3 HDREncode( FLOAT3 a )
- {
- FLOAT3 result;
- # if defined(_HDR) && defined(_HDR_FAKE)
- result = a * HDR_OVERBRIGHT;
- # else
- result = a * 2;
- # endif
- return result;
- }
- FLOAT3 HDREncodeLM( FLOAT3 a )
- {
- FLOAT3 result;
- # if defined(_HDR) && defined(_HDR_FAKE)
- result = a * HDR_OVERBRIGHT * 2;
- # else
- result = a * 4;
- # endif
- return result;
- }
- FLOAT3 HDREncodeAmb( FLOAT3 a )
- {
- FLOAT3 result;
- # if defined(_HDR) && defined(_HDR_FAKE)
- result = a * HDR_OVERBRIGHT / 2;
- # else
- result = a;
- # endif
- return result;
- }
-
- FLOAT3 HDRFogBlend( FLOAT3 vColor, FLOAT fFog, FLOAT3 vFogColor )
- {
- FLOAT3 result;
- # if defined(_HDR) && defined(_HDR_FAKE)
- result = lerp(HDREncodeAmb(vFogColor), vColor, fFog);
- # else
- result = vColor;
- # endif
- return result;
- }
-
- FLOAT4 HDRFogBlend( FLOAT4 vColor, FLOAT fFog, FLOAT3 vFogColor )
- {
- FLOAT4 result;
- # if defined(_HDR) && defined(_HDR_FAKE)
- result.xyz = lerp(HDREncodeAmb(vFogColor), vColor, fFog);
- result.a = vColor.a;
- # else
- result = vColor;
- # endif
- return result;
- }
-
- # define LOG(a, b) ( log(b) / log(a) )
-
- # define EXP_BASE (1.06)
- # define EXP_OFFSET (128.0)
-
- FLOAT4 EncodeHDR_RGB_RGBE8(in float3 rgb)
- {
- // Compute a common exponent
- FLOAT fLen = dot(rgb.rgb, 1.0);
- FLOAT fExp = LOG(EXP_BASE, fLen);
-
- FLOAT4 ret;
- ret.a = (fExp + EXP_OFFSET) / 256;
- ret.rgb = rgb / fLen;
-
- return ret;
- }
-
- FLOAT3 DecodeHDR_RGBE8_RGB(in float4 rgbe)
- {
- FLOAT fExp = rgbe.a * 256 - EXP_OFFSET;
- FLOAT fScale = pow(EXP_BASE, fExp);
-
- return (rgbe.rgb * fScale);
- }
-
- void HDROutput( out pixout OUT, FLOAT4 Color, FLOAT fDepth, FLOAT3 FogColor, FLOAT fFogFactor )
- {
- FLOAT3 result = HDRFogBlend(Color.xyz, fFogFactor, FogColor);
- # ifndef _MRT
- OUT.Color = float4(result, Color.a);
- # else
- //float4 rgbe = EncodeHDR_RGB_RGBE8(result.xyz);
- //OUT.Color0.xyz = rgbe.xyz;
- //OUT.Color0.a = Color.a;
- //OUT.Color1 = float4(rgbe.a, 0, 0, 1);
- float lum = Luminance(result.xyz) / HDRFAKE_MAXOVERBRIGHT;
- OUT.Color0 = float4(result.xyz, Color.a);
- OUT.Color1 = float4(lum,0,0,1);
- # endif
- # ifdef _DEPTH_OUT
- OUT.Depth = fDepth;
- # endif
- }
-
- void HDROutput( out pixout OUT, FLOAT4 Color, FLOAT fDepth)
- {
- # ifndef _MRT
- OUT.Color = Color;
- # else
- //float4 rgbe = EncodeHDR_RGB_RGBE8(Color.xyz);
- //OUT.Color0.xyz = rgbe.xyz;
- //OUT.Color0.a = Color.a;
- //OUT.Color1 = float4(rgbe.a, 0, 0, 1);
- float lum = Luminance(Color.xyz) / HDRFAKE_MAXOVERBRIGHT;
- OUT.Color0 = Color;
- OUT.Color1 = float4(lum,0,0,1);
- # endif
- # ifdef _DEPTH_OUT
- OUT.Depth = fDepth;
- # endif
- }
-
- FLOAT3 GetNormalMap( sampler2D bumpMap, float2 bumpTC )
- {
- FLOAT3 bumpNormal;
- # ifdef _3DC
- bumpNormal.xy = EXPAND(tex2D(bumpMap, bumpTC.xy).xy);
- bumpNormal.z = sqrt(1 - dot(bumpNormal.xy, bumpNormal.xy));
- # else
- bumpNormal = EXPAND(tex2D(bumpMap, bumpTC.xy).xyz);
- # endif
- return bumpNormal;
- }
-
- FLOAT DepthBias( FLOAT fHeight, FLOAT3 vNormal, FLOAT3 vView, FLOAT2 vZW )
- {
- FLOAT3 vN = vNormal * fHeight;
- FLOAT fOffs = dot(vView, vN) * 0.02;
- FLOAT fOrigZ = vZW.x;
- return (fOrigZ - fOffs) / vZW.y;
- }
-