Advertisement
Guest User

Untitled

a guest
Feb 18th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.14 KB | None | 0 0
  1. //UNITY CODE START
  2.  
  3. (Samplers)
  4. texFeedback = new RenderTexture(src.width, src.height, 0);
  5. texFeedback.hideFlags = HideFlags.HideAndDontSave;
  6. texFeedback.filterMode = FilterMode.Point;
  7. texFeedback.Create();
  8.  
  9. DestroyImmediate(texFeedback2); //clearTex(texFeedback2);
  10. texFeedback2 = new RenderTexture(src.width, src.height, 0);
  11. texFeedback2.hideFlags = HideFlags.HideAndDontSave;
  12. texFeedback2.filterMode = FilterMode.Point;
  13. texFeedback2.Create();
  14.  
  15. DestroyImmediate(texLast); //clearTex(texLast);
  16. texLast = new RenderTexture(src.width, src.height, 0);
  17. texLast.hideFlags = HideFlags.HideAndDontSave;
  18. texLast.filterMode = FilterMode.Point;
  19. texLast.Create();
  20.  
  21. (Code)
  22.  
  23. (PIXELSHADER3)
  24. _MainTex ("Render Input", 2D) = "white" {} //current frame without feedback
  25. _LastTex ("Render Input", 2D) = "white" {} //latest frame without feedback
  26. _FeedbackTex ("Render Input", 2D) = "white" {} //feedback buffer
  27.  
  28.  
  29. float2 p = i.uvn;// gl_FragCoord.xy / iResolution.xy;
  30. float one_x = 1.0/_ScreenParams.x;
  31. feedbackColor = half3(1.0,0.5,0.0);
  32.  
  33. //new feedback value
  34. half3 fc = tex2D( _MainTex, i.uvn).rgb; //current frame without feedback
  35. half3 fl = tex2D( _LastTex, i.uvn).rgb; //last frame without feedback
  36. float diff = abs(fl.x-fc.x + fl.y-fc.y + fl.z-fc.z)/3.0; //dfference between frames
  37. if(diff<feedbackThresh) diff = 0.0;
  38.  
  39. half3 fbn = fc*diff*feedbackAmount; //feedback new
  40. // fbn = half3(0.0, 0.0, 0.0);
  41.  
  42.  
  43. //old feedback buffer
  44. half3 fbb = half3(0.0, 0.0, 0.0);
  45. // fbb = tex2D( _FeedbackTex, i.uvn).rgb;
  46. fbb = ( //blur old bufffer a bit
  47. tex2D( _FeedbackTex, i.uvn).rgb +
  48. tex2D( _FeedbackTex, i.uvn + float2(one_x, 0.0)).rgb +
  49. tex2D( _FeedbackTex, i.uvn - float2(one_x, 0.0)).rgb
  50. ) / 3.0;
  51. fbb *= feedbackFade;
  52.  
  53. fbn = bm_screen(fbn, fbb);
  54. return half4(fbn*feedbackColor, 1.0);
  55.  
  56. (PIXELSHADER4)
  57. float2 p = i.uvn;
  58.  
  59. half3 col = tex2D( _MainTex, i.uvn).rgb; //curent frame
  60. half3 fbb = tex2D( _FeedbackTex, i.uvn).rgb; //feedback buffer
  61.  
  62. col = bm_screen(col, fbb*feedbackAmp);
  63. // col = col+ fbb*feedbackAmp;
  64.  
  65. return half4(col, 1.0);
  66.  
  67. (passes)
  68. mat3.SetTexture("_LastTex", texLast);
  69. mat3.SetTexture("_FeedbackTex", texFeedback);
  70.  
  71. Graphics.Blit (texPass23, texFeedback2, mat3);
  72. Graphics.Blit (texFeedback2, texFeedback);
  73. Graphics.Blit (texFeedback, dest);
  74.  
  75. //RESHADE CODE START
  76.  
  77. (samplers)
  78.  
  79. texture2D RFX_backbufferTex : COLOR;
  80. texture2D VHScurrTex { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
  81. texture2D VHSprevSingleTex { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
  82. texture2D VHSprevTex { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
  83.  
  84. sampler2D RFX_backbufferColor { Texture = RFX_backbufferTex; };
  85. sampler2D VHScurrColor { Texture = VHScurrTex; };
  86. sampler2D VHSprevSingleColor { Texture = VHSprevSingleTex; };
  87. sampler2D VHSprevColor { Texture = VHSprevTex; };
  88.  
  89. (code)
  90.  
  91. (From Framework, sorry Medie)
  92. float4 PS_VHSCopyFrame(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
  93. {
  94. return tex2D(RFX_backbufferColor, texcoord);
  95. }
  96.  
  97. (Also from Framework, sorry Medie)
  98. void PS_VHSCopyPreviousFrame(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 prevSingle : SV_Target0, out float4 prev : SV_Target1)
  99. {
  100. prevSingle = tex2D(VHScurrColor, texcoord);
  101. prev = tex2D(RFX_backbufferColor, texcoord);
  102. }
  103.  
  104. float3 bm_screen(float3 a, float3 b){ return 1.0- (1.0-a)*(1.0-b); }
  105.  
  106.  
  107. (PIXELSHADER3)
  108. float2 p = texcoord.xy;// gl_FragCoord.xy / iResolution.xy;
  109. float3 feedbackColor = float3(0.0,0.0,0.0);
  110. feedbackColor = float3(1.0,0.5,0.0);
  111.  
  112. //new feedback value
  113. float3 fc = tex2D( VHScurrColor, texcoord.xy).rgb; //current frame without feedback
  114. float3 fl = tex2D( VHSprevSingleColor, texcoord.xy).rgb; //last frame without feedback
  115. float diff = abs(fl.x-fc.x + fl.y-fc.y + fl.z-fc.z)/3.0; //dfference between frames
  116. if(diff<feedbackThresh) diff = 0.0;
  117.  
  118. float3 fbn = fc*diff*feedbackAmount; //feedback new
  119. // fbn = float3(0.0, 0.0, 0.0);
  120.  
  121.  
  122. //old feedback buffer
  123. float3 fbb = float3(0.0, 0.0, 0.0);
  124. // fbb = tex2D( _FeedbackTex, i.uvn).rgb;
  125. fbb = ( //blur old bufffer a bit
  126. tex2D( VHSprevColor , texcoord.xy).rgb +
  127. tex2D( VHSprevColor, texcoord.xy + float2(PixelSize.x, 0.0)).rgb +
  128. tex2D( VHSprevColor, texcoord.xy - float2(PixelSize.x, 0.0)).rgb
  129. ) / 3.0;
  130.  
  131. fbb *= feedbackFade;
  132.  
  133. fbn = bm_screen(fbn, fbb);
  134. return float4(fbn*feedbackColor, 1.0);
  135.  
  136. (PIXELSHADER4)
  137.  
  138. float2 p = texcoord.xy;
  139.  
  140. float3 col = tex2D( VHScurrColor, texcoord.xy).rgb; //curent frame
  141. float3 fbb = tex2D( VHSprevColor, texcoord.xy).rgb; //feedback buffer
  142.  
  143. col = bm_screen(col, fbb*feedbackAmp);
  144. // col = col+ fbb*feedbackAmp;
  145.  
  146. return float4(col, 1.0);
  147.  
  148. (passes)
  149. pass HVS3
  150. {
  151. VertexShader = VS_PostProcess;
  152. PixelShader = PS_VHS3;
  153. }
  154. pass HVS4
  155. {
  156. VertexShader = VS_PostProcess;
  157. PixelShader = PS_VHS4;
  158. RenderTarget = VHScurrTex;
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement