G2A Many GEOs
SHARE
TWEET

The Witcher 3 - witcher senses (fisheye & combining) 1.0

a guest Apr 6th, 2019 118 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // No HLSL available - function stub generated
  2.  
  3. //SamplerComparisonState sampler0 : register(s0); // can't disambiguate
  4. SamplerState sampler0 : register(s0); // can't disambiguate
  5. //SamplerComparisonState sampler2 : register(s2); // can't disambiguate
  6. SamplerState sampler2 : register(s2); // can't disambiguate
  7. Texture2D texture0 : register(t0);
  8. Texture2D texture2 : register(t2);
  9. Texture2D texture3 : register(t3);
  10.  
  11.  
  12. cbuffer cbuffer0 : register(b0) {
  13.     float4 cb0_v0 : packoffset(c0.x);
  14.     float4 cb0_v1 : packoffset(c1.x);
  15.     float4 cb0_v2 : packoffset(c2.x);
  16. };
  17.  
  18. cbuffer cbuffer3 : register(b3) {
  19.     float4 cb3_v0 : packoffset(c0.x);
  20.     float4 cb3_v1 : packoffset(c1.x);
  21.     float4 cb3_v2 : packoffset(c2.x);
  22.     float4 cb3_v3 : packoffset(c3.x);
  23.     float4 cb3_v4 : packoffset(c4.x);
  24.     float4 cb3_v5 : packoffset(c5.x);
  25.     float4 cb3_v6 : packoffset(c6.x);
  26. };
  27.  
  28. static const float PI = 3.1415;
  29. static const float PI_4 = PI / 4.0;
  30.  
  31.  
  32. float4 EditedShaderPS( float4 PosH : SV_Position )  : SV_Target0
  33. {
  34.     // *** Inputs  
  35.    
  36.     // * Zoom amount, always 1
  37.     float zoomAmount = cb3_v1.x;
  38.    
  39.     // Another value which affect fisheye effect
  40.     // but always set to float2(1.0, 1.0).
  41.     float2 amount = cb0_v2.zw;
  42.    
  43.     // Elapsed time in seconds
  44.     float time = cb0_v0.x;
  45.    
  46.     // Colors of witcher senses
  47.     float3 colorInteresting = cb3_v5.rgb;
  48.     float3 colorTraces = cb3_v4.rgb;
  49.    
  50.     // Was always set to float2(0.0, 0.0).
  51.     // Setting this to higher values
  52.     // makes "greyish corners" effect weaker.
  53.     float2 offset = cb3_v2.xy;
  54.    
  55.     // Dimensions of fullscreen
  56.     float2 texSize = cb0_v2.xy;
  57.     float2 invTexSize = cb0_v1.zw;
  58.    
  59.    
  60.     // *** Shader
  61.    
  62.     // Main uv
  63.     float2 uv = PosH.xy / texSize;
  64.    
  65.     // Scale at first from [0-1] to [-1;1], then calculate abs
  66.     float2 uv3 = abs( uv * 2.0 - 1.0);
  67.    
  68.     // Aspect ratio
  69.     float aspectRatio = texSize.x / texSize.y;
  70.    
  71.    
  72.     // * Mask used to make corners grey
  73.     float mask_gray_corners;
  74.     {
  75.         float2 newUv = float2( uv3.x * aspectRatio, uv3.y ) - offset;
  76.         newUv = saturate( newUv / 1.8 );
  77.         newUv = pow(newUv, 2.5);
  78.        
  79.         mask_gray_corners = 1-min(1.0,  length(newUv) );
  80.     }
  81.    
  82.    
  83.     // Main value which causes fisheye effect [0-1]
  84.     const float fisheyeAmount = saturate( cb3_v6.x );
  85.    
  86.    
  87.     // circle radius used further
  88.     float circle_radius;
  89.     {
  90.         float2 corners0 = saturate( float2(0.03, 0.03) - uv );
  91.         float cor = corners0.x + corners0.y;
  92.    
  93.         float2 corners1 = saturate( uv - float2(0.97, 0.97) );
  94.    
  95.         cor += corners1.x;
  96.         cor += corners1.y;
  97.    
  98.         circle_radius = saturate( cor * 20.0) ; // r0.x, line 21
  99.     }
  100.        
  101.    
  102.  
  103.     // * Zooming effect
  104.     float2 offsetUV = 0;
  105.     float2 colorUV = 0;
  106.     {
  107.         float2 uv4  = 2 * PosH.xy;
  108.         uv4 /= cb0_v2.xy;
  109.         uv4 -= float2(1.0, 1.0);
  110.        
  111.         float mask3  = dot(uv4, uv4);
  112.         uv4 *= mask3;
  113.        
  114.         float attenuation = fisheyeAmount * 0.1;
  115.         uv4 *= attenuation;
  116.        
  117.         offsetUV = clamp( uv4, float2(-0.4, -0.4), float2(0.4, 0.4) );
  118.         offsetUV *= zoomAmount;
  119.        
  120.         float2 uv = PosH.xy * invTexSize; // main uv
  121.         colorUV = uv - offsetUV*amount;
  122.     }
  123.    
  124.    
  125.     // * Sample color map
  126.     float3 color = texture0.Sample( sampler0, colorUV ).rgb; // r2.xyz
  127.    
  128.    
  129.     // * Sample outline map
  130.    
  131.     // interesting objects (upper left square)
  132.     float2 outlineUV = colorUV * 0.5;
  133.     float outlineInteresting = texture2.Sample( sampler2, outlineUV ).x; // r0.y
  134.    
  135.     // traces (upper right square)
  136.     outlineUV = colorUV * 0.5  + float2(0.5, 0.0);
  137.     float outlineTraces = texture2.Sample( sampler2, outlineUV ).x;  // r2.w
  138.    
  139.    
  140.     outlineInteresting /= 8.0; // r4.x
  141.     outlineTraces /= 8.0; // r4.y
  142.    
  143.     float timeParam =  time * 0.1;
  144.    
  145.     // adjust circle radius
  146.     circle_radius = 1.0 - circle_radius;
  147.     circle_radius *= 0.03;
  148.    
  149.     float3 color_circle_main = float3(0.0, 0.0, 0.0);
  150.    
  151.     [loop]
  152.     for (int i=0; 8 > i; i++)
  153.     {
  154.         // full 2*PI = 360 angles cycle
  155.         const float angleRadians = (float) i * PI_4 - timeParam;
  156.        
  157.         // unit circle
  158.         float2 unitCircle;
  159.         sincos(angleRadians, unitCircle.y, unitCircle.x); // unitCircle.x = cos, unitCircle.y = sin
  160.        
  161.         // adjust radius
  162.         unitCircle *= circle_radius;
  163.        
  164.         // * base texcoords (circle) - note we also scale radius here by 8
  165.         // * probably because of dimensions of outline map.
  166.         // line 55
  167.         float2 uv_outline_base = colorUV + unitCircle / 8.0;
  168.                
  169.         // * interesting objects (circle)
  170.         float2 uv_outline_interesting_circle = uv_outline_base * 0.5;
  171.         float outline_interesting_circle  = texture2.Sample( sampler2, uv_outline_interesting_circle ).x;
  172.         outlineInteresting += outline_interesting_circle / 8.0;
  173.        
  174.         // * traces (circle)
  175.         float2 uv_outline_traces_circle =  uv_outline_base * 0.5 + float2(0.5, 0.0);
  176.         float outline_traces_circle  = texture2.Sample( sampler2, uv_outline_traces_circle ).x;
  177.         outlineTraces += outline_traces_circle / 8.0;
  178.        
  179.         // * sample color texture with perturbation
  180.         float2 uv_color_circle  = colorUV + unitCircle * offsetUV;
  181.         float3 color_circle = texture0.Sample( sampler0, uv_color_circle ).rgb;
  182.         color_circle_main += color_circle / 8.0;
  183.     }
  184.    
  185.     // * Sample intensity map
  186.     float2 intensityMap = texture3.Sample( sampler0, colorUV ).xy;
  187.    
  188.     float intensityInteresting = intensityMap.r;
  189.     float intensityTraces = intensityMap.g;
  190.    
  191.     // * Adjust outlines
  192.     float mainOutlineInteresting = saturate( outlineInteresting - 0.8*intensityInteresting );
  193.     float mainOutlineTraces = saturate( outlineTraces - 0.75*intensityTraces );
  194.    
  195.     // * Greyish color
  196.     float3 color_greyish = dot( color_circle_main, float3(0.3, 0.3, 0.3) ).xxx;
  197.    
  198.     // * Determine main color.
  199.     // (1) At first, combine "circled" color with grey one.
  200.     // Now we have have greyish corners here.
  201.     float3 mainColor = lerp(color_greyish, color_circle_main, mask_gray_corners) * 0.6;
  202.    
  203.     // (2) Then mix "regular" color with the above.
  204.     // Please note this operation makes corners gradually grey (because fisheyeAmount rises from 0 to 1).
  205.     mainColor = lerp( color, mainColor, fisheyeAmount );
  206.    
  207.     // * Determine color of witcher senses
  208.     float3 senses_traces = mainOutlineTraces * colorTraces;
  209.     float3 senses_interesting = mainOutlineInteresting * colorInteresting;
  210.  
  211.     // * Slightly boost traces
  212.     float3 senses_total = 1.2 * senses_traces + senses_interesting;
  213.    
  214.     // * Final combining
  215.     float3 senses_total_sat = saturate(senses_total);
  216.     float dot_senses_total = saturate( dot(senses_total, float3(1.0, 1.0, 1.0) ) );
  217.    
  218.     float3 finalColor = lerp( mainColor, senses_total_sat, dot_senses_total );
  219.     return float4( finalColor, 1.0 );
  220. }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
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
Top