/////////////////////////////////////////////////////////////////////////////// // // ## ###### // ###### ### // ## ############### Shark 3D Engine (www.shark3d.com) // ########## # # # // ######## Copyright (c) 1996-2006 Spinor GmbH. // ######### # # # All rights reserved. // ## ########## // ## // /////////////////////////////////////////////////////////////////////////////// #include \ /////////////////////////////////////////////////////////////////////////////// struct PS_INPUT { float2 mainTexCoord: TEXCOORD0; float3 diffuse: TEXCOORD1; float3 specular: TEXCOORD2; #ifdef S3D_LIGHT_PROJ float4 lightProjCoord: TEXCOORD3; #endif #ifdef S3D_LIGHT_SHMAP float4 lightShmapCoord: TEXCOORD4; #endif }; /////////////////////////////////////////////////////////////////////////////// sampler tex0: register(s0); sampler tex1: register(s1); #ifdef S3D_LIGHT_PROJ sampler lightProjSamp: register(s2); #endif #ifdef S3D_LIGHT_SHMAP sampler lightShmapSamp: register(s3); #endif /////////////////////////////////////////////////////////////////////////////// const float4 lightAmbient; const float4 lightDiffuse; const float4 lightSpecular; #ifdef S3D_LIGHT_SHMAP const float4 lightShmapSize; const float4 lightShmapRcpSize; #endif /////////////////////////////////////////////////////////////////////////////// #define S3D_INTENS_DISCARD_TRESHOLD 0.001 #define S3D_BRIGHT_EPS 0.01 /////////////////////////////////////////////////////////////////////////////// // Pixelshader // Profile: 2x0 float4 main(PS_INPUT input): COLOR0 { #ifdef S3D_LIGHT_SHMAP float3 clipVal = input.lightShmapCoord.www - abs(2 * input.lightShmapCoord.xyz - input.lightShmapCoord.www); clip(clipVal.xyz); #endif #ifdef S3D_LIGHT_SHMAP // Shadow map: float shmapVal = s3d_shmapFilter( lightShmapSamp, input.lightShmapCoord, lightShmapSize, lightShmapRcpSize); clip(shmapVal - S3D_INTENS_DISCARD_TRESHOLD); #endif float4 ocolor = float4(tex2D(tex0, input.mainTexCoord).xyzw); float4 outCol = float4(0.0,0.0,0.0,0.0); // Preserve original opacity from texture. outCol.a = ocolor.a; outCol.rgb = ocolor.rgb * lightDiffuse.xyz + ocolor.rgb * lightSpecular.xyz; #ifdef S3D_LIGHT_PROJ float4 texColProjTex = tex2Dproj(lightProjSamp, input.lightProjCoord); texColProjTex = clamp(texColProjTex, 0.5, 1.0); outCol *= texColProjTex; #endif #ifdef S3D_LIGHT_SHMAP shmapVal = shmapVal + 0.65; shmapVal = clamp(shmapVal, 0.0, 1.0); outCol *= shmapVal; #endif return outCol; } ///////////////////////////////////////////////////////////////////////////////