1#include "core.h" 2 3 4#define FOG_G @shGlobalSettingBool(fog) 5#define FOG FOG_G && @shPropertyBool(fog_en) 6 7#define SHADOWS @shGlobalSettingBool(shadows_pssm) && @shPropertyBool(receives_shadows) 8#define SHADOWS_DEPTH @shGlobalSettingBool(shadows_depth) 9 10#define MRT @shPropertyBool(mrt_output) && @shGlobalSettingBool(mrt_output) 11 12#if SHADOWS 13#include "shadows.h" 14#endif 15 16#if FOG_G || (SHADOWS) || MRT 17#define NEED_DEPTH 18#endif 19 20#define ALPHA_MAP @shPropertyHasValue(alphaMap) 21#define NORMAL_MAP @shPropertyHasValue(normalMap) 22#define ENV_MAP @shPropertyBool(env_map) 23#define FRESNEL @shPropertyBool(fresnel) 24#define REFL_MAP @shPropertyHasValue(reflMap) 25#define SPEC_MAP @shPropertyHasValue(specMap) 26#define CAR_PAINT_MAP @shPropertyHasValue(carPaintMap) 27 28#define TERRAIN_LIGHT_MAP @shPropertyBool(terrain_light_map) 29#define TERRAIN_LIGHT_MAP_TOGGLEABLE @shPropertyBool(terrain_light_map_toggleable) 30#define MOTIONBLUR_MASK @shPropertyBool(motionblur_mask) 31 32#define INSTANCING @shPropertyBool(instancing) 33#define SOFT_PARTICLES (@shPropertyBool(soft_particles) && @shGlobalSettingBool(soft_particles)) 34#define SELECTED_GLOW @shGlobalSettingBool(editor) 35#define SPECULAR_ALPHA @shPropertyBool(specular_alpha) 36#define SPECMAP_RGB @shPropertyBool(specMap_rgb) 37 38#if (TERRAIN_LIGHT_MAP) || (ENV_MAP) || (SOFT_PARTICLES) || (FOG_G) 39#define NEED_WORLD_MATRIX 40#endif 41 42#define TREE_WIND @shPropertyBool(tree_wind) 43#define GRASS_WIND @shPropertyBool(grass_wind) 44#define VERTEX_COLOUR @shPropertyBool(vertex_colour) 45#define TWOSIDE_DIFFUSE @shPropertyBool(twoside_diffuse) 46#define ROAD_BLEND @shPropertyBool(road_blend) 47#define WATER_PARTICLES_LIT @shPropertyBool(water_particles_lit) 48 49 50#ifdef SH_VERTEX_SHADER 51 52 // VERTEX 53 //........................................................................................ 54 55 SH_BEGIN_PROGRAM 56 shUniform(float4x4, wvp) @shAutoConstant(wvp, worldviewproj_matrix) 57 shVertexInput(float2, uv0) 58 shOutput(float4, UV) 59 shNormalInput(float4) 60 61#if MRT 62 shUniform(float4x4, wvMat) @shAutoConstant(wvMat, worldview_matrix) 63 shUniform(float, far) @shAutoConstant(far, far_clip_distance) 64 shOutput(float4, viewNormal) 65#endif 66 67 68#if SOFT_PARTICLES 69 shOutput(float3, screenPosition) 70#endif 71 72#if VERTEX_COLOUR || ROAD_BLEND 73 shColourInput(float4) 74 shOutput(float4, vertexColour) 75#endif 76 77#if NORMAL_MAP 78 shTangentInput(float3) 79 shOutput(float3, tangentPassthrough) 80#endif 81 82#if TREE_WIND 83 84 shUniform(float, windTimer) @shSharedParameter(windTimer) 85 shVertexInput(float4, uv1) // windParams 86 shVertexInput(float4, uv2) // originPos 87#endif 88 89#if INSTANCING 90 shVertexInput(float4, uv1) 91 shVertexInput(float4, uv2) 92 shVertexInput(float4, uv3) 93 shUniform(float4x4, viewProjMatrix) @shAutoConstant(viewProjMatrix, viewproj_matrix) 94#endif 95 96#if GRASS_WIND 97 98 shUniform(float, grassTimer) @shSharedParameter(grassTimer) 99 shUniform(float, grassFrequency) @shSharedParameter(grassFrequency) 100 shUniform(float4, grassDirection) @shSharedParameter(grassDirection) 101 102 shUniform(float4x4, world) @shAutoConstant(world, world_matrix) 103 shUniform(float4, posSph0) @shSharedParameter(posSph0) // car grass colision spheres pos,r^2 104 shUniform(float4, posSph1) @shSharedParameter(posSph1) 105#endif 106 107 shOutput(float3, normalPassthrough) 108 shOutput(float4, objSpacePositionPassthrough) 109 110#if SHADOWS 111 @shForeach(3) 112 shOutput(float4, lightSpacePos@shIterator) 113 #if INSTANCING 114 shUniform(float4x4, texViewProjMatrix@shIterator) @shAutoConstant(texViewProjMatrix@shIterator, texture_viewproj_matrix, @shIterator) 115 #else 116 shUniform(float4x4, texWorldViewProjMatrix@shIterator) @shAutoConstant(texWorldViewProjMatrix@shIterator, texture_worldviewproj_matrix, @shIterator) 117 #endif 118 @shEndForeach 119#endif 120 121 122 //.............................................................................................................................. 123 124 SH_START_PROGRAM 125 { 126 127 float4 position = shInputPosition; 128 129#if INSTANCING 130 float4x4 worldMatrix; 131 worldMatrix[0] = uv1; 132 worldMatrix[1] = uv2; 133 worldMatrix[2] = uv3; 134 worldMatrix[3] = float4(0,0,0,1); 135 136 #if SH_GLSL 137 worldMatrix = transpose(worldMatrix); 138 #endif 139 140 141 float4 worldPos = shMatrixMult(worldMatrix, shInputPosition); 142 float3 worldNorm = shMatrixMult(worldMatrix, float4(normal.xyz, 0)).xyz; 143 normalPassthrough = worldNorm.xyz; 144#endif 145 146#if TREE_WIND 147 //float radiusCoeff = windParams.x; 148 //float heightCoeff = windParams.y; 149 //float factorX = windParams.z; 150 //float factorY = windParams.w; 151 152 position.y += sin(windTimer + uv2.z + position.y + position.x) * uv1.x * uv1.x * uv1.w; 153 position.x += sin(windTimer + uv2.z ) * uv1.y * uv1.y * uv1.z; 154#endif 155 156 157 // grass 158#if GRASS_WIND 159 float4 opos = shMatrixMult(world, position); 160 float oldposx = position.x; 161 if (uv0.y == 0.0f) 162 { 163 float offset = sin(grassTimer + oldposx * grassFrequency); 164 position += grassDirection * offset; 165 166 #if 1 167 ///() grass deform under car 168 // sphere: (x - x0)^2 + (y - y0)^2 + (z - z0)^2 = r^2 169 float r = posSph0.w; // sphere radius^2 170 if (r > 0.f) 171 { 172 float3 sph = posSph0.xyz; // sphere pos 173 float dx = opos.x - sph.x, dz = opos.z - sph.z; //, dy = opos.y - sph.y; 174 dx *= dx; dz *= dz; //dy *= dy; 175 //if (dx + dy + dz < r) // sphere 176 if (dx + dz < r) // circle (very high grasses too) 177 { 178 float y_on_sph = sph.y - sqrt(r - dx - dz); 179 if (position.y > y_on_sph) 180 { position.y = y_on_sph; opos.y = y_on_sph; } 181 } 182 sph = posSph1.xyz; // 2nd 183 dx = opos.x - sph.x; dz = opos.z - sph.z; 184 dx *= dx; dz *= dz; 185 if (dx + dz < r) 186 { 187 float y_on_sph = sph.y - sqrt(r - dx - dz); 188 if (position.y > y_on_sph) 189 position.y = y_on_sph; 190 } 191 } 192 #endif 193 } 194#endif 195 196#if INSTANCING 197 shOutputPosition = shMatrixMult(viewProjMatrix, worldPos); 198#else 199 shOutputPosition = shMatrixMult(wvp, position); 200#endif 201 202 203#if SOFT_PARTICLES 204 screenPosition = float3(shOutputPosition.xy, shOutputPosition.w); 205#endif 206 207 UV.xy = uv0; 208 209 normalPassthrough = normal.xyz; 210 211 212#if VERTEX_COLOUR || ROAD_BLEND 213 vertexColour = colour; 214#endif 215 216#ifdef NEED_DEPTH 217 UV.z = shOutputPosition.z; 218#endif 219 220#if MRT 221 UV.w = length(shMatrixMult(wvMat, position).xyz) / far; 222 viewNormal = shMatrixMult(wvMat, float4(normal.xyz, 0)); 223#endif 224 225 objSpacePositionPassthrough = position; 226 227#if NORMAL_MAP 228 tangentPassthrough = tangent; 229#endif 230 231 232#if SHADOWS 233 @shForeach(3) 234 #if INSTANCING 235 lightSpacePos@shIterator = shMatrixMult(texViewProjMatrix@shIterator, worldPos); 236 #else 237 lightSpacePos@shIterator = shMatrixMult(texWorldViewProjMatrix@shIterator, position); 238 #endif 239 @shEndForeach 240#endif 241 } 242 243 244#else 245 246 // FRAGMENT 247 //---------------------------------------------------------------------------------------- 248 249 SH_BEGIN_PROGRAM 250 shSampler2D(diffuseMap) 251 shInput(float4, UV) 252 253#if MRT 254 shInput(float4, viewNormal) 255 shDeclareMrtOutput(1) 256 shDeclareMrtOutput(2) 257#endif 258 259#if (MRT) || (SOFT_PARTICLES) 260 shUniform(float, far) @shAutoConstant(far, far_clip_distance) 261#endif 262 263#if SOFT_PARTICLES 264 shInput(float3, screenPosition) 265 shSampler2D(sceneDepth) 266 shUniform(float4, viewportSize) @shAutoConstant(viewportSize, viewport_size) 267 shUniform(float, flip) @shAutoConstant(flip, render_target_flipping) 268#endif 269 270#if (SOFT_PARTICLES) || (ENV_MAP) 271 shUniform(float3, camPosWS) @shAutoConstant(camPosWS, camera_position) 272#endif 273 274 275#if VERTEX_COLOUR || ROAD_BLEND 276 shInput(float4, vertexColour) 277#endif 278 279#ifdef NEED_WORLD_MATRIX 280 shUniform(float4x4, worldMatrix) @shAutoConstant(worldMatrix, world_matrix) 281#endif 282 283 284#if CAR_PAINT_MAP 285 shSampler2D(carPaintMap) 286 shUniform(float3, carColour) 287 288 shUniform(float, glossiness) 289 shUniform(float, reflectiveness) 290 291 shUniform(float3, fresnelScaleBiasPower2) @shUniformProperty3f(fresnelScaleBiasPower2, fresnelScaleBiasPower2) 292 shUniform(float4, specular2) @shUniformProperty4f(specular2, specular2) 293#endif 294 295 296#if ALPHA_MAP 297 shSampler2D(alphaMap) 298#endif 299 300#if NORMAL_MAP 301 shSampler2D(normalMap) 302 shInput(float3, tangentPassthrough) 303 shUniform(float, bumpScale) @shUniformProperty1f(bumpScale, bump_scale) 304#endif 305 306#if ENV_MAP 307 shSamplerCube(envMap) 308 309 #if REFL_MAP 310 shSampler2D(reflMap) 311 #endif 312 313 #if FRESNEL 314 shUniform(float3, fresnelScaleBiasPower) @shUniformProperty3f(fresnelScaleBiasPower, fresnelScaleBiasPower) 315 #else 316 shUniform(float, reflAmount) @shUniformProperty1f(reflAmount, refl_amount) 317 #endif 318 319 #if SPECULAR_ALPHA 320 shUniform(float4, env_alpha) @shUniformProperty4f(env_alpha, env_alpha) 321 #endif 322#endif 323 324#if SPEC_MAP 325 shSampler2D(specMap) 326#endif 327 328 shInput(float3, normalPassthrough) 329 shInput(float4, objSpacePositionPassthrough) 330 331 shUniform(float4, lightAmbient) @shAutoConstant(lightAmbient, ambient_light_colour) 332 shUniform(float4, materialAmbient) @shAutoConstant(materialAmbient, surface_ambient_colour) 333 shUniform(float4, materialDiffuse) @shAutoConstant(materialDiffuse, surface_diffuse_colour) 334 shUniform(float4, materialSpecular) @shAutoConstant(materialSpecular, surface_specular_colour) 335 shUniform(float4, materialEmissive) @shAutoConstant(materialEmissive, surface_emissive_colour) 336 shUniform(float, materialShininess) @shAutoConstant(materialShininess, surface_shininess) 337 338 shUniform(float4, lightPosObjSpace) @shAutoConstant(lightPosObjSpace, light_position_object_space) 339 shUniform(float4, lightSpecular) @shAutoConstant(lightSpecular, light_specular_colour) 340 shUniform(float4, lightDiffuse) @shAutoConstant(lightDiffuse, light_diffuse_colour) 341 342 shUniform(float3, camPosObjSpace) @shAutoConstant(camPosObjSpace, camera_position_object_space) 343 344#if FOG 345 shUniform(float4, fogParams) @shAutoConstant(fogParams, fog_params) 346 shUniform(float4, fogColorSun) @shSharedParameter(fogColorSun) 347 shUniform(float4, fogColorAway) @shSharedParameter(fogColorAway) 348 shUniform(float4, fogColorH) @shSharedParameter(fogColorH) 349 shUniform(float4, fogParamsH) @shSharedParameter(fogParamsH) 350 351 shUniform(float4, fogFluidH) @shSharedParameter(fogFluidH) 352 shUniform(float4, fogFluidClr) @shSharedParameter(fogFluidClr) 353#endif 354 355 356#if TERRAIN_LIGHT_MAP 357 shUniform(float, terrainWorldSize) @shSharedParameter(terrainWorldSize) 358 shSampler2D(terrainLightMap) 359 #if TERRAIN_LIGHT_MAP_TOGGLEABLE 360 shUniform(float, enableTerrainLightMap) 361 #endif 362#endif 363 364#if GRASS_WIND 365 shUniform(float, grassFadeRange) @shSharedParameter(grassFadeRange) 366#endif 367 368 369#if SELECTED_GLOW 370 shUniform(float, isSelected) @shAutoConstant(isSelected, custom, 1) 371 shUniform(float, time) @shAutoConstant(time, time, 1) 372#endif 373 374#if SHADOWS 375 @shForeach(3) 376 shInput(float4, lightSpacePos@shIterator) 377 shSampler2D(shadowMap@shIterator) 378 shUniform(float2, invShadowmapSize@shIterator) @shAutoConstant(invShadowmapSize@shIterator, inverse_texture_size, @shIterator) 379 @shEndForeach 380 shUniform(float3, pssmSplitPoints) @shSharedParameter(pssmSplitPoints) 381#endif 382 383#if SHADOWS 384 shUniform(float4, shadowFar_fadeStart) @shSharedParameter(shadowFar_fadeStart) 385 shUniform(float, shadowBias) @shUniformProperty1f(shadowBias, shadowBias) 386#endif 387 388 389 //------------------------------------------------------------------------------------------------------------------------------ 390 391 SH_START_PROGRAM 392 { 393 shOutputColour(0) = shSample(diffuseMap, UV.xy); 394 395#if CAR_PAINT_MAP 396 shOutputColour(0).xyz = shLerp ( shOutputColour(0).xyz, shSample(carPaintMap, UV.xy).r * carColour, 1 - shOutputColour(0).a); 397#endif 398 399#if VERTEX_COLOUR 400 shOutputColour(0) *= vertexColour; 401#endif 402 403#ifdef NEED_DEPTH 404 float depth = UV.z; 405#endif 406 407 // normal 408 float3 normal = normalize(normalPassthrough); 409 410#if NORMAL_MAP 411 412 float3 binormal = cross(tangentPassthrough.xyz, normal.xyz); 413 float3x3 tbn = float3x3(tangentPassthrough.xyz * bumpScale, binormal * bumpScale, normal.xyz); 414 415 #if SH_GLSL 416 tbn = transpose(tbn); 417 #endif 418 419 float3 TSnormal = shSample(normalMap, UV.xy).xyz * 2 - 1; 420 421 normal = normalize (shMatrixMult( transpose(tbn), TSnormal )); 422#endif 423 424#if WATER_PARTICLES_LIT 425 // *** water particles only average, don't color 426 float ambAvg = lightAmbient.x+lightAmbient.y+lightAmbient.z; 427 float3 ambient = materialAmbient.xyz * ambAvg / 3.f; 428#else 429 float3 ambient = materialAmbient.xyz * lightAmbient.xyz; 430#endif 431 432 433 // shadows 434#if SHADOWS 435 float shadow = pssmDepthShadow (lightSpacePos0, invShadowmapSize0, shadowMap0, lightSpacePos1, invShadowmapSize1, shadowMap1, lightSpacePos2, invShadowmapSize2, shadowMap2, depth, pssmSplitPoints, shadowBias); 436#endif 437 438#if SHADOWS 439 float fadeRange = shadowFar_fadeStart.x - shadowFar_fadeStart.y; 440 float fade = 1-((depth - shadowFar_fadeStart.y) / fadeRange); 441 shadow = (depth > shadowFar_fadeStart.x) ? 1.0 : ((depth > shadowFar_fadeStart.y) ? 1.0-((1.0-shadow)*fade) : shadow); 442#endif 443 444#if !(SHADOWS) 445 float shadow = 1.0; 446#endif 447 448 449#if TERRAIN_LIGHT_MAP 450 float shadowingLM; 451 float2 worldPos = shMatrixMult(worldMatrix, float4(objSpacePositionPassthrough.xyz, 1)).xz; 452 float2 lmTexCoord = (worldPos / terrainWorldSize) + 0.5; 453 shadowingLM = shSample(terrainLightMap, lmTexCoord).x; 454 #if TERRAIN_LIGHT_MAP_TOGGLEABLE 455 shadow = min(shadow, (enableTerrainLightMap == 1) ? shadowingLM : 1.0); 456 #else 457 shadow = min(shadow, shadowingLM); 458 #endif 459#endif 460 461 462 // diffuse, specular 463 float3 lightDir = normalize(lightPosObjSpace.xyz); 464 465#if GRASS_WIND 466 float NdotL = 1; 467#else 468 #if TWOSIDE_DIFFUSE 469 float NdotL = abs(dot(normal, lightDir)); 470 #else 471 float NdotL = max(dot(normal, lightDir), 0); 472 #endif 473#endif 474 float3 diffuse = materialDiffuse.xyz * lightDiffuse.xyz * NdotL * shadow; 475 476 float3 eyeDir = normalize(camPosObjSpace.xyz - objSpacePositionPassthrough.xyz); 477 float3 halfAngle = normalize (lightDir + eyeDir); 478 479 #if ENV_MAP 480 float spec_mul = 4; //x4 481 #else 482 float spec_mul = 1; 483 #endif 484 485 shOutputColour(0).xyz *= (ambient + diffuse + materialEmissive.xyz); 486 487 488 // specular 489 float3 specular = float3(0,0,0); 490 if (NdotL > 0 && shadow > 0) 491 { 492 #if TWOSIDE_DIFFUSE 493 float specDot = abs(dot(normal, halfAngle)); 494 #else 495 float specDot = max(dot(normal, halfAngle), 0); 496 #endif 497 498 #if CAR_PAINT_MAP 499 float smul = shLerp(1, specular2.w / materialShininess, glossiness); 500 float shininess = shLerp(materialShininess, specular2.w, glossiness); 501 float3 matSpec = shLerp(materialSpecular.xyz, specular2.xyz, glossiness); 502 #else 503 float shininess = materialShininess; 504 float3 matSpec = materialSpecular.xyz; 505 float smul = 1; 506 #endif 507 508 #if !SPEC_MAP 509 specular = pow(specDot, spec_mul * shininess) * matSpec; 510 511 #if CAR_PAINT_MAP 512 specular += pow(specDot, 1024) * matSpec; // sun on car body 513 #endif 514 #else 515 float4 specTex = shSample(specMap, UV.xy); 516 #if !SPECMAP_RGB /* spec_mul */ 517 specular = pow(specDot, specTex.a * 255 * smul) * specTex.xyz * matSpec; 518 #else 519 specular = pow(specDot, shininess * smul) * specTex.xyz * matSpec; 520 #endif 521 522 #if CAR_PAINT_MAP 523 specular += pow(specDot, 1024) * specTex.xyz * matSpec; 524 #endif 525 #endif 526 shOutputColour(0).xyz += specular * lightSpecular.xyz * shadow; 527 } 528 529 530 // reflection 531#if ENV_MAP 532 float3 r = reflect( -eyeDir, normal ); 533 r = normalize(shMatrixMult(worldMatrix, float4(r, 0)).xyz); 534 535 r.z = -r.z; 536 #if SPECULAR_ALPHA 537 float4 envColor = shCubicSample(envMap, r) * env_alpha.x; 538 #else 539 float4 envColor = shCubicSample(envMap, r); 540 #endif 541 542 float reflectionFactor = 1; 543 544 #if REFL_MAP 545 reflectionFactor *= shSample(reflMap, UV.xy).r; 546 #endif 547 548 #if FRESNEL 549 float facing = 1.0 - max(abs(dot(-eyeDir, normal)), 0); 550 #if CAR_PAINT_MAP 551 float3 fSBP = shLerp(fresnelScaleBiasPower, fresnelScaleBiasPower2, glossiness); 552 reflectionFactor *= reflectiveness; 553 #else 554 float3 fSBP = fresnelScaleBiasPower; 555 #endif 556 reflectionFactor *= shSaturate(fSBP.y + fSBP.x * pow(facing, fSBP.z)); 557 #else 558 float facing = reflAmount; 559 reflectionFactor *= reflAmount; 560 #endif 561 562 shOutputColour(0).xyz = shLerp(shOutputColour(0).xyz, envColor.xyz, reflectionFactor); 563#endif 564 565 566#if FOG 567 float worldPosY = shMatrixMult(worldMatrix, float4(objSpacePositionPassthrough.xyz, 1)).y; 568 569 ///_ calculate fog 570 float fogDepth = shSaturate((depth - fogParams.y) * fogParams.w); // w = 1 / (max - min) 571 float fogDepthH = shSaturate((depth - fogParamsH.z) * fogParamsH.w); 572 573 float fogDir = dot( normalize(eyeDir.xz), normalize(lightDir.xz) ) * 0.5 + 0.5; 574 float fogH = shSaturate( (fogParamsH.x/*h*/ - worldPosY) * fogParamsH.y/*dens*/); 575 576 float4 fogClrDir = shLerp( fogColorAway, fogColorSun, fogDir); 577 float4 fogClrFinal = shLerp( fogClrDir, fogColorH, fogH); 578 float fogL = shLerp( fogDepth * fogClrDir.a, fogDepthH * fogColorH.a, fogH); 579 580 /// fluid fog 581 float flDepth = shSaturate(depth * fogFluidH.y); 582 float flH = shSaturate((fogFluidH.x/*h*/ - worldPosY) * fogFluidH.z); 583 float4 flClrFinal = shLerp( fogClrFinal, fogFluidClr, flH); 584 float flL = shLerp( fogL, flDepth /* * fogFluidClr.a*/, flH); 585 586 shOutputColour(0).xyz = shLerp( shOutputColour(0).xyz, flClrFinal.rgb, flL); 587 ///_ 588#endif 589 // old FOG 590 //float fogValue = shSaturate((depth - fogParams.y) * fogParams.w); 591 //shOutputColour(0).xyz = shLerp (shOutputColour(0).xyz, fogColour, fogValue); 592 593 594 // alpha 595 shOutputColour(0).a *= materialDiffuse.a; 596 597#if ALPHA_MAP 598 shOutputColour(0).a *= shSample(alphaMap, float2(UV.x, UV.y * 0.025)).r; 599#endif 600 601#if SPECULAR_ALPHA 602 // bump alpha with specular 603 #if ENV_MAP // par // par 604 shOutputColour(0).a = min(shOutputColour(0).a + specular.g + pow(envColor.g * env_alpha.y, env_alpha.z) * facing * env_alpha.w, 1); 605 #else 606 shOutputColour(0).a = min(shOutputColour(0).a + specular.g, 1); 607 #endif 608#endif 609 610 611#if GRASS_WIND 612 // grass distance fading 613 float dist = distance(camPosObjSpace.xz, objSpacePositionPassthrough.xz); 614 shOutputColour(0).a *= (2.0f - (2.0f * dist / grassFadeRange)); 615#endif 616 617#if SOFT_PARTICLES 618 float2 screenUV = screenPosition.xy / screenPosition.z; 619 screenUV = screenUV * float2(0.5f, -0.5f) + float2(0.5f, 0.5f); 620 screenUV += (viewportSize.zw) * 0.5; 621 screenUV.y =(1-shSaturate(flip))+flip*screenUV.y; 622 float depthTex = shSample(sceneDepth, screenUV).x * far; 623 float4 worldPos = shMatrixMult(worldMatrix, float4(objSpacePositionPassthrough.xyz, 1)); 624 float distanceToPixel = length(worldPos.xyz - camPosWS.xyz); 625 float thickness = 0.5; 626 float tNear = distanceToPixel - thickness; 627 float tFar = distanceToPixel + thickness; 628 float depthAlpha = shSaturate(depthTex - distanceToPixel); 629 shOutputColour(0).a *= depthAlpha; 630#endif 631 632 633#if ROAD_BLEND 634 shOutputColour(0).a *= vertexColour.b; 635#endif 636 637#if SELECTED_GLOW 638 shOutputColour(0).xyzw += isSelected * (float4(0.0, 0.4, 1.0, 0.5) * (0.5 + 0.1 * cos(4.0 * time))); 639#endif 640 //shOutputColour(0).xyz = shOutputColour(0).xyz * 0.001 + normal.xyz; // normal test 641 642#if MRT 643 shOutputColour(1) = float4(UV.w, normalize(viewNormal.xyz)); 644 shOutputColour(2) = float4(UV.z / far, 0, UV.z / objSpacePositionPassthrough.w, MOTIONBLUR_MASK); 645#endif 646 647 } 648 649#endif 650