HOOPS/3dGS I.M. Interface

     << Back      Full Index      Forward >>


dx9hlsl.h

00001 /*
00002  * Copyright (c) 1998 by Tech Soft 3D, LLC.
00003  * The information contained herein is confidential and proprietary to
00004  * Tech Soft 3D, LLC., and considered a trade secret as defined under
00005  * civil and criminal statutes.  Tech Soft 3D shall pursue its civil
00006  * and criminal remedies in the event of unauthorized use or misappropriation
00007  * of its trade secrets.  Use of this information by anyone other than
00008  * authorized employees of Tech Soft 3D, LLC. is granted only under a
00009  * written non-disclosure agreement, expressly prescribing the scope and
00010  * manner of such use.
00011  *
00012  * $Id: dx9hlsl_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $
00013  */
00014 
00015 char CONST * dx9_common =
00016     "// Copyright (c) 2007 by Tech Soft 3D, LLC.\n"
00017     "// all rights reserved\n"
00018     "// $Id: dx9hlsl_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $\n"
00019     " \n"
00020     "/* Shared IO Types ***********************************************************/\n"
00021     "\n"
00022     "/* \n"
00023     " * ITERATOR\n"
00024     " * Output to triangle setup \n"
00025     " */\n"
00026     "#ifndef CREATE_SHADOW_MAP\n"
00027     "struct Iterator\n"
00028     "{\n"
00029     "   /* Transformed vertex position */\n"
00030     "   float4 position : POSITION;\n"
00031     "   \n"
00032     "   /* Color for interpolation */\n"
00033     "   float4 diffuse_color : COLOR0;\n"
00034     "\n"
00035     "   /* Specular color for interpolation */\n"
00036     "   float4 specular_color : COLOR1;\n"
00037     "   \n"
00038     "   #ifdef PER_PIXEL_LIGHTING\n"
00039     "       #if (POINT_LIGHT_COUNT > 0) || (SPOT_LIGHT_COUNT > 0)\n"
00040     "   float4 eye_position : EYE_POSITION_COORD;\n"
00041     "       #endif // POINT_LIGHT_COUNT > 0 || SPOT_LIGHT_COUNT > 0\n"
00042     "   #endif // PER_PIXEL_LIGHTING\n"
00043     "           \n"
00044     "   #ifdef HAS_ATMOSPHERIC_ATTENUATION\n"
00045     "       float fog : FOG;\n"
00046     "   #endif\n"
00047     "   #if (TEXTURE_COUNT > 0) || defined(ROUND_LINE) || defined(ANTI_ALIASED_LINE)\n"
00048     "       /* Diffuse texture coordinates */\n"
00049     "       float2 uv0 : DIFFUSE_TEXTURE_COORD0;\n"
00050     "   #endif\n"
00051     "   #if (TEXTURE_COUNT > 1) \n"
00052     "       float2 uv1 : DIFFUSE_TEXTURE_COORD1;\n"
00053     "   #endif\n"
00054     "   #if (TEXTURE_COUNT > 2) \n"
00055     "       float2 uv2 : DIFFUSE_TEXTURE_COORD2;\n"
00056     "   #endif\n"
00057     "   #if (TEXTURE_COUNT > 3) \n"
00058     "       float2 uv3 : DIFFUSE_TEXTURE_COORD3;\n"
00059     "   #endif\n"
00060     "   #if (TEXTURE_COUNT > 4) \n"
00061     "       float2 uv4 : DIFFUSE_TEXTURE_COORD4;\n"
00062     "   #endif\n"
00063     "   #if (TEXTURE_COUNT > 5) \n"
00064     "       float2 uv5 : DIFFUSE_TEXTURE_COORD5;\n"
00065     "   #endif\n"
00066     "   #if (TEXTURE_COUNT > 6) \n"
00067     "       float2 uv6 : DIFFUSE_TEXTURE_COORD6;\n"
00068     "   #endif\n"
00069     "   #if (TEXTURE_COUNT > 7) \n"
00070     "       float2 uv7 : DIFFUSE_TEXTURE_COORD7;\n"
00071     "   #endif\n"
00072     "\n"
00073     "   #if (SHADOW_MAP_COUNT > 0)\n"
00074     "       /* cutting planes */\n"
00075     "       float4 uvsm0 : SHADOW_MAP_COORD0;   \n"
00076     "   #ifdef SHADOW_MAP_JITTER\n"
00077     "       float4 screen_position : SHADOW_MAP_JITTER_COORD;\n"
00078     "   #endif\n"
00079     "   #endif\n"
00080     "   #if (SHADOW_MAP_COUNT > 1)\n"
00081     "       float4 uvsm1 : SHADOW_MAP_COORD1;\n"
00082     "   #endif\n"
00083     "   #if (SHADOW_MAP_COUNT > 2)\n"
00084     "       float4 uvsm2 : SHADOW_MAP_COORD2;\n"
00085     "   #endif\n"
00086     "   #if (SHADOW_MAP_COUNT > 3)\n"
00087     "       float4 uvsm3 : SHADOW_MAP_COORD3;\n"
00088     "   #endif\n"
00089     "\n"
00090     "   #if (CUTTING_PLANE_COUNT > 0)\n"
00091     "       /* cutting planes */\n"
00092     "       float4 uvcp0 : CUTTING_PLANE_COORD0;\n"
00093     "   #endif\n"
00094     "   #if (CUTTING_PLANE_COUNT > 4)\n"
00095     "       float4 uvcp1 : CUTTING_PLANE_COORD1;\n"
00096     "   #endif\n"
00097     "   #if (CUTTING_PLANE_COUNT > 8)\n"
00098     "       float4 uvcp2 : CUTTING_PLANE_COORD2;\n"
00099     "   #endif\n"
00100     "   #if (CUTTING_PLANE_COUNT > 12)\n"
00101     "       float4 uvcp3 : CUTTING_PLANE_COORD3;\n"
00102     "   #endif\n"
00103     "\n"
00104     "   #ifdef ENVIRONMENT_TEXTURE\n"
00105     "       /* special textures */\n"
00106     "       float2 uvenv : ENVIRONMENT_TEXTURE;\n"
00107     "   #endif\n"
00108     "\n"
00109     "   #ifdef SPECULAR_TEXTURE\n"
00110     "       /* special textures */\n"
00111     "       float2 uvspec : SPECULAR_TEXTURE;\n"
00112     "   #endif\n"
00113     "\n"
00114     "   #if defined(DEPTH_PEELING) || defined(DEPTH_WRITING)\n"
00115     "       /* Position as texcoords for depth peeling */\n"
00116     "       float4 peel_position : DEPTH_PEELING_POSITION_COORD;\n"
00117     "   #endif\n"
00118     "\n"
00119     "   #ifdef HAS_FACE_PATTERN\n"
00120     "       float4 uvzwfp : FACE_PATTERN_COORD;\n"
00121     "   #endif\n"
00122     "\n"
00123     "   #ifdef HAS_LINE_PATTERN\n"
00124     "       float4 uvlp : LINE_PATTERN_COORD;\n"
00125     "   #endif\n"
00126     "};\n"
00127     "#else // CREATE_SHADOW_MAP\n"
00128     "struct Iterator\n"
00129     "{\n"
00130     "   /* Transformed vertex position */\n"
00131     "   float4 position : POSITION;\n"
00132     "   /* Position as texcoords for shadow mapping. */\n"
00133     "   float4 shadow_position : TEXCOORD4;\n"
00134     "};\n"
00135     "#endif // ndef CREATE_SHADOW_MAP\n"
00136     "\n"
00137     "/* Uniform Types *************************************************************/\n"
00138     "\n"
00139     "/* A distant light */\n"
00140     "struct distant_light_t\n"
00141     "{\n"
00142     "   float3 direction;\n"
00143     "   float3 diffuse;\n"
00144     "   float3 specular;\n"
00145     "   float3 halfway;\n"
00146     "};\n"
00147     "\n"
00148     "/* A point light */\n"
00149     "struct point_light_t\n"
00150     "{\n"
00151     "   float3 position;\n"
00152     "   float3 diffuse;\n"
00153     "   float3 specular;\n"
00154     "};\n"
00155     "\n"
00156     "/* A spotlight */\n"
00157     "struct spot_light_t\n"
00158     "{\n"
00159     "   float3 position;\n"
00160     "   float3 direction;\n"
00161     "   float2 angles;\n"
00162     "   float3 diffuse;\n"
00163     "   float3 specular;\n"
00164     "};\n"
00165     "\n"
00166     "/* Material Properties */\n"
00167     "struct material_props_t\n"
00168     "{\n"
00169     "   float4 diffuse;\n"
00170     "   //float3 specular;\n"
00171     "   float gloss;\n"
00172     "};\n"
00173     "\n"
00174     "/* Helper functions **********************************************************/\n"
00175     "\n"
00176     "/*\n"
00177     " * Determine diffuse and specular light totals.\n"
00178     " */\n"
00179     "void compute_lighting( const float3 eye_normal, const float3 eye_position, out float3 diffuse_total, out float3 specular_total,\n"
00180     "                      uniform const material_props_t material,\n"
00181     "                      uniform const float3 ambient_light,\n"
00182     "                      uniform const distant_light_t distant_lights[1 + DISTANT_LIGHT_COUNT],\n"
00183     "                      uniform const point_light_t point_lights[1 + POINT_LIGHT_COUNT],\n"
00184     "                      uniform const spot_light_t spot_lights[1 + SPOT_LIGHT_COUNT] )\n"
00185     "{\n"
00186     "   // Start with ambient light\n"
00187     "   diffuse_total = ambient_light;\n"
00188     "   specular_total = 0;\n"
00189     "   \n"
00190     "   // Factor in distant (directional) lights\n"
00191     "   for( int i = 0; i < DISTANT_LIGHT_COUNT; i++)\n"
00192     "   {\n"
00193     "       // Factor in diffuse component of distant light\n"
00194     "       float diffuse_dot = saturate( dot( distant_lights[i].direction, eye_normal ) );\n"
00195     "       diffuse_total += distant_lights[i].diffuse * diffuse_dot;\n"
00196     "       \n"
00197     "       // Factor in specular component of distant light\n"
00198     "       float specular_dot = saturate ( dot(distant_lights[i].halfway,eye_normal) );\n"
00199     "       specular_total +=  distant_lights[i].specular * pow(specular_dot, 4 * material.gloss);\n"
00200     "   }\n"
00201     "   \n"
00202     "   #if (POINT_LIGHT_COUNT > 0) || (SPOT_LIGHT_COUNT > 0)\n"
00203     "   // Compute this once\n"
00204     "   float3 eye_vector = normalize(eye_position);\n"
00205     "   #endif\n"
00206     "               \n"
00207     "   #if (POINT_LIGHT_COUNT > 0)\n"
00208     "   \n"
00209     "       // Factor in point lights\n"
00210     "       for( int i = 0; i < POINT_LIGHT_COUNT; i++)\n"
00211     "       {\n"
00212     "           // Factor in diffuse component of point light\n"
00213     "           float3 light_vector = normalize(point_lights[i].position - eye_position);\n"
00214     "           float diffuse_dot = saturate (dot(eye_normal, light_vector));\n"
00215     "           diffuse_total += (point_lights[i].diffuse * diffuse_dot);\n"
00216     "           \n"
00217     "           // Factor in specular component of point light\n"
00218     "           float3 halfway = normalize( light_vector - eye_vector );\n"
00219     "           float specular_dot = saturate ( dot(halfway,eye_normal) );\n"
00220     "           specular_total += point_lights[i].specular * pow(specular_dot, 4 * material.gloss);\n"
00221     "       }\n"
00222     "\n"
00223     "   #endif // POINT_LIGHT_COUNT > 0\n"
00224     "\n"
00225     "   #if (SPOT_LIGHT_COUNT > 0)\n"
00226     "\n"
00227     "       // Factor in spot lights\n"
00228     "       for( int i = 0; i < SPOT_LIGHT_COUNT; i++)\n"
00229     "       {\n"
00230     "           float3 light_vector = normalize(spot_lights[i].position - eye_position);\n"
00231     "           \n"
00232     "           // Where is the point in the cone?\n"
00233     "           float cone_dot = saturate( dot(light_vector, -spot_lights[i].direction) );\n"
00234     "           \n"
00235     "           // Work out cone angle factor\n"
00236     "           float cone_attenuation = saturate( cone_dot * spot_lights[i].angles.x + spot_lights[i].angles.y );\n"
00237     "\n"
00238     "           // Factor in diffuse component of spot light\n"
00239     "           float diffuse_dot = saturate( dot(eye_normal, light_vector) );\n"
00240     "           diffuse_total += spot_lights[i].diffuse * (cone_attenuation * diffuse_dot);\n"
00241     "           \n"
00242     "           // Factor in specular component of spot light\n"
00243     "           float3 halfway = normalize( light_vector - eye_vector );\n"
00244     "           float specular_dot = saturate ( dot(halfway,eye_normal) );\n"
00245     "           specular_total += spot_lights[i].specular * (cone_attenuation * pow(specular_dot, 4 * material.gloss));\n"
00246     "       }\n"
00247     "\n"
00248     "   #endif // SPOT_LIGHT_COUNT > 0\n"
00249     "   \n"
00250     "   // Done. Results in diffuse/specular_total\n"
00251     "}\n"
00252     "\n"
00253 ; 
00254 
00255 
00256 char CONST * dx9_pixel =
00257     "// Copyright (c) 2007 by Tech Soft 3D, LLC.\n"
00258     "// all rights reserved\n"
00259     "// $Id: dx9hlsl_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $\n"
00260     "   \n"
00261     "/* Uniforms ******************************************************************/\n"
00262     "sampler DiffuseSampler0 : register(DIFFUSE_TEXTURE0_REGISTER);\n"
00263     "sampler DiffuseSampler1 : register(DIFFUSE_TEXTURE1_REGISTER);\n"
00264     "sampler DiffuseSampler2 : register(DIFFUSE_TEXTURE2_REGISTER);\n"
00265     "sampler DiffuseSampler3 : register(DIFFUSE_TEXTURE3_REGISTER);\n"
00266     "sampler DiffuseSampler4 : register(DIFFUSE_TEXTURE4_REGISTER);\n"
00267     "sampler DiffuseSampler5 : register(DIFFUSE_TEXTURE5_REGISTER);\n"
00268     "sampler DiffuseSampler6 : register(DIFFUSE_TEXTURE6_REGISTER);\n"
00269     "sampler DiffuseSampler7 : register(DIFFUSE_TEXTURE7_REGISTER);\n"
00270     "\n"
00271     "float3 ModulationColor0;\n"
00272     "float3 ModulationColor1;\n"
00273     "float3 ModulationColor2;\n"
00274     "float3 ModulationColor3;\n"
00275     "float3 ModulationColor4;\n"
00276     "float3 ModulationColor5;\n"
00277     "float3 ModulationColor6;\n"
00278     "float3 ModulationColor7;\n"
00279     "\n"
00280     "\n"
00281     "#ifdef SPECULAR_TEXTURE_REGISTER\n"
00282     "sampler SpecularSampler : register(SPECULAR_TEXTURE_REGISTER);\n"
00283     "#endif\n"
00284     "\n"
00285     "#ifdef HAS_FACE_PATTERN\n"
00286     "sampler FacePatternSampler : register(FACE_PATTERN_REGISTER);\n"
00287     "float4 FaceContrastColor;\n"
00288     "#endif\n"
00289     "\n"
00290     "#ifdef HAS_LINE_PATTERN\n"
00291     "sampler LinePatternSampler : register(LINE_PATTERN_REGISTER);\n"
00292     "float4 LineContrastColor;\n"
00293     "#endif\n"
00294     "\n"
00295     "#ifdef ENVIRONMENT_TEXTURE_REGISTER\n"
00296     "sampler EnvironmentSampler : register(ENVIRONMENT_TEXTURE_REGISTER);\n"
00297     "#endif\n"
00298     "\n"
00299     "#ifdef DEPTH_PEELING\n"
00300     "sampler DepthPeelingTexture : register(DEPTH_PEELING_TEXTURE_REGISTER);\n"
00301     "float4 DepthPeelingScaleAndBias;\n"
00302     "\n"
00303     "/* Viewport transform for depth peeling texture */\n"
00304     "float4 viewport_scale_and_bias;\n"
00305     "#endif // DEPTH_PEELING\n"
00306     "\n"
00307     "#if (SHADOW_MAP_COUNT > 0)\n"
00308     "sampler ShadowMapTexture0 : register(SHADOW_MAP_TEXTURE0_REGISTER);\n"
00309     "#ifdef SHADOW_MAP_JITTER\n"
00310     "sampler ShadowMapJitterSampler : register(SHADOW_MAP_JITTER_REGISTER);\n"
00311     "#endif // SHADOW_MAP_JITTER\n"
00312     "#endif // SHADOW_MAP_COUNT > 0\n"
00313     "#if (SHADOW_MAP_COUNT > 1)\n"
00314     "sampler ShadowMapTexture1 : register(SHADOW_MAP_TEXTURE1_REGISTER);\n"
00315     "#endif // DEPTH_PEELING\n"
00316     "#if (SHADOW_MAP_COUNT > 2)\n"
00317     "sampler ShadowMapTexture2 : register(SHADOW_MAP_TEXTURE2_REGISTER);\n"
00318     "#endif // DEPTH_PEELING\n"
00319     "#if (SHADOW_MAP_COUNT > 3)\n"
00320     "sampler ShadowMapTexture3 : register(SHADOW_MAP_TEXTURE3_REGISTER);\n"
00321     "#endif // DEPTH_PEELING\n"
00322     "\n"
00323     "float3 diffuse;\n"
00324     "float mirror;\n"
00325     "\n"
00326     "#ifdef PER_PIXEL_LIGHTING\n"
00327     "\n"
00328     "/* Normal ambient lighting */\n"
00329     "float3 AmbientLight;\n"
00330     "\n"
00331     "/* Distant lighting */\n"
00332     "distant_light_t DistantLights[DISTANT_LIGHT_COUNT+1];\n"
00333     "\n"
00334     "/* Point lights */\n"
00335     "point_light_t PointLights[POINT_LIGHT_COUNT+1];\n"
00336     "\n"
00337     "/* Spot lights */\n"
00338     "spot_light_t SpotLights[SPOT_LIGHT_COUNT+1];\n"
00339     "\n"
00340     "/* Material properties */\n"
00341     "material_props_t MaterialProperties;\n"
00342     "\n"
00343     "#endif // PER_PIXEL_LIGHTING\n"
00344     "\n"
00345     "// If we're using shader model 3, we need to support fog manually in the shader.\n"
00346     "#if defined(SHADER_MODEL_3) && defined(HAS_ATMOSPHERIC_ATTENUATION)\n"
00347     "float3 AtmosphericAttenuationColor;\n"
00348     "#endif\n"
00349     "\n"
00350     "/* Code **********************************************************************/\n"
00351     "\n"
00352     "#ifdef DEPTH_TEXTURE_HARDWARE\n"
00353     "#define SHADOW_BIAS 0\n"
00354     "#else\n"
00355     "#define SHADOW_BIAS 0.0001f\n"
00356     "#endif\n"
00357     "\n"
00358     "#if (SHADOW_MAP_COUNT > 0)\n"
00359     "\n"
00360     "\n"
00364     "float get_shadowmap_illumination( float4 jitter, float4 position, sampler2D shadowmap )\n"
00365     "{\n"
00366     "   // No results yet...\n"
00367     "   float accumulator = 0;\n"
00368     "   \n"
00369     "   // Bias depth for testing outside loop\n"
00370     "   float biased_depth = position.z - SHADOW_BIAS;\n"
00371     "   \n"
00372     "   // Temps\n"
00373     "   float4 uv;\n"
00374     "   float4 results;\n"
00375     "\n"
00376     "#ifndef SHADOW_MAP_SAMPLES\n"
00377     "\n"
00378     "   //\n"
00379     "   // Single sample\n"
00380     "   //\n"
00381     "\n"
00382     "   // Start at the centre\n"
00383     "   uv = position;\n"
00384     "\n"
00385     "#ifdef SHADOW_MAP_JITTER\n"
00386     "   // Rotate arbitrary (1,0) coordinate using jitter matrix.\n"
00387     "   uv.xy += jitter.xy;\n"
00388     "#endif // SHADOW_MAP_JITTER\n"
00389     "\n"
00390     "   results.x = tex2Dproj(shadowmap, uv);\n"
00391     "\n"
00392     "#ifndef DEPTH_TEXTURE_HARDWARE\n"
00393     "   // Do test\n"
00394     "   results.x = biased_depth < results.x;\n"
00395     "#endif\n"
00396     "\n"
00397     "   // Store\n"
00398     "   accumulator = results.x;\n"
00399     "\n"
00400     "#else\n"
00401     "\n"
00402     "   //\n"
00403     "   // Multiple samples in batches of four, vectorised.\n"
00404     "   //\n"
00405     "\n"
00406     "   // Weight each sample by 1/num samples\n"
00407     "   float weight = 1.0f/SHADOW_MAP_SAMPLES;\n"
00408     "   \n"
00409     "   // Hoisting these swizzles seems to help the compiler generate vector rather than scalar code.\n"
00410     "   float4 position_xyxy = position.xyxy;\n"
00411     "   float4 jitter_xzxz = jitter.xzxz;\n"
00412     "   float4 jitter_ywyw = jitter.ywyw;\n"
00413     "   \n"
00414     "   for ( int i = 0; i < SHADOW_MAP_SAMPLES/4; ++i )\n"
00415     "   {\n"
00416     "       //\n"
00417     "       // Jittered sampling. Note that we don't need to #ifdef this out in non-jitter mode - \n"
00418     "       // the jitter matrix will be identity and the compiler will optimise it out.\n"
00419     "       //\n"
00420     "   \n"
00421     "       // Rotate first two sample points\n"
00422     "       uv = position_xyxy + jitter_xzxz * pcf_taps[i * 2];\n"
00423     "#ifdef SHADER_MODEL_3\n"
00424     "       // Complete the rotation. (Higher quality)\n"
00425     "       uv += jitter_ywyw * pcf_taps[i * 2];\n"
00426     "#endif SHADER_MODEL_3\n"
00427     "\n"
00428     "       // Take first two samples\n"
00429     "       results.x = tex2Dproj(shadowmap, float4(uv.xy,position.zw));\n"
00430     "       results.y = tex2Dproj(shadowmap, float4(uv.zw,position.zw));\n"
00431     "\n"
00432     "       // Rotate second two sample points\n"
00433     "       uv = position_xyxy + jitter_xzxz * pcf_taps[i * 2 + 1];\n"
00434     "#ifdef SHADER_MODEL_3\n"
00435     "       // Complete the rotation\n"
00436     "       uv += jitter_ywyw * pcf_taps[i * 2 + 1];\n"
00437     "#endif SHADER_MODEL_3      \n"
00438     "       \n"
00439     "       // Take second two samples\n"
00440     "       results.z = tex2Dproj(shadowmap, float4(uv.xy,position.zw));\n"
00441     "       results.w = tex2Dproj(shadowmap, float4(uv.zw,position.zw));\n"
00442     "       \n"
00443     "#ifndef DEPTH_TEXTURE_HARDWARE\n"
00444     "       // Do tests\n"
00445     "       results = biased_depth < results;\n"
00446     "#endif\n"
00447     "\n"
00448     "       // Sum results for four samples\n"
00449     "       accumulator += dot(results,weight);\n"
00450     "   }\n"
00451     "\n"
00452     "#endif // def SHADOW_MAP_SAMPLES\n"
00453     "   \n"
00454     "   // Done\n"
00455     "   return accumulator;\n"
00456     "}\n"
00457     "#endif\n"
00458     "\n"
00459     "#ifdef TEST_CODE\n"
00460     "float2 get_shadowmap_knockout2( float4 position, sampler2D shadowmap )\n"
00461     "{\n"
00462     "   float3 shadow_uvz = position.xyz / position.w;\n"
00463     "   shadow_uvz.xy = float2(0.5f,-0.5f) * shadow_uvz.xy + float2(0.5f,0.5f) + float2(0.5f, 0.5f) / SHADOW_MAP_SIZE;\n"
00464     "\n"
00465     "   float accumulator[4] = { 0, 0, 0, 0 };\n"
00466     "   float result = 0;\n"
00467     "\n"
00468     "   for ( int i = 0; i < TAP_COUNT; ++i )\n"
00469     "   {\n"
00470     "       // Offset UV for this tap\n"
00471     "       float2 uv = shadow_uvz.xy + pcf_taps[i] / SHADOW_MAP_SIZE;\n"
00472     "\n"
00473     "       // Sample the map\n"
00474     "       float shadow_result = tex2D(shadowmap, uv);\n"
00475     "       \n"
00476     "       // Accumulate test result\n"
00477     "       if ( shadow_uvz.z <= shadow_result + SHADOW_BIAS )\n"
00478     "       {\n"
00479     "           accumulator[i] = 1.0f;\n"
00480     "       }\n"
00481     "   }\n"
00482     "\n"
00483     "   float2 p = frac(shadow_uvz.xy * SHADOW_MAP_SIZE - 0.5f);\n"
00484     "   float top = lerp(accumulator[0], accumulator[1], p.x);\n"
00485     "   float bot = lerp(accumulator[2], accumulator[3], p.x);\n"
00486     "   result = lerp(top, bot, p.y);\n"
00487     "\n"
00488     "   // Normalise\n"
00489     "   //result /= TAP_COUNT;\n"
00490     "\n"
00491     "   return float2(0.5f, 0.25f) + result * float2(0.5f, 0.75f);\n"
00492     "}\n"
00493     "#endif\n"
00494     "\n"
00495     "#ifdef DEPTH_PEELING\n"
00496     "\n"
00497     "// Define bias constant\n"
00498     "#ifdef DEPTH_PEELING_RGBA\n"
00499     "   // No bias in RGBA mode \n"
00500     "   #define DEPTH_PEELING_BIAS 0\n"
00501     "       \n"
00502     "   // Pack a float value for output to RGBA8 texture.\n"
00503     "   float4 pack_rgba(float value)\n"
00504     "   {\n"
00505     "       const float4 shift = float4(1, 256, 256*256,  256*256*256); \n"
00506     "       const float4 mask = float4(1.0f/256, 1.0f/256, 1.0f/256, 0); \n"
00507     "\n"
00508     "       // Shift into the different ranges and take the fractional part in each.\n"
00509     "       float4 packed = frac(value * shift);\n"
00510     "       \n"
00511     "       // Remove what can't be represented.\n"
00512     "       return packed - mask * packed.yzww; \n"
00513     "   }\n"
00514     "\n"
00515     "   /// Unpacking a [0-1] float value from a 4D vector where each component was a 8-bits integer\n"
00516     "   float unpack_rgba(const float4 value)\n"
00517     "   {\n"
00518     "       // Reconstruct by mutliplying each range by the remainder and add up.\n"
00519     "       const float4 shift = float4(1, 1.0f/256, 1.0f/(256*256), 1.0/(256*256*256));\n"
00520     "       return dot(value, shift);   \n"
00521     "   }\n"
00522     "#else\n"
00523     "   #ifndef CAMERA_PERSPECTIVE\n"
00524     "       #define DEPTH_PEELING_BIAS 0.000001f\n"
00525     "   #else\n"
00526     "       #define DEPTH_PEELING_BIAS 0.000001f\n"
00527     "   #endif\n"
00528     "#endif // DEPTH_PEELING_RGBA\n"
00529     "   \n"
00530     "#endif // DEPTH_PEELING\n"
00531     "\n"
00532     "/* Main **********************************************************************/\n"
00533     "void main (\n"
00534     "   Iterator input\n"
00535     "   , out float4 FinalColor : COLOR0\n"
00536     "#ifdef SHADER_MODEL_3\n"
00537     "   , in float Face : VFACE\n"
00538     "#endif // SHADER_MODEL_3\n"
00539     "#if defined(DEPTH_WRITING) && defined(DEPTH_PEELING_SINGLE_PASS)\n"
00540     "   , out float4 FinalDepth : COLOR1\n"
00541     "#endif // DEPTH_PEELING_SINGLE_PASS && DEPTH_WRITING \n"
00542     ")\n"
00543     "{   \n"
00544     "#ifdef CREATE_SHADOW_MAP\n"
00545     "\n"
00546     "   // Read position from input, perspective divide, and write z.\n"
00547     "   FinalColor.r = input.shadow_position.z / input.shadow_position.w;\n"
00548     "   FinalColor.gba = 0;\n"
00549     "\n"
00550     "#else // CREATE_SHADOW_MAP\n"
00551     "\n"
00552     "#ifdef DEPTH_PEELING\n"
00553     "\n"
00554     "   // Read position from input\n"
00555     "   float4 peel = input.peel_position;\n"
00556     "\n"
00557     "   // Perspective divide.\n"
00558     "   peel.xyz /= peel.w;\n"
00559     "\n"
00560     "   // Normalize depth such that it never reaches 1.0 (needed for packing)\n"
00561     "   peel.z = saturate( peel.z * 0.9f );\n"
00562     "\n"
00563     "   // Map to viewport\n"
00564     "   peel.xy *= viewport_scale_and_bias.xy;\n"
00565     "   peel.xy += viewport_scale_and_bias.zw;\n"
00566     "\n"
00567     "   // Scale and bias to turn into texture coords\n"
00568     "   peel.xy *= DepthPeelingScaleAndBias.xy;\n"
00569     "   peel.xy += DepthPeelingScaleAndBias.zw;\n"
00570     "   \n"
00571     "   // Lookup depth texture\n"
00572     "   const float4 peel_texture = tex2D( DepthPeelingTexture, peel );\n"
00573     "   \n"
00574     "   #ifdef DEPTH_PEELING_RGBA\n"
00575     "       // Unpack from RGBA\n"
00576     "       const float previous_depth = unpack_rgba( peel_texture );\n"
00577     "   #else\n"
00578     "       // Use directly.\n"
00579     "       const float previous_depth = peel_texture.r;\n"
00580     "   #endif // DEPTH_PEELING_RGBA\n"
00581     "\n"
00582     "   // If this fragment is nearer (depth less than) what we drew last time, discard it.\n"
00583     "   clip( peel.z - (previous_depth+DEPTH_PEELING_BIAS) );\n"
00584     "\n"
00585     "   #ifdef DEPTH_WRITING\n"
00586     "   \n"
00587     "       #ifdef DEPTH_PEELING_RGBA\n"
00588     "           // Pack depth into colour channels\n"
00589     "           const float4 final_depth = pack_rgba(peel.z);\n"
00590     "       #else\n"
00591     "           // Output depth as float\n"
00592     "           const float4 final_depth = peel.z;\n"
00593     "       #endif // DEPTH_PEELING_RGBA\n"
00594     "       \n"
00595     "       #ifdef DEPTH_PEELING_SINGLE_PASS\n"
00596     "           // Output depth to second channel, carry on through shader to do colour.\n"
00597     "           FinalDepth = final_depth;\n"
00598     "       #else\n"
00599     "           // If we're in multipass, output depth and stop\n"
00600     "           FinalColor = final_depth;\n"
00601     "           return;\n"
00602     "       #endif // DEPTH_PEELING_SINGLE_PASS\n"
00603     "\n"
00604     "   #endif // DEPTH_WRITING\n"
00605     "   \n"
00606     "#endif // DEPTH_PEELING\n"
00607     "\n"
00608     "#ifdef PER_PIXEL_LIGHTING\n"
00609     "\n"
00610     "   // Reconstruct normal\n"
00611     "   float3 eye_normal = normalize(input.specular_color.xyz * 2 - 1);\n"
00612     "\n"
00613     "   #if defined(SHADER_MODEL_3) && defined(HAS_HANDEDNESS) && defined(TRIANGLE)\n"
00614     "       // Exact normal fix using face register.\n"
00615     "       eye_normal *= NORMAL_FLIP_SIGN * sign(Face);\n"
00616     "       #ifdef RIGHT_HANDED_MATRIX\n"
00617     "           eye_normal = -eye_normal;\n"
00618     "       #endif\n"
00619     "   #else   \n"
00620     "       #ifdef HAS_HANDEDNESS\n"
00621     "           #ifdef RIGHT_HANDED_MATRIX\n"
00622     "               eye_normal = -eye_normal;\n"
00623     "           #endif\n"
00624     "       #else\n"
00625     "           if(eye_normal.z > 0)\n"
00626     "               eye_normal = -eye_normal;\n"
00627     "       #endif\n"
00628     "   #endif // ndef SHADER_MODEL_3\n"
00629     "\n"
00630     "   #if (POINT_LIGHT_COUNT > 0) || (SPOT_LIGHT_COUNT > 0)\n"
00631     "       // Get  hold of eye position\n"
00632     "       float3 eye_position = input.eye_position.xyz;\n"
00633     "   #else\n"
00634     "       // Dummy position - will not be used\n"
00635     "       float3 eye_position = (1,0,0);\n"
00636     "   #endif\n"
00637     "   \n"
00638     "   float3 diffuse, specular;\n"
00639     "   compute_lighting( eye_normal, eye_position, diffuse, specular, \n"
00640     "                     MaterialProperties, AmbientLight, DistantLights, PointLights, SpotLights );\n"
00641     "   \n"
00642     "   // Incorporate lighting colors\n"
00643     "   #ifdef HAS_VERTEX_COLORS\n"
00644     "       // Combine with interpolated color from vertex\n"
00645     "       input.diffuse_color.rgb *= diffuse;\n"
00646     "   #else\n"
00647     "       // Replace material color, which we don't care about apart from alpha\n"
00648     "       input.diffuse_color.rgb = diffuse;\n"
00649     "   #endif // HAS_VERTEX_COLORS\n"
00650     "   input.specular_color.rgb = specular;\n"
00651     "\n"
00652     "#endif // PER_PIXEL_LIGHTING\n"
00653     "\n"
00654     "//If cutting planes exist, and the pixel is 'cut', then discard\n"
00655     "#if (CUTTING_PLANE_COUNT > 0)\n"
00656     "   clip(input.uvcp0);\n"
00657     "#endif\n"
00658     "#if (CUTTING_PLANE_COUNT > 4)\n"
00659     "   clip(input.uvcp1);\n"
00660     "#endif\n"
00661     "#if (CUTTING_PLANE_COUNT > 8)\n"
00662     "   clip(input.uvcp2);\n"
00663     "#endif\n"
00664     "#if (CUTTING_PLANE_COUNT > 12)\n"
00665     "   clip(input.uvcp3);\n"
00666     "#endif\n"
00667     "\n"
00668     "    //calculate the fog factor  \n"
00669     "    //float fog = CalcFogFactor( input.fogDist );\n"
00670     "    \n"
00671     "    //alpha test\n"
00672     "    //if( color.a < 0.5 )\n"
00673     "    //    discard;\n"
00674     "\n"
00675     "   float4 final_color = input.diffuse_color;\n"
00676     "   float4 tex_color = 0;\n"
00677     "   float4 new_color = 0;\n"
00678     "\n"
00679     "#if (TEXTURE_COUNT > 0) || defined(ROUND_LINE) || defined(ANTI_ALIASED_LINE)\n"
00680     "   // Factor in the diffuse texture specular_color\n"
00681     "   // Deal with Texture Unit 0\n"
00682     "   #ifdef TEXTURE0_COLOR\n"
00683     "       tex_color = tex2D(DiffuseSampler0, input.uv0) * float4(ModulationColor0,1);\n"
00684     "   #else\n"
00685     "       tex_color = tex2D(DiffuseSampler0, input.uv0);\n"
00686     "   #endif\n"
00687     "\n"
00688     "   #if defined(ROUND_LINE) || defined(ANTI_ALIASED_LINE)\n"
00689     "       #ifndef ANTI_ALIASED_LINE\n"
00690     "           if(tex_color.a < 0.5)\n"
00691     "               discard;\n"
00692     "           tex_color.a = input.diffuse_color.a * ceil(tex_color.a);\n"
00693     "       #endif\n"
00694     "       tex_color.rgb = input.diffuse_color.rgb;\n"
00695     "   #endif\n"
00696     "\n"
00697     "   #ifdef TEXTURE0_DECAL\n"
00698     "       new_color = float4(lerp((float3)diffuse, tex_color, tex_color.a), 1);\n"
00699     "   #else\n"
00700     "       new_color = tex_color;\n"
00701     "   #endif\n"
00702     "\n"
00703     "   #ifdef HAS_VERTEX_NORMALS\n"
00704     "       // We need to check TEXTURE0_MODULATE to see if we need to multiply texture alpha or not\n"
00705     "       #ifdef TEXTURE0_MODULATE\n"
00706     "           final_color.rgb *= new_color.rgb;\n"
00707     "       #else\n"
00708     "           final_color *= new_color;\n"
00709     "       #endif\n"
00710     "   #else\n"
00711     "       #ifdef TEXTURE0_MODULATE\n"
00712     "           final_color.rgb *= new_color.rgb;\n"
00713     "       #else\n"
00714     "           final_color = float4(new_color.rgb, final_color.a * new_color.a);\n"
00715     "       #endif\n"
00716     "   #endif\n"
00717     "#endif\n"
00718     "\n"
00719     "\n"
00720     "#if (TEXTURE_COUNT > 1)\n"
00721     "   // Deal with Texture Unit 1\n"
00722     "   #ifdef TEXTURE1_COLOR\n"
00723     "       tex_color = tex2D(DiffuseSampler1, input.uv1) * float4(ModulationColor1,1);\n"
00724     "   #else\n"
00725     "       tex_color = tex2D(DiffuseSampler1, input.uv1);\n"
00726     "   #endif\n"
00727     "\n"
00728     "   new_color = float4(lerp((float3)final_color, tex_color, tex_color.a), final_color.a);\n"
00729     "\n"
00730     "   #ifdef TEXTURE1_MODULATE\n"
00731     "       final_color *= new_color;\n"
00732     "   #else\n"
00733     "       final_color = new_color;\n"
00734     "   #endif\n"
00735     "#endif\n"
00736     "\n"
00737     "#if (TEXTURE_COUNT > 2)\n"
00738     "   // Deal with Texture Unit 2\n"
00739     "   #ifdef TEXTURE2_COLOR\n"
00740     "       tex_color = tex2D(DiffuseSampler2, input.uv2) * float4(ModulationColor2,1);\n"
00741     "   #else\n"
00742     "       tex_color = tex2D(DiffuseSampler2, input.uv2);\n"
00743     "   #endif\n"
00744     "\n"
00745     "   new_color = float4(lerp((float3)final_color, tex_color, tex_color.a), final_color.a);\n"
00746     "\n"
00747     "   #ifdef TEXTURE2_MODULATE\n"
00748     "       final_color *= new_color;\n"
00749     "   #else\n"
00750     "       final_color = new_color;\n"
00751     "   #endif\n"
00752     "#endif\n"
00753     "\n"
00754     "#if (TEXTURE_COUNT > 3)\n"
00755     "   // Deal with Texture Unit 3\n"
00756     "   #ifdef TEXTURE3_COLOR\n"
00757     "       tex_color = tex2D(DiffuseSampler3, input.uv3) * float4(ModulationColor3,1);\n"
00758     "   #else\n"
00759     "       tex_color = tex2D(DiffuseSampler3, input.uv3);\n"
00760     "   #endif\n"
00761     "\n"
00762     "   new_color = float4(lerp((float3)final_color, tex_color, tex_color.a), final_color.a);\n"
00763     "\n"
00764     "   #ifdef TEXTURE3_MODULATE\n"
00765     "       final_color *= new_color;\n"
00766     "   #else\n"
00767     "       final_color = new_color;\n"
00768     "   #endif\n"
00769     "#endif\n"
00770     "\n"
00771     "#if (TEXTURE_COUNT > 4)\n"
00772     "   // Deal with Texture Unit 4\n"
00773     "   #ifdef TEXTURE4_COLOR\n"
00774     "       tex_color = tex2D(DiffuseSampler4, input.uv4) * float4(ModulationColor4,1);\n"
00775     "   #else\n"
00776     "       tex_color = tex2D(DiffuseSampler4, input.uv4);\n"
00777     "   #endif\n"
00778     "\n"
00779     "   new_color = float4(lerp((float3)final_color, tex_color, tex_color.a), final_color.a);\n"
00780     "\n"
00781     "   #ifdef TEXTURE4_MODULATE\n"
00782     "       final_color *= new_color;\n"
00783     "   #else\n"
00784     "       final_color = new_color;\n"
00785     "   #endif\n"
00786     "#endif\n"
00787     "\n"
00788     "#if (TEXTURE_COUNT > 5)\n"
00789     "   // Deal with Texture Unit 5\n"
00790     "   #ifdef TEXTURE5_COLOR\n"
00791     "       tex_color = tex2D(DiffuseSampler5, input.uv5) * float4(ModulationColor5,1);\n"
00792     "   #else\n"
00793     "       tex_color = tex2D(DiffuseSampler5, input.uv5);\n"
00794     "   #endif\n"
00795     "\n"
00796     "   new_color = float4(lerp((float3)final_color, tex_color, tex_color.a), final_color.a);\n"
00797     "\n"
00798     "   #ifdef TEXTURE5_MODULATE\n"
00799     "       final_color *= new_color;\n"
00800     "   #else\n"
00801     "       final_color = new_color;\n"
00802     "   #endif\n"
00803     "#endif\n"
00804     "\n"
00805     "#if (TEXTURE_COUNT > 6)\n"
00806     "   // Deal with Texture Unit 6\n"
00807     "   #ifdef TEXTURE6_COLOR\n"
00808     "       tex_color = tex2D(DiffuseSampler6, input.uv6) * float4(ModulationColor6,1);\n"
00809     "   #else\n"
00810     "       tex_color = tex2D(DiffuseSampler6, input.uv6);\n"
00811     "   #endif\n"
00812     "\n"
00813     "   new_color = float4(lerp((float3)final_color, tex_color, tex_color.a), final_color.a);\n"
00814     "\n"
00815     "   #ifdef TEXTURE6_MODULATE\n"
00816     "       final_color *= new_color;\n"
00817     "   #else\n"
00818     "       final_color = new_color;\n"
00819     "   #endif\n"
00820     "#endif\n"
00821     "\n"
00822     "#if (TEXTURE_COUNT > 7)\n"
00823     "   // Deal with Texture Unit 7\n"
00824     "   #ifdef TEXTURE7_COLOR\n"
00825     "       tex_color = tex2D(DiffuseSampler7, input.uv7) * float4(ModulationColor7,1);\n"
00826     "   #else\n"
00827     "       tex_color = tex2D(DiffuseSampler7, input.uv7);\n"
00828     "   #endif\n"
00829     "\n"
00830     "   new_color = float4(lerp((float3)final_color, tex_color, tex_color.a), final_color.a);\n"
00831     "\n"
00832     "   #ifdef TEXTURE7_MODULATE\n"
00833     "       final_color *= new_color;\n"
00834     "   #else\n"
00835     "       final_color = new_color;\n"
00836     "   #endif\n"
00837     "#endif\n"
00838     "\n"
00839     "#ifdef ENVIRONMENT_TEXTURE\n"
00840     "   mirror = saturate(mirror);\n"
00841     "   tex_color = tex2D(EnvironmentSampler, input.uvenv);\n"
00842     "\n"
00843     "   final_color = float4(lerp((float3)final_color, tex_color, mirror), final_color.a);\n"
00844     "#endif\n"
00845     "\n"
00846     "#if (SHADOW_MAP_COUNT > 0)\n"
00847     "\n"
00848     "   // Default to no jitter.\n"
00849     "   float4 jitter = float4(1,1,1,1);\n"
00850     "\n"
00851     "#ifdef SHADOW_MAP_JITTER   \n"
00852     "   // 2x2 Rotation matrix with row 0 in xy, row 1 in zw. Load this once!\n"
00853     "   jitter = tex2D(ShadowMapJitterSampler, input.screen_position.xy/input.screen_position.w) * 2 - 1;\n"
00854     "#endif // SHADOW_MAP_JITTER\n"
00855     "   \n"
00856     "   // Scale to texture coords and expand filter slightly to hide texel artifacts.\n"
00857     "   jitter *= 2.0f / SHADOW_MAP_SIZE;\n"
00858     "\n"
00859     "   float illumination = get_shadowmap_illumination(jitter, input.uvsm0, ShadowMapTexture0);\n"
00860     "#if (SHADOW_MAP_COUNT > 1)\n"
00861     "   illumination *= get_shadowmap_illumination(jitter, input.uvsm1, ShadowMapTexture1);\n"
00862     "#endif\n"
00863     "#if (SHADOW_MAP_COUNT > 2)\n"
00864     "   illumination *= get_shadowmap_illumination(jitter, input.uvsm2, ShadowMapTexture2);\n"
00865     "#endif\n"
00866     "#if (SHADOW_MAP_COUNT > 3)\n"
00867     "   illumination *= get_shadowmap_illumination(jitter, input.uvsm3, ShadowMapTexture3);\n"
00868     "#endif\n"
00869     "   final_color *= 0.5f + 0.5f * illumination;\n"
00870     "   input.specular_color *= illumination;\n"
00871     "#endif\n"
00872     "   \n"
00873     "#ifdef SPECULAR_TEXTURE\n"
00874     "   final_color.rgb += input.specular_color.rgb * tex2D(SpecularSampler, input.uvspec);\n"
00875     "#else\n"
00876     "   final_color.rgb += input.specular_color.rgb;\n"
00877     "#endif\n"
00878     "\n"
00879     "#ifdef HAS_FACE_PATTERN\n"
00880     "   float texel_offset;\n"
00881     "\n"
00882     "   #ifdef CAMERA_PERSPECTIVE\n"
00883     "       #ifdef HAS_TRANSPARENCY_STIPPLE\n"
00884     "           texel_offset = 0.5/16;\n"
00885     "       #else\n"
00886     "           texel_offset = 0.5/32;\n"
00887     "       #endif\n"
00888     "   \n"
00889     "       input.uvzwfp.xy /= input.uvzwfp.w;\n"
00890     "       input.uvzwfp.xy += texel_offset;\n"
00891     "   #endif\n"
00892     "   \n"
00893     "   tex_color = tex2D(FacePatternSampler, input.uvzwfp.xy);\n"
00894     "\n"
00895     "   #ifdef HAS_TRANSPARENCY_STIPPLE\n"
00896     "       if(tex_color.a > 0)\n"
00897     "           discard;\n"
00898     "   #else\n"
00899     "       if(tex_color.a < 1)\n"
00900     "           final_color = FaceContrastColor;\n"
00901     "   #endif\n"
00902     "#endif\n"
00903     "\n"
00904     "#ifdef HAS_LINE_PATTERN\n"
00905     "   tex_color = tex2D(LinePatternSampler, input.uvlp.xy);\n"
00906     "\n"
00907     "   if(tex_color.a < 1)\n"
00908     "       discard;\n"
00909     "#endif\n"
00910     "\n"
00911     "#if defined(SHADER_MODEL_3) && defined(HAS_ATMOSPHERIC_ATTENUATION)\n"
00912     "   final_color.rgb = lerp(AtmosphericAttenuationColor,final_color.rgb, input.fog);\n"
00913     "#endif \n"
00914     "\n"
00915     "#if defined(CREATE_REFLECTION_PLANE) || defined(DEPTH_PEELING)\n"
00916     "\n"
00917     "   // Premultiply by alpha so we can filter and compose properly.\n"
00918     "   final_color.rgb *= final_color.a;\n"
00919     "\n"
00920     "#endif // CREATE_REFLECTION_PLANE\n"
00921     "\n"
00922     "   // Output color\n"
00923     "    FinalColor = final_color;\n"
00924     "\n"
00925     "#endif // CREATE_SHADOW_MAP\n"
00926     "\n"
00927     "#ifdef CREATE_SIMPLE_SHADOW\n"
00928     "\n"
00929     "   // Output whiteness, let material determine opacity.\n"
00930     "   FinalColor.rgb = 1;\n"
00931     "   \n"
00932     "#endif // CREATE_SIMPLE_SHADOW\n"
00933     "}\n"
00934     "\n"
00935 ; 
00936 
00937 
00938 char CONST * dx9_post_apply_reflection =
00939     "// Copyright (c) 2007 by Tech Soft 3D, LLC.\n"
00940     "// all rights reserved\n"
00941     "// $Id: dx9hlsl_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $\n"
00942     " \n"
00943     "/* IO Types ******************************************************************/\n"
00944     "\n"
00945     "/* \n"
00946     " * ITERATOR\n"
00947     " * Input from triangle setup \n"
00948     " */\n"
00949     "struct Iterator\n"
00950     "{\n"
00951     "   /* Transformed vertex position */\n"
00952     "   float4 position : POSITION;\n"
00953     "   \n"
00954     "   /* Texture coordinates */\n"
00955     "   float4 uv : TEXCOORD0;\n"
00956     "   float2 world_uv : TEXCOORD1;\n"
00957     "};\n"
00958     "\n"
00959     "/* Uniforms ******************************************************************/\n"
00960     "\n"
00961     "sampler2D ReflectionSampler;\n"
00962     "sampler2D NormalMapSampler;\n"
00963     "\n"
00964     "float Opacity;\n"
00965     "float BumpSize;\n"
00966     "float BumpStrength;\n"
00967     "\n"
00968     "/* Code **********************************************************************/\n"
00969     "\n"
00970     "float4 main( const Iterator iterator ) : COLOR0\n"
00971     "{\n"
00972     "   // For diagnosing problems with the UV mapping\n"
00973     "   //return float4(frac(iterator.world_uv/BumpSize),0,1);\n"
00974     "   \n"
00975     "   // Form perspective-correct bumped image-space texture coords\n"
00976     "   float2 uv = 0.5f + 0.5f * (iterator.uv.xy/iterator.uv.w);\n"
00977     "   \n"
00978     "#ifdef REFLECTION_BUMPMAP\n"
00979     "   // Lookup bump\n"
00980     "   float2 offset = tex2D(NormalMapSampler, iterator.world_uv/BumpSize).rg * 2 - 1;\n"
00981     "\n"
00982     "   // Offset coordinates\n"
00983     "   uv += offset * BumpStrength;\n"
00984     "#endif // REFLECTION_BUMPMAP\n"
00985     "   \n"
00986     "   // Sample reflection\n"
00987     "   float2 flip_uv = float2(uv.x, 1-uv.y);\n"
00988     "   float4 reflection = tex2D( ReflectionSampler, flip_uv );\n"
00989     "\n"
00990     "   // Fade reflection (premultiplied alpha, don't forget, so we multiply alpha and rgb)\n"
00991     "   return reflection * Opacity;\n"
00992     "} \n"
00993     "\n"
00994 ; 
00995 
00996 
00997 char CONST * dx9_post_copy =
00998     "// Copyright (c) 2007 by Tech Soft 3D, LLC.\n"
00999     "// all rights reserved\n"
01000     "// $Id: dx9hlsl_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $\n"
01001     " \n"
01002     "/* IO Types ******************************************************************/\n"
01003     "\n"
01004     "/* \n"
01005     " * ITERATOR\n"
01006     " * Input from triangle setup \n"
01007     " */\n"
01008     "struct Iterator\n"
01009     "{\n"
01010     "   /* Transformed vertex position */\n"
01011     "   float4 position : POSITION;\n"
01012     "   \n"
01013     "   /* Texture coordinate */\n"
01014     "   float2 uv : TEXCOORD0;\n"
01015     "};\n"
01016     "\n"
01017     "/* Uniforms ******************************************************************/\n"
01018     "\n"
01019     "sampler2D Sampler;\n"
01020     "float4 ModulationColor;\n"
01021     "\n"
01022     "/* Code **********************************************************************/\n"
01023     "\n"
01024     "float4 main( const Iterator iterator ) : COLOR0\n"
01025     "{\n"
01026     "   return ModulationColor * tex2D( Sampler, iterator.uv );\n"
01027     "} \n"
01028     "\n"
01029 ; 
01030 
01031 
01032 char CONST * dx9_post_filter_12 =
01033     "// Copyright (c) 2007 by Tech Soft 3D, LLC.\n"
01034     "// all rights reserved\n"
01035     "// $Id: dx9hlsl_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $\n"
01036     " \n"
01037     "// Specialise filter shader for N taps\n"
01038     "#define NUM_TAPS 12\n"
01039     "\n"
01040     "// Copyright (c) 2007 by Tech Soft 3D, LLC.\n"
01041     "// all rights reserved\n"
01042     "// $Id: dx9hlsl_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $\n"
01043     " \n"
01044     "#ifndef NUM_TAPS\n"
01045     "#error NUM_TAPS must be defined to use this shader!\n"
01046     "#endif // NUM_TAPS\n"
01047     " \n"
01048     "/* IO Types ******************************************************************/\n"
01049     "\n"
01050     "/* \n"
01051     " * ITERATOR\n"
01052     " * Input from triangle setup \n"
01053     " */\n"
01054     "struct Iterator\n"
01055     "{\n"
01056     "   /* Transformed vertex position */\n"
01057     "   float4 position : POSITION;\n"
01058     "   \n"
01059     "   /* Texture coordinate */\n"
01060     "   float2 uv : TEXCOORD0;\n"
01061     "};\n"
01062     "\n"
01063     "/* Uniforms ******************************************************************/\n"
01064     "\n"
01065     "sampler2D Sampler;\n"
01066     "const float4 Kernel[NUM_TAPS];\n"
01067     "\n"
01068     "/* Code **********************************************************************/\n"
01069     "\n"
01070     "float4 main( const Iterator iterator ) : COLOR0\n"
01071     "{\n"
01072     "   float4 result = 0;\n"
01073     "   for ( int i = 0; i < NUM_TAPS; ++i )\n"
01074     "   {\n"
01075     "       result += Kernel[i].w * tex2D( Sampler, iterator.uv + Kernel[i].xy );\n"
01076     "   }\n"
01077     "\n"
01078     "   return result;\n"
01079     "} \n"
01080     "\n"
01081 ; 
01082 
01083 
01084 char CONST * dx9_post_filter_16 =
01085     "// Copyright (c) 2007 by Tech Soft 3D, LLC.\n"
01086     "// all rights reserved\n"
01087     "// $Id: dx9hlsl_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $\n"
01088     " \n"
01089     "// Specialise filter shader for N taps\n"
01090     "#define NUM_TAPS 16\n"
01091     "\n"
01092     "// Copyright (c) 2007 by Tech Soft 3D, LLC.\n"
01093     "// all rights reserved\n"
01094     "// $Id: dx9hlsl_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $\n"
01095     " \n"
01096     "#ifndef NUM_TAPS\n"
01097     "#error NUM_TAPS must be defined to use this shader!\n"
01098     "#endif // NUM_TAPS\n"
01099     " \n"
01100     "/* IO Types ******************************************************************/\n"
01101     "\n"
01102     "/* \n"
01103     " * ITERATOR\n"
01104     " * Input from triangle setup \n"
01105     " */\n"
01106     "struct Iterator\n"
01107     "{\n"
01108     "   /* Transformed vertex position */\n"
01109     "   float4 position : POSITION;\n"
01110     "   \n"
01111     "   /* Texture coordinate */\n"
01112     "   float2 uv : TEXCOORD0;\n"
01113     "};\n"
01114     "\n"
01115     "/* Uniforms ******************************************************************/\n"
01116     "\n"
01117     "sampler2D Sampler;\n"
01118     "const float4 Kernel[NUM_TAPS];\n"
01119     "\n"
01120     "/* Code **********************************************************************/\n"
01121     "\n"
01122     "float4 main( const Iterator iterator ) : COLOR0\n"
01123     "{\n"
01124     "   float4 result = 0;\n"
01125     "   for ( int i = 0; i < NUM_TAPS; ++i )\n"
01126     "   {\n"
01127     "       result += Kernel[i].w * tex2D( Sampler, iterator.uv + Kernel[i].xy );\n"
01128     "   }\n"
01129     "\n"
01130     "   return result;\n"
01131     "} \n"
01132     "\n"
01133     "\n"
01134 ; 
01135 
01136 
01137 char CONST * dx9_post_filter_4 =
01138     "// Copyright (c) 2007 by Tech Soft 3D, LLC.\n"
01139     "// all rights reserved\n"
01140     "// $Id: dx9hlsl_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $\n"
01141     " \n"
01142     "// Specialise filter shader for N taps\n"
01143     "#define NUM_TAPS 4\n"
01144     "\n"
01145     "// Copyright (c) 2007 by Tech Soft 3D, LLC.\n"
01146     "// all rights reserved\n"
01147     "// $Id: dx9hlsl_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $\n"
01148     " \n"
01149     "#ifndef NUM_TAPS\n"
01150     "#error NUM_TAPS must be defined to use this shader!\n"
01151     "#endif // NUM_TAPS\n"
01152     " \n"
01153     "/* IO Types ******************************************************************/\n"
01154     "\n"
01155     "/* \n"
01156     " * ITERATOR\n"
01157     " * Input from triangle setup \n"
01158     " */\n"
01159     "struct Iterator\n"
01160     "{\n"
01161     "   /* Transformed vertex position */\n"
01162     "   float4 position : POSITION;\n"
01163     "   \n"
01164     "   /* Texture coordinate */\n"
01165     "   float2 uv : TEXCOORD0;\n"
01166     "};\n"
01167     "\n"
01168     "/* Uniforms ******************************************************************/\n"
01169     "\n"
01170     "sampler2D Sampler;\n"
01171     "const float4 Kernel[NUM_TAPS];\n"
01172     "\n"
01173     "/* Code **********************************************************************/\n"
01174     "\n"
01175     "float4 main( const Iterator iterator ) : COLOR0\n"
01176     "{\n"
01177     "   float4 result = 0;\n"
01178     "   for ( int i = 0; i < NUM_TAPS; ++i )\n"
01179     "   {\n"
01180     "       result += Kernel[i].w * tex2D( Sampler, iterator.uv + Kernel[i].xy );\n"
01181     "   }\n"
01182     "\n"
01183     "   return result;\n"
01184     "} \n"
01185     "\n"
01186 ; 
01187 
01188 
01189 char CONST * dx9_post_filter_8 =
01190     "// Copyright (c) 2007 by Tech Soft 3D, LLC.\n"
01191     "// all rights reserved\n"
01192     "// $Id: dx9hlsl_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $\n"
01193     " \n"
01194     "// Specialise filter shader for N taps\n"
01195     "#define NUM_TAPS 8\n"
01196     "\n"
01197     "// Copyright (c) 2007 by Tech Soft 3D, LLC.\n"
01198     "// all rights reserved\n"
01199     "// $Id: dx9hlsl_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $\n"
01200     " \n"
01201     "#ifndef NUM_TAPS\n"
01202     "#error NUM_TAPS must be defined to use this shader!\n"
01203     "#endif // NUM_TAPS\n"
01204     " \n"
01205     "/* IO Types ******************************************************************/\n"
01206     "\n"
01207     "/* \n"
01208     " * ITERATOR\n"
01209     " * Input from triangle setup \n"
01210     " */\n"
01211     "struct Iterator\n"
01212     "{\n"
01213     "   /* Transformed vertex position */\n"
01214     "   float4 position : POSITION;\n"
01215     "   \n"
01216     "   /* Texture coordinate */\n"
01217     "   float2 uv : TEXCOORD0;\n"
01218     "};\n"
01219     "\n"
01220     "/* Uniforms ******************************************************************/\n"
01221     "\n"
01222     "sampler2D Sampler;\n"
01223     "const float4 Kernel[NUM_TAPS];\n"
01224     "\n"
01225     "/* Code **********************************************************************/\n"
01226     "\n"
01227     "float4 main( const Iterator iterator ) : COLOR0\n"
01228     "{\n"
01229     "   float4 result = 0;\n"
01230     "   for ( int i = 0; i < NUM_TAPS; ++i )\n"
01231     "   {\n"
01232     "       result += Kernel[i].w * tex2D( Sampler, iterator.uv + Kernel[i].xy );\n"
01233     "   }\n"
01234     "\n"
01235     "   return result;\n"
01236     "} \n"
01237     "\n"
01238 ; 
01239 
01240 
01241 char CONST * dx9_post_vertex =
01242     "// Copyright (c) 2007 by Tech Soft 3D, LLC.\n"
01243     "// all rights reserved\n"
01244     "// $Id: dx9hlsl_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $\n"
01245     " \n"
01246     "/* IO Types ******************************************************************/\n"
01247     "\n"
01248     "/* \n"
01249     " * VERTEX\n"
01250     " * Input from vertex buffer \n"
01251     " */\n"
01252     "struct Vertex\n"
01253     "{\n"
01254     "   /* Vertex position */\n"
01255     "   float3 position : POSITION;\n"
01256     "};\n"
01257     "\n"
01258     "\n"
01259     "/* \n"
01260     " * ITERATOR\n"
01261     " * Output to triangle setup \n"
01262     " */\n"
01263     "struct Iterator\n"
01264     "{\n"
01265     "   /* Transformed vertex position */\n"
01266     "   float4 position : POSITION;\n"
01267     "   \n"
01268     "   /* Texture coordinate */\n"
01269     "   float4 screen_uv : TEXCOORD0;\n"
01270     "};\n"
01271     "\n"
01272     "/* Uniforms ******************************************************************/\n"
01273     "\n"
01274     "/* Depth value */\n"
01275     "float ConstantDepth;\n"
01276     "\n"
01277     "/* 2D offset to centre pixels on texels correctly */\n"
01278     "float2 TexelOffset;\n"
01279     "\n"
01280     "/* Code **********************************************************************/\n"
01281     "\n"
01282     "Iterator main( const Vertex vertex )\n"
01283     "{\n"
01284     "   Iterator result;\n"
01285     "\n"
01286     "   // Assemble position with fixed depth and no perspective divide.\n"
01287     "   float4 position = float4(vertex.position.xy,ConstantDepth,1);\n"
01288     "   result.position = position;\n"
01289     "   \n"
01290     "    // Map NDC space into unit square UV space\n"
01291     "   result.screen_uv = position * 0.5f + 0.5f;\n"
01292     "   result.screen_uv.xy += TexelOffset;\n"
01293     "    \n"
01294     "   // Done\n"
01295     "   return result;\n"
01296     "} \n"
01297     "\n"
01298 ; 
01299 
01300 
01301 char CONST * dx9_post_vertex_3d =
01302     "// Copyright (c) 2007 by Tech Soft 3D, LLC.\n"
01303     "// all rights reserved\n"
01304     "// $Id: dx9hlsl_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $\n"
01305     " \n"
01306     "/* IO Types ******************************************************************/\n"
01307     "\n"
01308     "/* \n"
01309     " * VERTEX\n"
01310     " * Input from vertex buffer \n"
01311     " */\n"
01312     "struct Vertex\n"
01313     "{\n"
01314     "   /* Vertex position */\n"
01315     "   float3 position : POSITION;\n"
01316     "};\n"
01317     "\n"
01318     "\n"
01319     "/* \n"
01320     " * ITERATOR\n"
01321     " * Output to triangle setup \n"
01322     " */\n"
01323     "struct Iterator\n"
01324     "{\n"
01325     "   /* Transformed vertex position */\n"
01326     "   float4 position : POSITION;\n"
01327     "   \n"
01328     "   /* Texture coordinate */\n"
01329     "   float4 screen_uv : TEXCOORD0;\n"
01330     "   \n"
01331     "   /* Texture coordinate */\n"
01332     "   float2 world_uv : TEXCOORD1;\n"
01333     "};\n"
01334     "\n"
01335     "/* Uniforms ******************************************************************/\n"
01336     "\n"
01337     "/* Depth value */\n"
01338     "float ConstantDepth;\n"
01339     "float4x4 ModelToProjection;\n"
01340     "\n"
01341     "/* Code **********************************************************************/\n"
01342     "\n"
01343     "Iterator main( const Vertex vertex )\n"
01344     "{\n"
01345     "   Iterator result;\n"
01346     "\n"
01347     "   // Assemble and transform position\n"
01348     "   float4 position = mul(float4(vertex.position.xy,0,1), ModelToProjection);\n"
01349     "   \n"
01350     "   // Output a position at a fixed depth, working around perspective divide\n"
01351     "   result.position = float4(position.xy, ConstantDepth * position.w, position.w);\n"
01352     "       \n"
01353     "    // Map NDC space into unit square UV space\n"
01354     "   result.screen_uv = position;\n"
01355     "   result.world_uv = vertex.position.xy;\n"
01356     "    \n"
01357     "   // Done\n"
01358     "   return result;\n"
01359     "} \n"
01360     "\n"
01361 ; 
01362 
01363 
01364 char CONST * dx9_vertex =
01365     "// Copyright (c) 2007 by Tech Soft 3D, LLC.\n"
01366     "// all rights reserved\n"
01367     "// $Id: dx9hlsl_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $\n"
01368     " \n"
01369     "/* IO Types ******************************************************************/\n"
01370     "\n"
01371     "/* \n"
01372     " * VERTEX\n"
01373     " * Input from vertex buffer \n"
01374     " */\n"
01375     "#ifndef CREATE_SHADOW_MAP\n"
01376     "struct Vertex\n"
01377     "{\n"
01378     "   /* Vertex position */\n"
01379     "   float3 position : POSITION;\n"
01380     "\n"
01381     "   #ifdef HAS_VERTEX_NORMALS\n"
01382     "       /* Vertex normal (in object space) for lighting */\n"
01383     "       float3 normal : NORMAL;\n"
01384     "   #endif\n"
01385     "   #ifdef WIDE_LINE\n"
01386     "       /* expected to be mutually exclusive with textures or normals */\n"
01387     "       float3 end : NORMAL;\n"
01388     "       #ifdef MITERED_LINE\n"
01389     "           float3 previous : TEXCOORD0;    /* Start of previous line */\n"
01390     "           /* Offset constants\n"
01391     "            *   x displaces along line\n"
01392     "            *   y displaces perpendicular to line\n"
01393     "            *   z id's between the vertices used to start vs end a span */\n"
01394     "           float4 miter_offset : TEXCOORD1;\n"
01395     "       #else\n"
01396     "           float3 offset : TEXCOORD0;\n"
01397     "       #endif\n"
01398     "\n"
01399     "       #if defined(ROUND_LINE) || defined(ANTI_ALIASED_LINE)\n"
01400     "           float2 uv : TEXCOORD0;\n"
01401     "       #endif\n"
01402     "   #endif\n"
01403     "\n"
01404     "   #ifdef HAS_VERTEX_COLORS\n"
01405     "       /* Diffuse color from the material */\n"
01406     "       float4 color : COLOR0;\n"
01407     "   #endif\n"
01408     "   \n"
01409     "   #ifdef HAS_AMBIENT_OCCLUSION\n"
01410     "       /* AO term in specular.a */\n"
01411     "       float4 ambient_occlusion : COLOR1;\n"
01412     "   #endif \n"
01413     "       \n"
01414     "   #ifdef HAS_LINE_PATTERN\n"
01415     "       float2 uvlp : LINE_PATTERN_COORD;\n"
01416     "   #endif\n"
01417     "\n"
01418     "   #if (TEXTURE_COUNT > 0)\n"
01419     "       /* Texture coordinates */\n"
01420     "       float2 uv0 : DIFFUSE_TEXTURE_COORD0;\n"
01421     "   #endif\n"
01422     "\n"
01423     "   #if (TEXTURE_COUNT > 1) \n"
01424     "       float2 uv1 : DIFFUSE_TEXTURE_COORD1;\n"
01425     "   #endif\n"
01426     "   #if (TEXTURE_COUNT > 2) \n"
01427     "       float2 uv2 : DIFFUSE_TEXTURE_COORD2;\n"
01428     "   #endif\n"
01429     "   #if (TEXTURE_COUNT > 3) \n"
01430     "       float2 uv3 : DIFFUSE_TEXTURE_COORD3;\n"
01431     "   #endif\n"
01432     "   #if (TEXTURE_COUNT > 4) \n"
01433     "       float2 uv4 : DIFFUSE_TEXTURE_COORD4;\n"
01434     "   #endif\n"
01435     "   #if (TEXTURE_COUNT > 5) \n"
01436     "       float2 uv5 : DIFFUSE_TEXTURE_COORD5;\n"
01437     "   #endif\n"
01438     "   #if (TEXTURE_COUNT > 6) \n"
01439     "       float2 uv6 : DIFFUSE_TEXTURE_COORD6;\n"
01440     "   #endif\n"
01441     "   #if (TEXTURE_COUNT > 7) \n"
01442     "       float2 uv7 : DIFFUSE_TEXTURE_COORD7;\n"
01443     "   #endif\n"
01444     "\n"
01445     "   #ifdef SPECULAR_TEXTURE\n"
01446     "       float2 uvspec : SPECULAR_TEXTURE;\n"
01447     "   #endif\n"
01448     "};\n"
01449     "#else /* CREATE_SHADOW_MAP */\n"
01450     "struct Vertex\n"
01451     "{\n"
01452     "   /* Vertex position */\n"
01453     "   float3 position : POSITION;\n"
01454     "};\n"
01455     "#endif\n"
01456     "\n"
01457     "/* shadow map */\n"
01458     "struct shadow_map_t\n"
01459     "{\n"
01460     "   float4x4 transform;\n"
01461     "#ifdef SHADOW_MAP_DISTORTION\n"
01462     "   float4 distortion;\n"
01463     "#endif // SHADOW_MAP_DISTORTION\n"
01464     "};\n"
01465     "\n"
01466     "/* Atmospheric Attenuation */\n"
01467     "struct atmospheric_attenuation_t\n"
01468     "{\n"
01469     "   float hither;\n"
01470     "   float yon;\n"
01471     "};\n"
01472     "\n"
01473     "/* Reflection plane */\n"
01474     "struct reflection_plane_t\n"
01475     "{\n"
01476     "   float4 plane;\n"
01477     "   float scale; // Convert depth to attenuation\n"
01478     "   float bias;\n"
01479     "};\n"
01480     "\n"
01481     "/* Uniforms ******************************************************************/\n"
01482     "\n"
01483     "/* Transformations */\n"
01484     "#ifdef DC\n"
01485     "   float4x4 WorldViewProj;\n"
01486     "#else\n"
01487     "   float4x4 Projection;\n"
01488     "   float4x4 ModelView;\n"
01489     "   float4x4 Model;\n"
01490     "   float3x3 NormalizedModelView3x3;\n"
01491     "\n"
01492     "   #if (TEXTURE_COUNT > 0)\n"
01493     "       float4x4 TextureMatrix0;\n"
01494     "   #endif\n"
01495     "   #if (TEXTURE_COUNT > 1)\n"
01496     "       float4x4 TextureMatrix1;\n"
01497     "   #endif\n"
01498     "   #if (TEXTURE_COUNT > 2)\n"
01499     "       float4x4 TextureMatrix2;\n"
01500     "   #endif\n"
01501     "   #if (TEXTURE_COUNT > 3)\n"
01502     "       float4x4 TextureMatrix3;\n"
01503     "   #endif\n"
01504     "   #if (TEXTURE_COUNT > 4)\n"
01505     "       float4x4 TextureMatrix4;\n"
01506     "   #endif\n"
01507     "   #if (TEXTURE_COUNT > 5)\n"
01508     "       float4x4 TextureMatrix5;\n"
01509     "   #endif\n"
01510     "   #if (TEXTURE_COUNT > 6)\n"
01511     "       float4x4 TextureMatrix6;\n"
01512     "   #endif\n"
01513     "   #if (TEXTURE_COUNT > 7)\n"
01514     "       float4x4 TextureMatrix7;\n"
01515     "   #endif\n"
01516     "#endif\n"
01517     "float FaceDisplacement;\n"
01518     "float GeneralDisplacement;\n"
01519     "\n"
01520     "float3 CameraPosition;     //camera position in object space\n"
01521     "\n"
01522     "#ifdef WIDE_LINE\n"
01523     "   float WindowWidth;\n"
01524     "   float WindowHeight;\n"
01525     "#endif\n"
01526     "\n"
01527     "#ifdef HAS_FACE_PATTERN\n"
01528     "   float ScaledWindowWidth;\n"
01529     "   float ScaledWindowHeight;\n"
01530     "#endif\n"
01531     "\n"
01532     "#ifdef WIDE_LINE\n"
01533     "   #define LINE_TOOLS_SIZE 256.0\n"
01534     "   float LineWeight;       \n"
01535     "   float CircleSubImageStart;\n"
01536     "\n"
01537     "   #ifdef MITERED_LINE\n"
01538     "   float CosJoinCutoffAngle;\n"
01539     "   #endif\n"
01540     "#endif\n"
01541     "\n"
01542     "#ifndef PER_PIXEL_LIGHTING\n"
01543     "\n"
01544     "/* Normal ambient lighting */\n"
01545     "float3 AmbientLight;\n"
01546     "\n"
01547     "/* Distant lighting */\n"
01548     "distant_light_t DistantLights[DISTANT_LIGHT_COUNT+1];\n"
01549     "\n"
01550     "/* Point lights */\n"
01551     "point_light_t PointLights[POINT_LIGHT_COUNT+1];\n"
01552     "\n"
01553     "/* Spot lights */\n"
01554     "spot_light_t SpotLights[SPOT_LIGHT_COUNT+1];\n"
01555     "\n"
01556     "#endif // ndef PER_PIXEL_LIGHTING\n"
01557     "\n"
01558     "/* Shadow maps */\n"
01559     "shadow_map_t ShadowMaps[SHADOW_MAP_COUNT+1];\n"
01560     "\n"
01561     "#ifdef SHADOW_MAP_DISTORTION\n"
01562     "#ifdef CREATE_SHADOW_MAP\n"
01563     "/* Shadow distortion when rendering depth image */\n"
01564     "float4 ShadowDistortion;\n"
01565     "#endif // CREATE_SHADOW_MAP\n"
01566     "#endif // SHADOW_MAP_DISTORTION\n"
01567     "\n"
01568     "/* Material properties */\n"
01569     "material_props_t MaterialProperties;\n"
01570     "\n"
01571     "/* Cutting planes */\n"
01572     "float4 CuttingPlanes[CUTTING_PLANE_COUNT+1];\n"
01573     "\n"
01574     "/* Atmospheric attenuation */\n"
01575     "atmospheric_attenuation_t AtmosphericAttenuation;\n"
01576     "\n"
01577     "/* Colormap Size */\n"
01578     "int ColormapSize;\n"
01579     "\n"
01580     "/* And for shadow jitter table */\n"
01581     "float4 JitterScaleAndBias;\n"
01582     "\n"
01583     "/* Reflection plane data */\n"
01584     "reflection_plane_t ReflectionPlane;\n"
01585     "\n"
01586     "/* Code **********************************************************************/\n"
01587     "\n"
01588     "#ifdef SHADOW_MAP_DISTORTION\n"
01589     "\n"
01590     "//\n"
01591     "// Use logarithmic distortion to concentrate shadow texels around the viewer.\n"
01592     "// Rescale projected texture coordinates or position for shadowing around the\n"
01593     "// projection of the viewer onto the shadow map plane.\n"
01594     "//\n"
01595     "float4 distort_shadowmap_position( float4 position, uniform float4 distortion )\n"
01596     "{\n"
01597     "   // Where is the shadowed point relative to the viewer's projection on the shadow plane?\n"
01598     "   float2 delta = position.xy - distortion.xy;\n"
01599     "   \n"
01600     "   // Calculate undistorted distance from viewer position at the texture\n"
01601     "   float t = length(delta);\n"
01602     "   \n"
01603     "   #ifndef CREATE_SHADOW_MAP\n"
01604     "       // If we're creating a shadow map, these coordinates will be in \n"
01605     "       // NDC space. If not, they'll be in UV space and we need to double\n"
01606     "       // the scale to get the same distortion.\n"
01607     "       t *= 2.0f;\n"
01608     "   #endif // CREATE_SHADOW_MAP\n"
01609     "   \n"
01610     "   // If this point is inside the distortion circle...\n"
01611     "   if ( t < 1 )\n"
01612     "   {\n"
01613     "       // Compute log(kt + 1) distortion factor, normalise log s.t. t = 1 -> no distortion.\n"
01614     "       // Dividing by t turns delta into a unit vector suitable for rescaling.\n"
01615     "       float t_dash = distortion.w * log( distortion.z * t + 1) / t; \n"
01616     "\n"
01617     "       // Remap using distorted distance.\n"
01618     "       position.xy = distortion.xy + delta * t_dash;\n"
01619     "   }\n"
01620     "   \n"
01621     "   // Otherwise leave the point along - gives slightly better texel density on\n"
01622     "   // distant texels\n"
01623     "   \n"
01624     "   // Done\n"
01625     "   return position;\n"
01626     "}\n"
01627     "\n"
01628     "#endif // SHADOW_MAP_DISTORTION\n"
01629     "\n"
01630     "#ifndef CREATE_SHADOW_MAP\n"
01631     "#ifdef HAS_VERTEX_NORMALS\n"
01632     "float3 reflect_physical(const Vertex vertex)\n"
01633     "{\n"
01634     "   float3 N = vertex.normal;\n"
01635     "   float3 I = normalize(vertex.position - CameraPosition);\n"
01636     "   float3 ray = I - N * 2 * dot(N,I);\n"
01637     "\n"
01638     "   /* map to sphere */\n"
01639     "   ray.z = 1-ray.z;\n"
01640     "   float tmp = length(ray);\n"
01641     "   if(tmp < 0.000001)\n"
01642     "       tmp = 0.000001;\n"
01643     "   tmp = 0.5 / tmp;\n"
01644     "\n"
01645     "   return ray * tmp + 0.5;\n"
01646     "}\n"
01647     "\n"
01648     "float3 reflect(float3 eye_normal, float3 eye_position)\n"
01649     "{\n"
01650     "   float3 N = normalize(eye_normal);\n"
01651     "   float3 I = float3(0,0,1);\n"
01652     "   float3 ray = I - N * 2 * dot(N,I);\n"
01653     "\n"
01654     "   /* map to sphere */\n"
01655     "   ray.z = 1-ray.z;\n"
01656     "   float tmp = length(ray);\n"
01657     "   if(tmp < 0.000001)\n"
01658     "       tmp = 0.000001;\n"
01659     "   tmp = 0.5 / tmp;\n"
01660     "\n"
01661     "   return ray * tmp + 0.5;\n"
01662     "}\n"
01663     "#endif\n"
01664     "#endif\n"
01665     "\n"
01666     "\n"
01667     "Iterator main( const Vertex vertex )\n"
01668     "{\n"
01669     "   int i;\n"
01670     "   Iterator result;\n"
01671     "\n"
01672     "#ifndef CREATE_SHADOW_MAP\n"
01673     "   result.specular_color = float4(0,0,0,1);\n"
01674     "   result.diffuse_color = MaterialProperties.diffuse;\n"
01675     "#endif // CREATE_SHADOW_MAP\n"
01676     "   \n"
01677     "#ifdef DC  \n"
01678     "   float3 position = vertex.position;\n"
01679     "   #ifdef WIDE_LINE\n"
01680     "       #ifdef MITERED_LINE\n"
01681     "           //calculate vectors pointing away from start point of line\n"
01682     "           float2 prev_path = normalize( float2(vertex.previous.xy - position.xy) );\n"
01683     "           float2 path = normalize( float2(vertex.end.xy - position.xy) );\n"
01684     "\n"
01685     "           //keep cos_angle from actually hitting 1, since that would cause divide by 0\n"
01686     "           float cos_angle = dot(prev_path, path) * 0.999f;\n"
01687     "           //sin is z component of cross product\n"
01688     "           float sin_angle = prev_path.x*path.y - prev_path.y*path.x;\n"
01689     "           float tan_half = sqrt( (1+cos_angle) / (1-cos_angle) );\n"
01690     "           float adjust = tan_half;\n"
01691     "           \n"
01692     "           //check against the miter limit\n"
01693     "           if (cos_angle >= CosJoinCutoffAngle)\n"
01694     "               adjust = 0;\n"
01695     "               \n"
01696     "           float3 miter_offset = vertex.miter_offset;\n"
01697     "           //Scale the offsets up to the given line weight\n"
01698     "           if (miter_offset.z > 0)\n"
01699     "               path = -prev_path * LineWeight/2;\n"
01700     "           else\n"
01701     "               path *= LineWeight/2;\n"
01702     "           \n"
01703     "           // Offset horizontally (away from line axis)\n"
01704     "           position.xy += miter_offset.x * float2( -path.y, path.x );\n"
01705     "           \n"
01706     "           //clockwise bends rotate seam between line segments clockwise,\n"
01707     "           //but counterclockwise bends rotate seam counterclockwise\n"
01708     "           if (sin_angle > 0)\n"
01709     "               miter_offset.y *= -1;\n"
01710     "           \n"
01711     "           // Offset vertically (along line axis, for caps/joints)\n"
01712     "           position.xy += miter_offset.y * adjust * -path;\n"
01713     "       #else   \n"
01714     "           // Point along the line\n"
01715     "           float2 path = normalize( float2(vertex.end.xy - vertex.position.xy) );\n"
01716     "           // Scale up\n"
01717     "           path *= LineWeight/2;\n"
01718     "           path *= 1 - vertex.offset.z;\n"
01719     "           position.x = floor(position.x) + 0.5;\n"
01720     "           position.y = floor(position.y) + 0.5;\n"
01721     "\n"
01722     "           // Offset horizontally (away from line axis)\n"
01723     "           position.xy += vertex.offset.x * float2( -path.y, path.x );\n"
01724     "           // Offset vertically (along line axis, for caps/joints)\n"
01725     "           position.xy += vertex.offset.y * path;\n"
01726     "           \n"
01727     "       #endif\n"
01728     "\n"
01729     "       #if defined(ROUND_LINE) || defined(ANTI_ALIASED_LINE)   \n"
01730     "           // Compress [-1, 1] into [0, 1]\n"
01731     "           // First offset (x) defines V coordinate for line\n"
01732     "           // Second offset (y) defines U coordinate - 0.5 except at endcaps\n"
01733     "           result.uv0 = vertex.uv.xy * 0.5f + 0.5f;\n"
01734     "           // Compress [0,1] into circle's subimage\n"
01735     "           result.uv0.x *= (LineWeight)/LINE_TOOLS_SIZE;\n"
01736     "           result.uv0.y *= (LineWeight-1)/LINE_TOOLS_SIZE;\n"
01737     "           result.uv0.x += CircleSubImageStart;\n"
01738     "           result.uv0.y += 0.5/LINE_TOOLS_SIZE;\n"
01739     "       #endif\n"
01740     "   #endif\n"
01741     "\n"
01742     "   // DC projections are trivial\n"
01743     "    result.position = mul(float4(position, 1), WorldViewProj);\n"
01744     "#else\n"
01745     "   //\n"
01746     "   // Transformation\n"
01747     "   // ====================================================================\n"
01748     "\n"
01749     "   // Transform point to eye space\n"
01750     "   float4 eye_position = mul( float4(vertex.position,1), ModelView);\n"
01751     "   \n"
01752     "   // Transform point to screen space (TODO: One transform not two, if the\n"
01753     "   // world position is not needed for lighting)\n"
01754     "   result.position = mul( eye_position, Projection );\n"
01755     "   \n"
01756     "#ifndef CREATE_SHADOW_MAP\n"
01757     "   \n"
01758     "   #ifdef HAS_VERTEX_NORMALS\n"
01759     "       // Transform normal to eye space\n"
01760     "       //float3 eye_normal = mul( vertex.normal, (float3x3)ModelView );\n"
01761     "       float3 eye_normal = mul( vertex.normal, NormalizedModelView3x3);\n"
01762     "       #ifdef HAS_NON_UNIFORM_SCALE\n"
01763     "           eye_normal = normalize(eye_normal);\n"
01764     "       #endif\n"
01765     "       \n"
01766     "       #ifdef HAS_LIGHTING\n"
01767     "       \n"
01768     "           #ifdef PER_PIXEL_LIGHTING\n"
01769     "           \n"
01770     "               // Send normal and eye position through to PS\n"
01771     "               result.specular_color.xyz = eye_normal * 0.5f + 0.5f;\n"
01772     "               \n"
01773     "               #if (POINT_LIGHT_COUNT > 0) || (SPOT_LIGHT_COUNT > 0)\n"
01774     "                   result.eye_position = eye_position;\n"
01775     "               #endif // POINT_LIGHT_COUNT > 0 || SPOT_LIGHT_COUNT > 0\n"
01776     "\n"
01777     "               // Ensure we have vertex color\n"
01778     "               #ifdef HAS_VERTEX_COLORS\n"
01779     "                   result.diffuse_color = vertex.color;\n"
01780     "               #endif\n"
01781     "               \n"
01782     "           #endif // PER_PIXEL_LIGHTING\n"
01783     "\n"
01784     "           // temporarily flip all normals to face the camera\n"
01785     "           #ifdef HAS_HANDEDNESS\n"
01786     "               #ifdef RIGHT_HANDED_MATRIX\n"
01787     "                   eye_normal = -eye_normal;\n"
01788     "               #endif\n"
01789     "           #else\n"
01790     "               if(eye_normal.z > 0)\n"
01791     "                   eye_normal = -eye_normal;\n"
01792     "           #endif\n"
01793     "\n"
01794     "           #ifndef PER_PIXEL_LIGHTING  \n"
01795     "           \n"
01796     "               //\n"
01797     "               // Lighting\n"
01798     "               // ====================================================================\n"
01799     "               \n"
01800     "               float3 diffuse, specular;\n"
01801     "               compute_lighting( eye_normal, eye_position, diffuse, specular, \n"
01802     "                                 MaterialProperties, AmbientLight, DistantLights, PointLights, SpotLights );\n"
01803     "               \n"
01804     "               #ifdef HAS_AMBIENT_OCCLUSION\n"
01805     "                   diffuse *= vertex.ambient_occlusion.a;\n"
01806     "                   specular *= vertex.ambient_occlusion.a;\n"
01807     "               #endif\n"
01808     "\n"
01809     "               // Combine with vertex color\n"
01810     "               #ifdef HAS_VERTEX_COLORS\n"
01811     "                   diffuse *= vertex.color;\n"
01812     "               #endif\n"
01813     "\n"
01814     "               // Output lighting colors       \n"
01815     "               result.diffuse_color = float4(diffuse,MaterialProperties.diffuse.a);\n"
01816     "               result.specular_color = float4(specular,1);\n"
01817     "       \n"
01818     "           #endif // ndef PER_PIXEL_LIGHTING\n"
01819     "       #endif // HAS_LIGHTING\n"
01820     "   \n"
01821     "   #endif // HAS_VERTEX_NORMALS\n"
01822     "\n"
01823     "#endif // ndef CREATE_SHADOW_MAP\n"
01824     "\n"
01825     "#endif // ndef DC\n"
01826     "\n"
01827     "#ifndef CREATE_SHADOW_MAP\n"
01828     "\n"
01829     "#ifndef HAS_LIGHTING\n"
01830     "   //if no vertex lighting (i.e. unlit), just copy the color\n"
01831     "   #ifdef HAS_VERTEX_COLORS\n"
01832     "       result.diffuse_color = vertex.color;\n"
01833     "   #else\n"
01834     "       result.diffuse_color = MaterialProperties.diffuse;\n"
01835     "   #endif\n"
01836     "#endif\n"
01837     "   \n"
01838     "#if (TEXTURE_COUNT > 0)\n"
01839     "   //\n"
01840     "   // Texturing\n"
01841     "   // ====================================================================\n"
01842     "   \n"
01843     "   #ifndef DC\n"
01844     "       // calculate the world position in case this or any of the subsequent stages need it\n"
01845     "       float4 world_position = mul(float4(vertex.position,1), Model);\n"
01846     "       #ifdef TEXTURE0_WORLD\n"
01847     "           result.uv0 = world_position;\n"
01848     "       #else\n"
01849     "           result.uv0 = vertex.uv0;\n"
01850     "       #endif\n"
01851     "       result.uv0 = mul(float4(result.uv0, 0, 1), TextureMatrix0);\n"
01852     "   #else\n"
01853     "       result.uv0 = float4(vertex.uv0, 0, 1);\n"
01854     "   #endif\n"
01855     "\n"
01856     "   #ifdef HAS_VERTEX_FINDICES\n"
01857     "       float colormap_shift = 0.5/ColormapSize;\n"
01858     "       result.uv0.x = result.uv0.x / ColormapSize + colormap_shift;\n"
01859     "   #endif\n"
01860     "#endif\n"
01861     "\n"
01862     "#if (TEXTURE_COUNT > 1) \n"
01863     "   #ifndef DC\n"
01864     "       #ifdef TEXTURE1_WORLD\n"
01865     "           result.uv1 = world_position;\n"
01866     "       #else\n"
01867     "           result.uv1 = vertex.uv1;\n"
01868     "       #endif\n"
01869     "       result.uv1 = mul(float4(result.uv1, 0, 1), TextureMatrix1);\n"
01870     "   #else\n"
01871     "       result.uv1 = float4(vertex.uv1, 0, 1);\n"
01872     "   #endif  \n"
01873     "#endif\n"
01874     "\n"
01875     "#if (TEXTURE_COUNT > 2) \n"
01876     "   #ifndef DC\n"
01877     "       #ifdef TEXTURE2_WORLD\n"
01878     "           result.uv2 = world_position;\n"
01879     "       #else\n"
01880     "           result.uv2 = vertex.uv2;\n"
01881     "       #endif\n"
01882     "       result.uv2 = mul(float4(result.uv2, 0, 1), TextureMatrix2);\n"
01883     "   #else\n"
01884     "       result.uv2 = float4(vertex.uv2, 0, 1);\n"
01885     "   #endif  \n"
01886     "#endif\n"
01887     "\n"
01888     "#if (TEXTURE_COUNT > 3) \n"
01889     "   #ifndef DC\n"
01890     "       #ifdef TEXTURE3_WORLD\n"
01891     "           result.uv3 = world_position;\n"
01892     "       #else\n"
01893     "           result.uv3 = vertex.uv3;\n"
01894     "       #endif\n"
01895     "       result.uv3 = mul(float4(result.uv3, 0, 1), TextureMatrix3);\n"
01896     "   #else\n"
01897     "       result.uv3 = float4(vertex.uv3, 0, 1);\n"
01898     "   #endif  \n"
01899     "#endif\n"
01900     "#if (TEXTURE_COUNT > 4) \n"
01901     "   #ifndef DC\n"
01902     "       #ifdef TEXTURE4_WORLD\n"
01903     "           result.uv4 = world_position;\n"
01904     "       #else\n"
01905     "           result.uv4 = vertex.uv4;\n"
01906     "       #endif\n"
01907     "       result.uv4 = mul(float4(result.uv4, 0, 1), TextureMatrix4);\n"
01908     "   #else\n"
01909     "       result.uv4 = float4(vertex.uv4, 0, 1);\n"
01910     "   #endif  \n"
01911     "#endif\n"
01912     "#if (TEXTURE_COUNT > 5) \n"
01913     "   #ifndef DC\n"
01914     "       #ifdef TEXTURE5_WORLD\n"
01915     "           result.uv5 = world_position;\n"
01916     "       #else\n"
01917     "           result.uv5 = vertex.uv5;\n"
01918     "       #endif\n"
01919     "       result.uv5 = mul(float5(result.uv5, 0, 1), TextureMatrix5);\n"
01920     "   #else\n"
01921     "       result.uv5 = float5(vertex.uv5, 0, 1);\n"
01922     "   #endif  \n"
01923     "#endif\n"
01924     "#if (TEXTURE_COUNT > 6) \n"
01925     "   #ifndef DC\n"
01926     "       #ifdef TEXTURE6_WORLD\n"
01927     "           result.uv6 = world_position;\n"
01928     "       #else\n"
01929     "           result.uv6 = vertex.uv6;\n"
01930     "       #endif\n"
01931     "       result.uv6 = mul(float4(result.uv6, 0, 1), TextureMatrix6);\n"
01932     "   #else\n"
01933     "       result.uv6 = float4(vertex.uv6, 0, 1);\n"
01934     "   #endif  \n"
01935     "#endif\n"
01936     "#if (TEXTURE_COUNT > 7) \n"
01937     "   #ifndef DC\n"
01938     "       #ifdef TEXTURE7_WORLD\n"
01939     "           result.uv7 = world_position;\n"
01940     "       #else\n"
01941     "           result.uv7 = vertex.uv7;\n"
01942     "       #endif\n"
01943     "       result.uv7 = mul(float4(result.uv7, 0, 1), TextureMatrix7);\n"
01944     "   #else\n"
01945     "       result.uv7 = float4(vertex.uv7, 0, 1);\n"
01946     "   #endif  \n"
01947     "#endif\n"
01948     "\n"
01949     "#ifdef HAS_FACE_PATTERN\n"
01950     "   result.uvzwfp.x = ScaledWindowWidth * result.position.x;\n"
01951     "   result.uvzwfp.y = -ScaledWindowHeight * result.position.y;\n"
01952     "   result.uvzwfp.z = 0;\n"
01953     "   result.uvzwfp.w = result.position.w;\n"
01954     "   #ifndef CAMERA_PERSPECTIVE\n"
01955     "       #ifdef HAS_TRANSPARENCY_STIPPLE\n"
01956     "           float texel_offset = 0.5/16;\n"
01957     "       #else\n"
01958     "           float texel_offset = 0.5/32;\n"
01959     "       #endif\n"
01960     "       result.uvzwfp.xy += texel_offset;\n"
01961     "   #endif\n"
01962     "#endif\n"
01963     "\n"
01964     "#ifdef HAS_LINE_PATTERN\n"
01965     "   result.uvlp.x = vertex.uvlp.x;\n"
01966     "   result.uvlp.y = vertex.uvlp.y;\n"
01967     "   result.uvlp.z = 0;\n"
01968     "   result.uvlp.w = 0;\n"
01969     "#endif\n"
01970     "\n"
01971     "#ifdef ENVIRONMENT_TEXTURE\n"
01972     "   #ifdef  HAS_PHYSICAL_REFLECTION\n"
01973     "       result.uvenv = reflect_physical(vertex);\n"
01974     "   #else\n"
01975     "       result.uvenv = reflect(eye_normal, eye_position);\n"
01976     "   #endif\n"
01977     "   result.uvenv.y = -result.uvenv.y;\n"
01978     "#endif\n"
01979     "#ifdef HAS_BUMP_TEXTURE\n"
01980     "   result.uv5 = vertex.uv5;\n"
01981     "   result.uv5.y = -result.uv5.y;\n"
01982     "#endif\n"
01983     "#ifdef SPECULAR_TEXTURE\n"
01984     "   result.uvspec = vertex.uvspec;\n"
01985     "   result.uvspec.y = -result.uvspec.y;\n"
01986     "#endif\n"
01987     "       \n"
01988     "#if (SHADOW_MAP_COUNT > 0)\n"
01989     "   result.uvsm0 = mul( float4(vertex.position,1), ShadowMaps[0].transform);\n"
01990     "#ifdef SHADOW_MAP_DISTORTION\n"
01991     "   result.uvsm0 = distort_shadowmap_position( result.uvsm0, ShadowMaps[0].distortion );\n"
01992     "#endif // SHADOW_MAP_DISTORTION\n"
01993     "#ifdef SHADOW_MAP_JITTER\n"
01994     "   result.screen_position = result.position;\n"
01995     "   // Map to viewport\n"
01996     "   result.screen_position.xy *= JitterScaleAndBias.xy;\n"
01997     "   result.screen_position.xy += JitterScaleAndBias.zw;\n"
01998     "#endif // SHADOW_MAP_JITTER\n"
01999     "#endif\n"
02000     "#if (SHADOW_MAP_COUNT > 1)\n"
02001     "   result.uvsm1 = mul( float4(vertex.position,1), ShadowMaps[1].transform);\n"
02002     "#ifdef SHADOW_MAP_DISTORTION\n"
02003     "   result.uvsm1 = distort_shadowmap_position( result.uvsm0, ShadowMaps[1].distortion );\n"
02004     "#endif // SHADOW_MAP_DISTORTION\n"
02005     "#endif\n"
02006     "#if (SHADOW_MAP_COUNT > 2)\n"
02007     "   result.uvsm2 = mul( float4(vertex.position,1), ShadowMaps[2].transform);\n"
02008     "#ifdef SHADOW_MAP_DISTORTION\n"
02009     "   result.uvsm2 = distort_shadowmap_position( result.uvsm0, ShadowMaps[2].distortion );\n"
02010     "#endif // SHADOW_MAP_DISTORTION\n"
02011     "#endif\n"
02012     "#if (SHADOW_MAP_COUNT > 3)\n"
02013     "   result.uvsm3 = mul( float4(vertex.position,1), ShadowMaps[3].transform);\n"
02014     "#ifdef SHADOW_MAP_DISTORTION\n"
02015     "   result.uvsm3 = distort_shadowmap_position( result.uvsm0, ShadowMaps[3].distortion );\n"
02016     "#endif // SHADOW_MAP_DISTORTION\n"
02017     "#endif\n"
02018     "\n"
02019     "#if (CUTTING_PLANE_COUNT > 0)\n"
02020     "   #ifdef DC\n"
02021     "       float4 cutting_position = float4(vertex.position,1);\n"
02022     "   #else\n"
02023     "       float4 cutting_position = eye_position;\n"
02024     "   #endif\n"
02025     "\n"
02026     "   result.uvcp0 = dot(cutting_position, CuttingPlanes[0]);\n"
02027     "#endif\n"
02028     "#if (CUTTING_PLANE_COUNT > 1)\n"
02029     "   result.uvcp0.y = dot(cutting_position, CuttingPlanes[1]);\n"
02030     "#endif\n"
02031     "#if (CUTTING_PLANE_COUNT > 2)\n"
02032     "   result.uvcp0.z = dot(cutting_position, CuttingPlanes[2]);\n"
02033     "#endif\n"
02034     "#if (CUTTING_PLANE_COUNT > 3)\n"
02035     "   result.uvcp0.w = dot(cutting_position, CuttingPlanes[3]);\n"
02036     "#endif\n"
02037     "#if (CUTTING_PLANE_COUNT > 4)\n"
02038     "   result.uvcp1 = dot(cutting_position, CuttingPlanes[4]);\n"
02039     "#endif\n"
02040     "#if (CUTTING_PLANE_COUNT > 5)\n"
02041     "   result.uvcp1.y = dot(cutting_position, CuttingPlanes[5]);\n"
02042     "#endif\n"
02043     "#if (CUTTING_PLANE_COUNT > 6)\n"
02044     "   result.uvcp1.z = dot(cutting_position, CuttingPlanes[6]);\n"
02045     "#endif\n"
02046     "#if (CUTTING_PLANE_COUNT > 7)\n"
02047     "   result.uvcp1.w = dot(cutting_position, CuttingPlanes[7]);\n"
02048     "#endif\n"
02049     "#if (CUTTING_PLANE_COUNT > 8)\n"
02050     "   result.uvcp2 = dot(cutting_position, CuttingPlanes[8]);\n"
02051     "#endif\n"
02052     "#if (CUTTING_PLANE_COUNT > 9)\n"
02053     "   result.uvcp2.y = dot(cutting_position, CuttingPlanes[9]);\n"
02054     "#endif\n"
02055     "#if (CUTTING_PLANE_COUNT > 10)\n"
02056     "   result.uvcp2.z = dot(cutting_position, CuttingPlanes[10]);\n"
02057     "#endif\n"
02058     "#if (CUTTING_PLANE_COUNT > 11)\n"
02059     "   result.uvcp2.w = dot(cutting_position, CuttingPlanes[11]);\n"
02060     "#endif\n"
02061     "#if (CUTTING_PLANE_COUNT > 12)\n"
02062     "   result.uvcp3 = dot(cutting_position, CuttingPlanes[12]);\n"
02063     "#endif\n"
02064     "#if (CUTTING_PLANE_COUNT > 13)\n"
02065     "   result.uvcp3.y = dot(cutting_position, CuttingPlanes[13]);\n"
02066     "#endif\n"
02067     "#if (CUTTING_PLANE_COUNT > 14)\n"
02068     "   result.uvcp3.z = dot(cutting_position, CuttingPlanes[14]);\n"
02069     "#endif\n"
02070     "// SIL: Only support up to 15 - need to make space in shader ID for one more to complete.\n"
02071     "\n"
02072     "#if defined(DEPTH_PEELING) || defined(DEPTH_WRITING)\n"
02073     "   // Copy position to iterator\n"
02074     "   result.peel_position = result.position;\n"
02075     "#endif\n"
02076     "\n"
02077     "\n"
02078     "#ifdef CREATE_REFLECTION_PLANE\n"
02079     "\n"
02080     "   // How far is the point from the reflection plane?\n"
02081     "   float plane_distance = dot(eye_position, ReflectionPlane.plane);\n"
02082     "\n"
02083     "   // Scale into suitable range\n"
02084     "   float reflection_strength = 1 - saturate( plane_distance * ReflectionPlane.scale + ReflectionPlane.bias );\n"
02085     "   result.diffuse_color.a *= reflection_strength * reflection_strength;\n"
02086     "   \n"
02087     "#endif\n"
02088     "\n"
02089     "#ifdef HAS_ATMOSPHERIC_ATTENUATION\n"
02090     "   float fog_z = abs(eye_position.z);\n"
02091     "   result.fog = (fog_z - AtmosphericAttenuation.yon) / (AtmosphericAttenuation.hither - AtmosphericAttenuation.yon);\n"
02092     "#endif\n"
02093     "\n"
02094     "#else // CREATE_SHADOW_MAP\n"
02095     "\n"
02096     "#ifdef SHADOW_MAP_DISTORTION\n"
02097     "   // Distort position\n"
02098     "   result.position = distort_shadowmap_position( result.position, ShadowDistortion );\n"
02099     "#endif // SHADOW_MAP_DISTORTION\n"
02100     "\n"
02101     "   // Output position to texcoords\n"
02102     "   result.shadow_position = result.position;\n"
02103     "\n"
02104     "#endif // ndef CREATE_SHADOW_MAP\n"
02105     "\n"
02106     "   // Done\n"
02107     "   return result;\n"
02108     "} \n"
02109     "\n"
02110 ; 
02111 
02112 
Main Index
HOOPS/3dGS I.M. Interface

     << Back      Full Index      Forward >>