SHARE
TWEET

The Witcher 3 - witcher senses (outline map) 1.0

a guest Apr 5th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // RenderDoc compatible
  2. // No HLSL available - function stub generated
  3.  
  4. //SamplerComparisonState sampler0 : register(s0); // can't disambiguate
  5. SamplerState sampler0 : register(s0); // can't disambiguate
  6. //SamplerComparisonState sampler1 : register(s1); // can't disambiguate
  7. SamplerState sampler1 : register(s1); // can't disambiguate
  8. Texture2D texOutlineMap : register(t0);
  9. Texture2D texIntensityMap : register(t1);
  10.  
  11.  
  12. cbuffer cbuffer3 : register(b3) {
  13.     float4 cb3_v0;
  14. };
  15.  
  16.  
  17.  
  18. struct FSInput
  19. {
  20.     float4 param0 : SV_Position;
  21.     float4 param1 : COLOR;
  22.     float4 param2 : TEXCOORD;
  23. };
  24.  
  25. struct FSOutput
  26. {
  27.     float4 param0 : SV_Target0;
  28. };
  29.  
  30. float getParams(float2 uv)
  31. {
  32.     float d = dot(uv, uv);
  33.     d = 1.0 - d;
  34.     d = max( d, 0.0 );
  35.  
  36.     return d;
  37. }
  38.  
  39.  // For more details see: http://libnoise.sourceforge.net/noisegen/  
  40. float integerNoise( int n )
  41. {  
  42.      n = (n >> 13) ^ n;  
  43.      int nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;  
  44.      return ((float)nn / 1073741824.0);  
  45. }  
  46.  
  47. FSOutput EditedShaderPS(in FSInput IN)
  48. {
  49.     FSOutput OUT = (FSOutput)0;
  50.    
  51.     // * Inputs
  52.     float2 uv = IN.param2.xy;
  53.     float dampingParam = saturate( cb3_v0.x );
  54.     float2 noiseAnimation = cb3_v0.zw;
  55.    
  56.     // * Split texture in four equal parts
  57.     // 0: add r0.xyzw, v2.xyxy, v2.xyxy  
  58.     float2 TextureUV = 2 * uv;
  59.    
  60.     // 1: round_ni r1.xy, r0.zwzz
  61.     float2 flooredTextureUV = floor( TextureUV );
  62.    
  63.     // 2: frc r0.xyzw, r0.xyzw
  64.     TextureUV = frac( TextureUV );
  65.    
  66.     // 3-14
  67.     float2 uv1 = flooredTextureUV;
  68.     float2 uv2 = flooredTextureUV + float2(-1.0, -0.0);
  69.     float2 uv3 = flooredTextureUV + float2( -0.0, -1.0);
  70.     float2 uv4 = flooredTextureUV + float2(-1.0, -1.0);
  71.  
  72.     float4 corners;
  73.     corners.x = getParams( uv1 );
  74.     corners.y = getParams( uv2 );
  75.     corners.z = getParams( uv3 );
  76.     corners.w = getParams( uv4 );
  77.  
  78.     //  15: sample_indexable(texture2d)(float,float,float,float) r1.xyzw, r0.zwzz, t1.xyzw, s1
  79.     float4 texIntensity = texIntensityMap.Sample( sampler1, TextureUV );
  80.    
  81.     float masterFilter = dot(texIntensity, corners);
  82.    
  83.     // 17: add r2.xyzw, r0.zwzw, l(0.003906, 0.000000, -0.003906, 0.000000)  
  84.     // 18: add r0.xyzw, r0.xyzw, l(0.000000, 0.003906, 0.000000, -0.003906)  
  85.    
  86.    
  87.     // * Generate outlines
  88.     float fTexel = 1.0 / 256;
  89.    
  90.     float2 sampling1 = TextureUV + float2( fTexel, 0 );
  91.     float2 sampling2 = TextureUV + float2( -fTexel, 0 );
  92.     float2 sampling3 = TextureUV + float2( 0, fTexel );
  93.     float2 sampling4 = TextureUV + float2( 0, -fTexel );
  94.    
  95.     float2 intensity_x0 = texIntensityMap.Sample( sampler1, sampling1 ).xy;
  96.     float2 intensity_x1 = texIntensityMap.Sample( sampler1, sampling2 ).xy;
  97.     float2 intensity_diff_x = intensity_x0 - intensity_x1;
  98.    
  99.     float2 intensity_y0 = texIntensityMap.Sample( sampler1, sampling3 ).xy;
  100.     float2 intensity_y1 = texIntensityMap.Sample( sampler1, sampling4 ).xy;
  101.     float2 intensity_diff_y = intensity_y0 - intensity_y1;
  102.    
  103.     float2 maxAbsDifference = max( abs(intensity_diff_x), abs(intensity_diff_y) );
  104.     maxAbsDifference = saturate(maxAbsDifference);
  105.    
  106.     // Outlines here
  107.     float2 outlines = masterFilter * maxAbsDifference;
  108.    
  109.    
  110.    
  111.     // Sample outline map
  112.     float2 outlineMap =  texOutlineMap.Sample( sampler0, uv ).xy;
  113.    
  114.     float paramOutline = masterFilter*0.15 + outlineMap.y;
  115.     paramOutline += 0.35 * outlines.r;
  116.     paramOutline += 0.35 * outlines.g;
  117.  
  118.    
  119.     // input for integer noise
  120.     float2 noiseInputs = 150*uv + 300.0 * noiseAnimation;
  121.     int2 iNoiseInputs = (int2) noiseInputs;
  122.    
  123.     // calc noise
  124.     float noise0 = 0.65 + integerNoise( iNoiseInputs.x + reversebits(iNoiseInputs.y) ); // r0.y
  125.    
  126.    
  127.     // sampling of outline map
  128.     fTexel = 1.0 / 512.0;
  129.    
  130.     sampling1 = saturate( uv + float2( fTexel, 0 ) );
  131.     sampling2 = saturate( uv + float2( -fTexel, 0 ) );
  132.     sampling3 = saturate( uv + float2( 0, fTexel ) );
  133.     sampling4 = saturate( uv + float2( 0, -fTexel ) );
  134.    
  135.     float outline_x0 = texOutlineMap.Sample( sampler0, sampling1 ).x;
  136.     float outline_x1 = texOutlineMap.Sample( sampler0, sampling2 ).x;
  137.     float outline_y0 = texOutlineMap.Sample( sampler0, sampling3 ).x;
  138.     float outline_y1 = texOutlineMap.Sample( sampler0, sampling4 ).x;
  139.     float averageOutline = (outline_x0+outline_x1+outline_y0+outline_y1) / 4.0;
  140.    
  141.     // * perturb the difference with noise
  142.     float frameOutlineDifference = averageOutline - outlineMap.x;
  143.     frameOutlineDifference *= noise0;
  144.    
  145.     //  56: mul r0.y, r0.y, r0.z
  146.     // the main place with gives blocky look of texture
  147.     float newNoise = outlineMap.x * noise0;
  148.    
  149.     float newOutline = frameOutlineDifference * 0.9 + paramOutline;
  150.     newOutline -= 0.24*newNoise;
  151.    
  152.     // 59: add r0.x, r0.y, r0.z
  153.     float2 finalOutline = float2( outlineMap.x + newOutline, newOutline);
  154.    
  155.     // * calculate damping
  156.     dampingParam = pow( dampingParam, 100 );  
  157.     float damping = 0.7 + 0.16*dampingParam;
  158.    
  159.     // * final multiplication
  160.     OUT.param0.xy = finalOutline * damping;
  161.  
  162.     return OUT;
  163. }
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
 
Top