[2330] | 1 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 2 | //
|
---|
| 3 | // ## ######
|
---|
| 4 | // ###### ###
|
---|
| 5 | // ## ############### Shark 3D Engine (www.shark3d.com)
|
---|
| 6 | // ########## # # #
|
---|
| 7 | // ######## Copyright (c) 1996-2006 Spinor GmbH.
|
---|
| 8 | // ######### # # # All rights reserved.
|
---|
| 9 | // ## ##########
|
---|
| 10 | // ##
|
---|
| 11 | //
|
---|
| 12 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 13 |
|
---|
| 14 | #include \
|
---|
| 15 | <levelutil/shader/prog/d3d9_hlsl/include_shmap_filter_d3d9_hlsl.s3d_shadercode_run>
|
---|
| 16 |
|
---|
| 17 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 18 |
|
---|
| 19 | struct PS_INPUT
|
---|
| 20 | {
|
---|
| 21 | float2 mainTexCoord: TEXCOORD0;
|
---|
| 22 | float2 texCoord0: TEXCOORD1;
|
---|
| 23 | float2 texCoord1: TEXCOORD2;
|
---|
| 24 | float3 diffuse: TEXCOORD3;
|
---|
| 25 | float3 specular: TEXCOORD4;
|
---|
| 26 | #ifdef S3D_LIGHT_PROJ
|
---|
| 27 | float4 lightProjCoord: TEXCOORD5;
|
---|
| 28 | #endif
|
---|
| 29 | #ifdef S3D_LIGHT_SHMAP
|
---|
| 30 | float4 lightShmapCoord: TEXCOORD6;
|
---|
| 31 | #endif
|
---|
| 32 | };
|
---|
| 33 |
|
---|
| 34 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 35 |
|
---|
| 36 | sampler tex0: register(s0);
|
---|
| 37 | sampler tex1: register(s1);
|
---|
| 38 | #ifdef S3D_LIGHT_PROJ
|
---|
| 39 | sampler lightProjSamp: register(s2);
|
---|
| 40 | #endif
|
---|
| 41 | #ifdef S3D_LIGHT_SHMAP
|
---|
| 42 | sampler lightShmapSamp: register(s3);
|
---|
| 43 | #endif
|
---|
| 44 |
|
---|
| 45 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 46 |
|
---|
| 47 | const float4 lightAmbient;
|
---|
| 48 | const float4 lightDiffuse;
|
---|
| 49 | const float4 lightSpecular;
|
---|
| 50 |
|
---|
| 51 | #ifdef S3D_LIGHT_SHMAP
|
---|
| 52 | const float4 lightShmapSize;
|
---|
| 53 | const float4 lightShmapRcpSize;
|
---|
| 54 | #endif
|
---|
| 55 |
|
---|
| 56 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 57 |
|
---|
| 58 | #define S3D_INTENS_DISCARD_TRESHOLD 0.001
|
---|
| 59 | #define S3D_BRIGHT_EPS 0.01
|
---|
| 60 |
|
---|
| 61 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 62 | // Pixelshader
|
---|
| 63 | // Profile: 2x0
|
---|
| 64 |
|
---|
| 65 | float4 main(PS_INPUT input): COLOR0
|
---|
| 66 | {
|
---|
| 67 |
|
---|
| 68 | #ifdef S3D_LIGHT_SHMAP
|
---|
| 69 | float3 clipVal = input.lightShmapCoord.www
|
---|
| 70 | - abs(2 * input.lightShmapCoord.xyz - input.lightShmapCoord.www);
|
---|
| 71 | clip(clipVal.xyz);
|
---|
| 72 | #endif
|
---|
| 73 |
|
---|
| 74 | #ifdef S3D_LIGHT_SHMAP
|
---|
| 75 | // Shadow map:
|
---|
| 76 | float shmapVal = s3d_shmapFilter(
|
---|
| 77 | lightShmapSamp, input.lightShmapCoord,
|
---|
| 78 | lightShmapSize, lightShmapRcpSize);
|
---|
| 79 | clip(shmapVal - S3D_INTENS_DISCARD_TRESHOLD);
|
---|
| 80 | #endif
|
---|
| 81 |
|
---|
| 82 | float sourceTextureSize = 16.0;
|
---|
| 83 | float sqrtNumSamples = 4.0;
|
---|
| 84 | float epsilonX = -0.35;
|
---|
| 85 | float epsilonY = -0.06;
|
---|
| 86 | float4 ocolor = float4(0.0, 1.0, 0.0, 0.0);
|
---|
| 87 | float2 epsilon = float2(epsilonX, epsilonY);
|
---|
| 88 | float4 value = tex2D(tex0, input.texCoord1).xyzw;
|
---|
| 89 | float2 coords = float2(0.0, 1.0) - abs(input.texCoord0 - ( value.xy - epsilon ) );
|
---|
| 90 | if (value.w != 0.0)
|
---|
| 91 | {
|
---|
| 92 | float2 newcoord = (float2(1.0, 1.0) - value.zw) + ((coords * sourceTextureSize) / sqrtNumSamples);
|
---|
| 93 | ocolor = float4(tex2D(tex1, newcoord).xyzw);
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | float4 outCol;
|
---|
| 97 | outCol.rgb = input.diffuse * ocolor.rgb * lightDiffuse.xyz * 2.0 + input.specular * ocolor.rgb * lightSpecular.xyz * 3.0 + ocolor.rgb;
|
---|
| 98 |
|
---|
| 99 | // Preserve original opacity from texture.
|
---|
| 100 | outCol.a = ocolor.a;
|
---|
| 101 |
|
---|
| 102 | #ifdef S3D_LIGHT_PROJ
|
---|
| 103 | float4 texColProjTex = tex2Dproj(lightProjSamp, input.lightProjCoord);
|
---|
| 104 | outCol *= texColProjTex;
|
---|
| 105 | #endif
|
---|
| 106 |
|
---|
| 107 | #ifdef S3D_LIGHT_SHMAP
|
---|
| 108 | shmapVal = shmapVal + 0.65;
|
---|
| 109 | shmapVal = clamp(shmapVal, 0.0, 1.0);
|
---|
| 110 | outCol *= shmapVal;
|
---|
| 111 | #endif
|
---|
| 112 |
|
---|
| 113 | return outCol;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | ///////////////////////////////////////////////////////////////////////////////
|
---|