SHARE
TWEET

The Witcher 3 - HLSL Fog Shader (RenderDoc ready)

a guest Jun 16th, 2019 134 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. cbuffer cbuffer12 : register(b12) {
  3.     float4 cb12_v0 : packoffset(c0.x);
  4.     float4 cb12_v1 : packoffset(c1.x);
  5.     float4 cb12_v2 : packoffset(c2.x);
  6.     float4 cb12_v3 : packoffset(c3.x);
  7.     float4 cb12_v4 : packoffset(c4.x);
  8.     float4 cb12_v5 : packoffset(c5.x);
  9.     float4 cb12_v6 : packoffset(c6.x);
  10.     float4 cb12_v7 : packoffset(c7.x);
  11.     float4 cb12_v8 : packoffset(c8.x);
  12.     float4 cb12_v9 : packoffset(c9.x);
  13.     float4 cb12_v10 : packoffset(c10.x);
  14.     float4 cb12_v11 : packoffset(c11.x);
  15.     float4 cb12_v12 : packoffset(c12.x);
  16.     float4 cb12_v13 : packoffset(c13.x);
  17.     float4 cb12_v14 : packoffset(c14.x);
  18.     float4 cb12_v15 : packoffset(c15.x);
  19.     float4 cb12_v16 : packoffset(c16.x);
  20.     float4 cb12_v17 : packoffset(c17.x);
  21.     float4 cb12_v18 : packoffset(c18.x);
  22.     float4 cb12_v19 : packoffset(c19.x);
  23.     float4 cb12_v20 : packoffset(c20.x);
  24.     float4 cb12_v21 : packoffset(c21.x);
  25.     float4 cb12_v22 : packoffset(c22.x);
  26.     float4 cb12_v23 : packoffset(c23.x);
  27.     float4 cb12_v24 : packoffset(c24.x);
  28.     float4 cb12_v25 : packoffset(c25.x);
  29.     float4 cb12_v26 : packoffset(c26.x);
  30.     float4 cb12_v27 : packoffset(c27.x);
  31.     float4 cb12_v28 : packoffset(c28.x);
  32.     float4 cb12_v29 : packoffset(c29.x);
  33.     float4 cb12_v30 : packoffset(c30.x);
  34.     float4 cb12_v31 : packoffset(c31.x);
  35.     float4 cb12_v32 : packoffset(c32.x);
  36.     float4 cb12_v33 : packoffset(c33.x);
  37.     float4 cb12_v34 : packoffset(c34.x);
  38.     float4 cb12_v35 : packoffset(c35.x);
  39.     float4 cb12_v36 : packoffset(c36.x);
  40.     float4 cb12_v37 : packoffset(c37.x);
  41.     float4 cb12_v38 : packoffset(c38.x);
  42.     float4 cb12_v39 : packoffset(c39.x);
  43.     float4 cb12_v40 : packoffset(c40.x);
  44.     float4 cb12_v41 : packoffset(c41.x);
  45.     float4 cb12_v42 : packoffset(c42.x);
  46.     float4 cb12_v43 : packoffset(c43.x);
  47.     float4 cb12_v44 : packoffset(c44.x);
  48.     float4 cb12_v45 : packoffset(c45.x);
  49.     float4 cb12_v46 : packoffset(c46.x);
  50.     float4 cb12_v47 : packoffset(c47.x);
  51.     float4 cb12_v48 : packoffset(c48.x);
  52.     float4 cb12_v49 : packoffset(c49.x);
  53.     float4 cb12_v50 : packoffset(c50.x);
  54.     float4 cb12_v51 : packoffset(c51.x);
  55.     float4 cb12_v52 : packoffset(c52.x);
  56.     float4 cb12_v53 : packoffset(c53.x);
  57.     float4 cb12_v54 : packoffset(c54.x);
  58.     float4 cb12_v55 : packoffset(c55.x);
  59.     float4 cb12_v56 : packoffset(c56.x);
  60.     float4 cb12_v57 : packoffset(c57.x);
  61.     float4 cb12_v58 : packoffset(c58.x);
  62.     float4 cb12_v59 : packoffset(c59.x);
  63.     float4 cb12_v60 : packoffset(c60.x);
  64.     float4 cb12_v61 : packoffset(c61.x);
  65.     float4 cb12_v62 : packoffset(c62.x);
  66.     float4 cb12_v63 : packoffset(c63.x);
  67.     float4 cb12_v64 : packoffset(c64.x);
  68.     float4 cb12_v65 : packoffset(c65.x);
  69.     float4 cb12_v66 : packoffset(c66.x);
  70.     float4 cb12_v67 : packoffset(c67.x);
  71.     float4 cb12_v68 : packoffset(c68.x);
  72.     float4 cb12_v69 : packoffset(c69.x);
  73.     float4 cb12_v70 : packoffset(c70.x);
  74.     float4 cb12_v71 : packoffset(c71.x);
  75.     float4 cb12_v72 : packoffset(c72.x);
  76.     float4 cb12_v73 : packoffset(c73.x);
  77.     float4 cb12_v74 : packoffset(c74.x);
  78.     float4 cb12_v75 : packoffset(c75.x);
  79.     float4 cb12_v76 : packoffset(c76.x);
  80.     float4 cb12_v77 : packoffset(c77.x);
  81.     float4 cb12_v78 : packoffset(c78.x);
  82.     float4 cb12_v79 : packoffset(c79.x);
  83.     float4 cb12_v80 : packoffset(c80.x);
  84.     float4 cb12_v81 : packoffset(c81.x);
  85.     float4 cb12_v82 : packoffset(c82.x);
  86.     float4 cb12_v83 : packoffset(c83.x);
  87.     float4 cb12_v84 : packoffset(c84.x);
  88.     float4 cb12_v85 : packoffset(c85.x);
  89.     float4 cb12_v86 : packoffset(c86.x);
  90.     float4 cb12_v87 : packoffset(c87.x);
  91.     float4 cb12_v88 : packoffset(c88.x);
  92.     float4 cb12_v89 : packoffset(c89.x);
  93.     float4 cb12_v90 : packoffset(c90.x);
  94.     float4 cb12_v91 : packoffset(c91.x);
  95.     float4 cb12_v92 : packoffset(c92.x);
  96.     float4 cb12_v93 : packoffset(c93.x);
  97.     float4 cb12_v94 : packoffset(c94.x);
  98.     float4 cb12_v95 : packoffset(c95.x);
  99.     float4 cb12_v96 : packoffset(c96.x);
  100.     float4 cb12_v97 : packoffset(c97.x);
  101.     float4 cb12_v98 : packoffset(c98.x);
  102.     float4 cb12_v99 : packoffset(c99.x);
  103.     float4 cb12_v100 : packoffset(c100.x);
  104.     float4 cb12_v101 : packoffset(c101.x);
  105.     float4 cb12_v102 : packoffset(c102.x);
  106.     float4 cb12_v103 : packoffset(c103.x);
  107.     float4 cb12_v104 : packoffset(c104.x);
  108.     float4 cb12_v105 : packoffset(c105.x);
  109.     float4 cb12_v106 : packoffset(c106.x);
  110.     float4 cb12_v107 : packoffset(c107.x);
  111.     float4 cb12_v108 : packoffset(c108.x);
  112.     float4 cb12_v109 : packoffset(c109.x);
  113.     float4 cb12_v110 : packoffset(c110.x);
  114.     float4 cb12_v111 : packoffset(c111.x);
  115.     float4 cb12_v112 : packoffset(c112.x);
  116.     float4 cb12_v113 : packoffset(c113.x);
  117.     float4 cb12_v114 : packoffset(c114.x);
  118.     float4 cb12_v115 : packoffset(c115.x);
  119.     float4 cb12_v116 : packoffset(c116.x);
  120.     float4 cb12_v117 : packoffset(c117.x);
  121.     float4 cb12_v118 : packoffset(c118.x);
  122.     float4 cb12_v119 : packoffset(c119.x);
  123.     float4 cb12_v120 : packoffset(c120.x);
  124.     float4 cb12_v121 : packoffset(c121.x);
  125.     float4 cb12_v122 : packoffset(c122.x);
  126.     float4 cb12_v123 : packoffset(c123.x);
  127.     float4 cb12_v124 : packoffset(c124.x);
  128.     float4 cb12_v125 : packoffset(c125.x);
  129.     float4 cb12_v126 : packoffset(c126.x);
  130.     float4 cb12_v127 : packoffset(c127.x);
  131.     float4 cb12_v128 : packoffset(c128.x);
  132.     float4 cb12_v129 : packoffset(c129.x);
  133.     float4 cb12_v130 : packoffset(c130.x);
  134.     float4 cb12_v131 : packoffset(c131.x);
  135.     float4 cb12_v132 : packoffset(c132.x);
  136.     float4 cb12_v133 : packoffset(c133.x);
  137.     float4 cb12_v134 : packoffset(c134.x);
  138.     float4 cb12_v135 : packoffset(c135.x);
  139.     float4 cb12_v136 : packoffset(c136.x);
  140.     float4 cb12_v137 : packoffset(c137.x);
  141.     float4 cb12_v138 : packoffset(c138.x);
  142.     float4 cb12_v139 : packoffset(c139.x);
  143.     float4 cb12_v140 : packoffset(c140.x);
  144.     float4 cb12_v141 : packoffset(c141.x);
  145.     float4 cb12_v142 : packoffset(c142.x);
  146.     float4 cb12_v143 : packoffset(c143.x);
  147.     float4 cb12_v144 : packoffset(c144.x);
  148.     float4 cb12_v145 : packoffset(c145.x);
  149.     float4 cb12_v146 : packoffset(c146.x);
  150.     float4 cb12_v147 : packoffset(c147.x);
  151.     float4 cb12_v148 : packoffset(c148.x);
  152.     float4 cb12_v149 : packoffset(c149.x);
  153.     float4 cb12_v150 : packoffset(c150.x);
  154.     float4 cb12_v151 : packoffset(c151.x);
  155.     float4 cb12_v152 : packoffset(c152.x);
  156.     float4 cb12_v153 : packoffset(c153.x);
  157.     float4 cb12_v154 : packoffset(c154.x);
  158.     float4 cb12_v155 : packoffset(c155.x);
  159.     float4 cb12_v156 : packoffset(c156.x);
  160.     float4 cb12_v157 : packoffset(c157.x);
  161.     float4 cb12_v158 : packoffset(c158.x);
  162.     float4 cb12_v159 : packoffset(c159.x);
  163.     float4 cb12_v160 : packoffset(c160.x);
  164.     float4 cb12_v161 : packoffset(c161.x);
  165.     float4 cb12_v162 : packoffset(c162.x);
  166.     float4 cb12_v163 : packoffset(c163.x);
  167.     float4 cb12_v164 : packoffset(c164.x);
  168.     float4 cb12_v165 : packoffset(c165.x);
  169.     float4 cb12_v166 : packoffset(c166.x);
  170.     float4 cb12_v167 : packoffset(c167.x);
  171.     float4 cb12_v168 : packoffset(c168.x);
  172.     float4 cb12_v169 : packoffset(c169.x);
  173.     float4 cb12_v170 : packoffset(c170.x);
  174.     float4 cb12_v171 : packoffset(c171.x);
  175.     float4 cb12_v172 : packoffset(c172.x);
  176.     float4 cb12_v173 : packoffset(c173.x);
  177.     float4 cb12_v174 : packoffset(c174.x);
  178.     float4 cb12_v175 : packoffset(c175.x);
  179.     float4 cb12_v176 : packoffset(c176.x);
  180.     float4 cb12_v177 : packoffset(c177.x);
  181.     float4 cb12_v178 : packoffset(c178.x);
  182.     float4 cb12_v179 : packoffset(c179.x);
  183.     float4 cb12_v180 : packoffset(c180.x);
  184.     float4 cb12_v181 : packoffset(c181.x);
  185.     float4 cb12_v182 : packoffset(c182.x);
  186.     float4 cb12_v183 : packoffset(c183.x);
  187.     float4 cb12_v184 : packoffset(c184.x);
  188.     float4 cb12_v185 : packoffset(c185.x);
  189.     float4 cb12_v186 : packoffset(c186.x);
  190.     float4 cb12_v187 : packoffset(c187.x);
  191.     float4 cb12_v188 : packoffset(c188.x);
  192.     float4 cb12_v189 : packoffset(c189.x);
  193.     float4 cb12_v190 : packoffset(c190.x);
  194.     float4 cb12_v191 : packoffset(c191.x);
  195.     float4 cb12_v192 : packoffset(c192.x);
  196.     float4 cb12_v193 : packoffset(c193.x);
  197.     float4 cb12_v194 : packoffset(c194.x);
  198.     float4 cb12_v195 : packoffset(c195.x);
  199.     float4 cb12_v196 : packoffset(c196.x);
  200.     float4 cb12_v197 : packoffset(c197.x);
  201.     float4 cb12_v198 : packoffset(c198.x);
  202.     float4 cb12_v199 : packoffset(c199.x);
  203.     float4 cb12_v200 : packoffset(c200.x);
  204.     float4 cb12_v201 : packoffset(c201.x);
  205.     float4 cb12_v202 : packoffset(c202.x);
  206.     float4 cb12_v203 : packoffset(c203.x);
  207.     float4 cb12_v204 : packoffset(c204.x);
  208.     float4 cb12_v205 : packoffset(c205.x);
  209.     float4 cb12_v206 : packoffset(c206.x);
  210.     float4 cb12_v207 : packoffset(c207.x);
  211.     float4 cb12_v208 : packoffset(c208.x);
  212.     float4 cb12_v209 : packoffset(c209.x);
  213.     row_major float4x4 screenToWorld : packoffset(c210.x);
  214. };
  215.  
  216.  
  217. cbuffer cbuffer3 : register(b3) {
  218.     float4 cb3_v0 : packoffset(c0.x);
  219.     float4 cb3_v1 : packoffset(c1.x);
  220. };
  221.  
  222. #define OVERRIDE_FOG
  223.  
  224. Texture2D texDepth : register (t0);
  225. Texture2D texColor : register (t1);
  226. Texture2D texAO    : register (t2);
  227.  
  228. SamplerState samplerPointClamp  : register (s0);
  229. SamplerState samplerPointWrap   : register (s1);
  230. SamplerState samplerLinearClamp : register (s2);
  231. SamplerState samplerLinearWrap  : register (s3);
  232. SamplerState samplerAnisoClamp  : register (s4);
  233. SamplerState samplerAnisoWrap   : register (s5);
  234.  
  235. struct VS_OUTPUT
  236. {
  237.     float4 PositionH : SV_Position;
  238.     float2 Texcoords : Texcoord0;
  239. };
  240.  
  241. struct FogResult
  242. {
  243.     float4 paramsFog;
  244.     float4 paramsAerial;
  245. };
  246.  
  247. float3 getWorldPos( float2 screenPos, float depth )  
  248. {  
  249.    float4 worldPos = float4(screenPos, depth, 1.0);  
  250.    worldPos = mul( worldPos, screenToWorld );  
  251.      
  252.    return worldPos.xyz / worldPos.w;  
  253. }
  254.  
  255. float linstep( float min, float max, float v )  
  256. {  
  257.     return saturate( (v - min) / (max - min) );  
  258. }
  259.  
  260.  
  261. float4 SelectDensityParams(const bool isSky)
  262. {
  263.     float4 FogDensityParamsScene = cb12_v43;
  264.     float4 FogDensityParamsSky = cb12_v44;
  265.    
  266.     if (isSky)
  267.         return FogDensityParamsSky;
  268.     else
  269.         return FogDensityParamsScene;
  270. }
  271.  
  272. float AdjustAmbientOcclusion(in float inputAO, in float worldToCameraDistance)
  273. {
  274.     // *** Inputs *** //
  275.     const float aoDistanceStart = cb3_v0.x;
  276.     const float aoDistanceEnd = cb3_v0.y;
  277.     const float aoStrengthStart = cb3_v0.z;
  278.     const float aoStrengthEnd = cb3_v0.w;
  279.      
  280.     // * Adjust AO
  281.     float aoDistanceIntensity = linstep( aoDistanceStart, aoDistanceEnd, worldToCameraDistance );
  282.     float aoStrength = lerp(aoStrengthStart, aoStrengthEnd, aoDistanceIntensity);  
  283.     float adjustedAO = lerp(1.0, inputAO, aoStrength);
  284.    
  285.     return adjustedAO;
  286. }
  287.  
  288. FogResult CalculateFog(float3 fragPosWorldSpace, float3 customCameraPos, float fogStartDist, float ao, const bool isSky)
  289. {
  290.     // *** Inputs *** //
  291.     float3 FogSunDir = cb12_v38.xyz;
  292.     float3 FogColorFront = cb12_v39.xyz;
  293.     float3 FogColorMiddle = cb12_v40.xyz;
  294.     float3 FogColorBack = cb12_v41.xyz;
  295.    
  296.     float4 FogBaseParams = cb12_v42;
  297.     float4 FogDensityParamsScene = cb12_v43;
  298.     float4 FogDensityParamsSky = cb12_v44;
  299.    
  300.     float3 AerialColorFront = cb12_v45.xyz;
  301.     float3 AerialColorMiddle = cb12_v46.xyz;
  302.     float3 AerialColorBack = cb12_v47.xyz;
  303.     float4 AerialParams = cb12_v48;
  304.    
  305.     float3 GlobalLightDirection = FogSunDir;
  306.    
  307.     float4 density_params = SelectDensityParams(isSky);
  308.    
  309.    
  310.      // *** Shader data *** //
  311.     float density = density_params.x;
  312.     float dist_clamp = FogBaseParams.z;
  313.     float final_exp_fog = FogBaseParams.w;
  314.     float final_exp_aerial = AerialParams.x;
  315.  
  316.     float3 frag_vec = fragPosWorldSpace.xyz - customCameraPos.xyz;
  317.     float frag_dist = length(frag_vec);
  318.    
  319.     float3 frag_dir = frag_vec / frag_dist;
  320.    
  321.     customCameraPos += frag_dir * fogStartDist;
  322.     frag_dist = max(0, frag_dist - fogStartDist);
  323.  
  324.     frag_dist = (isSky) ? dist_clamp : min(dist_clamp, frag_dist);
  325.     frag_vec = frag_dir * frag_dist;
  326.  
  327.     const float inv_num_samples = 1.0 / 16;
  328.     float3 frag_step = frag_vec * inv_num_samples;
  329.     float density_sample_scale = frag_dist * density * inv_num_samples;
  330.     float dot_fragDirSunDir = dot(GlobalLightDirection.xyz, frag_dir);
  331.  
  332.     float density_factor = 1.0;
  333.     {
  334.         float density_shift = FogBaseParams.x;
  335.  
  336.         float fc_t = dot_fragDirSunDir;
  337.         fc_t = (fc_t + density_shift) / (1.0 + density_shift);
  338.         fc_t = saturate(fc_t);
  339.         density_factor = lerp(density_params.z, density_params.y, fc_t);
  340.     }
  341.  
  342.     float3 curr_col_fog;
  343.     float3 curr_col_aerial;
  344.     {
  345.         float _dot = dot_fragDirSunDir;
  346.  
  347.         float _dd = _dot;
  348.         {
  349.             const float _distOffset = -150;
  350.             const float _distRange = 500;
  351.             const float _mul = 1.0 / _distRange;
  352.             const float _bias = _distOffset * _mul;
  353.  
  354.             _dd = abs(_dd);
  355.             _dd *= _dd;
  356.             _dd *= saturate( frag_dist * _mul + _bias );
  357.         }
  358.  
  359.         curr_col_fog = lerp( FogColorMiddle.xyz, (_dot>0.0f ? FogColorFront.xyz : FogColorBack.xyz), _dd );
  360.         curr_col_aerial = lerp( AerialColorMiddle.xyz, (_dot>0.0f ? AerialColorFront.xyz : AerialColorBack.xyz), _dd );
  361.     }
  362.  
  363.     float fog_amount = 1;
  364.     float fog_amount_scale = 0;
  365.     [branch]
  366.     if ( frag_dist >= AerialParams.y )
  367.     {
  368.         float curr_pos_z_base = (customCameraPos.z + FogBaseParams.y) * density_factor;
  369.         float curr_pos_z_step = frag_step.z * density_factor;
  370.  
  371.         [unroll] for ( int i=16; i>0; --i )
  372.         {
  373.             fog_amount *= 1 - saturate( density_sample_scale / (1 + max( 0.0, curr_pos_z_base + (i) * curr_pos_z_step ) ) );
  374.         }
  375.  
  376.         fog_amount = 1 - fog_amount;
  377.         fog_amount_scale = saturate( (frag_dist - AerialParams.y) * AerialParams.z );
  378.     }
  379.     //ret.paramsFog.xyz = fog_amount;
  380.     //return ret;
  381.  
  382.     FogResult ret;
  383.  
  384.     ret.paramsFog = float4 ( curr_col_fog, fog_amount_scale * pow( abs(fog_amount), final_exp_fog ) );
  385.     ret.paramsAerial = float4 ( curr_col_aerial, fog_amount_scale * pow( abs(fog_amount), final_exp_aerial ) );
  386.    
  387.    
  388. #ifdef OVERRIDE_FOG
  389.    
  390.     // Override
  391.     float fog_influence = ret.paramsFog.w; // r0.w
  392.  
  393.     float override1ColorScale = cb12_v189.x;
  394.     float override1ColorBias = cb12_v189.y;
  395.     float3 override1Color = cb12_v188.rgb;
  396.    
  397.     float override1InfluenceScale = cb12_v189.z;
  398.     float override1InfluenceBias = cb12_v189.w;
  399.     float override1Influence = cb12_v188.w;
  400.    
  401.    
  402.     float override1ColorAmount = saturate(fog_influence * override1ColorScale + override1ColorBias);
  403.     float override1InfluenceAmount = saturate(fog_influence * override1InfluenceScale + override1InfluenceBias);  
  404.    
  405.     float4 paramsFogOverride;
  406.     paramsFogOverride.rgb = lerp(curr_col_fog, override1Color, override1ColorAmount ); // ***r5.xyz  
  407.    
  408.  
  409.     float param1 = lerp(1.0, override1Influence, override1InfluenceAmount); // r0.x
  410.     paramsFogOverride.w = saturate(fog_influence * param1); // ** r5.w
  411.  
  412.    
  413.     const float extraFogOverride = cb12_v192.x;
  414.    
  415.     [branch]
  416.     if (extraFogOverride > 0.0)
  417.     {
  418.         float override2ColorScale = cb12_v191.x;
  419.         float override2ColorBias = cb12_v191.y;
  420.         float3 override2Color = cb12_v190.rgb;
  421.    
  422.         float override2InfluenceScale = cb12_v191.z;
  423.         float override2InfluenceBias = cb12_v191.w;
  424.         float override2Influence = cb12_v190.w;
  425.        
  426.         float override2ColorAmount = saturate(fog_influence * override2ColorScale + override2ColorBias);
  427.         float override2InfluenceAmount = saturate(fog_influence * override2InfluenceScale + override2InfluenceBias);
  428.      
  429.         float4 paramsFogOverride2;
  430.         paramsFogOverride2.rgb = lerp(curr_col_fog, override2Color, override2ColorAmount); // r3.xyz
  431.                
  432.         float  ov_param1 = lerp(1.0, override2Influence, override2InfluenceAmount); // r0.z
  433.         paramsFogOverride2.w = saturate(fog_influence * ov_param1); // r3.w
  434.  
  435.         paramsFogOverride = lerp(paramsFogOverride, paramsFogOverride2, extraFogOverride);
  436.  
  437.     }
  438.     ret.paramsFog = paramsFogOverride;
  439.    
  440. #endif
  441.  
  442.     return ret;
  443. }
  444.  
  445.  
  446. float3 ApplyFog(FogResult fog, float3 color)
  447. {
  448.     const float3 LuminanceFactors = float3(0.333f, 0.555f, 0.222f);
  449.  
  450.     float3 aerialColor = dot(LuminanceFactors, color) * fog.paramsAerial.xyz;
  451.     color = lerp(color, aerialColor, fog.paramsAerial.w);
  452.     color = lerp(color, fog.paramsFog.xyz, fog.paramsFog.w);
  453.     return color.xyz;
  454.  
  455.     //return fog.paramsFog.xyz;
  456. }
  457.  
  458.  
  459. float4 EditedShaderPS( in VS_OUTPUT Input ) : SV_Target0
  460. {    
  461.     // Get coordinates for load
  462.     uint3 ssPosition = uint3( (uint2) Input.PositionH.xy, 0);
  463.    
  464.     // Load depth from texture
  465.     float hardwareDepth = texDepth.Load(ssPosition).x;
  466.    
  467.     // Calculate inverted depth
  468.     float depthScale = cb12_v22.x;
  469.     float depthBias  = cb12_v22.y;    
  470.     float invDepth = hardwareDepth * depthScale + depthBias;
  471.    
  472.     // Output color
  473.     float3 outColor = 0.0.xxx;
  474.    
  475.     [branch]
  476.     if (invDepth < 1.0)
  477.     {
  478.         float3 worldPos = getWorldPos( ssPosition.xy, hardwareDepth );
  479.         float3 CameraPosition = cb12_v0.xyz;
  480.        
  481.         // Get HDR color
  482.         float3 colorHDR = texColor.Load( ssPosition ).rgb;
  483.        
  484.         // Get AO and adjust it
  485.         float ao = texAO.Load( ssPosition ).x;  
  486.         ao = max(cb3_v1.x, ao);
  487.         ao = AdjustAmbientOcclusion(ao, length(worldPos-CameraPosition));
  488.        
  489.         // Calculate fog
  490.         float fogStart = cb12_v22.z; // near plane
  491.        
  492.         FogResult fog = CalculateFog( worldPos, CameraPosition, fogStart, ao, false );
  493.      
  494.         // Apply AO to influence
  495.         fog.paramsFog.w *= ao;
  496.         fog.paramsAerial.w *= ao;
  497.      
  498.         // Mix fog with scene color
  499.         outColor = ApplyFog(fog, colorHDR);
  500.     }
  501.    
  502.     return float4( outColor, 1.0);
  503. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top