Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //UNITY CODE START
- (Samplers)
- texFeedback = new RenderTexture(src.width, src.height, 0);
- texFeedback.hideFlags = HideFlags.HideAndDontSave;
- texFeedback.filterMode = FilterMode.Point;
- texFeedback.Create();
- DestroyImmediate(texFeedback2); //clearTex(texFeedback2);
- texFeedback2 = new RenderTexture(src.width, src.height, 0);
- texFeedback2.hideFlags = HideFlags.HideAndDontSave;
- texFeedback2.filterMode = FilterMode.Point;
- texFeedback2.Create();
- DestroyImmediate(texLast); //clearTex(texLast);
- texLast = new RenderTexture(src.width, src.height, 0);
- texLast.hideFlags = HideFlags.HideAndDontSave;
- texLast.filterMode = FilterMode.Point;
- texLast.Create();
- (Code)
- (PIXELSHADER3)
- _MainTex ("Render Input", 2D) = "white" {} //current frame without feedback
- _LastTex ("Render Input", 2D) = "white" {} //latest frame without feedback
- _FeedbackTex ("Render Input", 2D) = "white" {} //feedback buffer
- float2 p = i.uvn;// gl_FragCoord.xy / iResolution.xy;
- float one_x = 1.0/_ScreenParams.x;
- feedbackColor = half3(1.0,0.5,0.0);
- //new feedback value
- half3 fc = tex2D( _MainTex, i.uvn).rgb; //current frame without feedback
- half3 fl = tex2D( _LastTex, i.uvn).rgb; //last frame without feedback
- float diff = abs(fl.x-fc.x + fl.y-fc.y + fl.z-fc.z)/3.0; //dfference between frames
- if(diff<feedbackThresh) diff = 0.0;
- half3 fbn = fc*diff*feedbackAmount; //feedback new
- // fbn = half3(0.0, 0.0, 0.0);
- //old feedback buffer
- half3 fbb = half3(0.0, 0.0, 0.0);
- // fbb = tex2D( _FeedbackTex, i.uvn).rgb;
- fbb = ( //blur old bufffer a bit
- tex2D( _FeedbackTex, i.uvn).rgb +
- tex2D( _FeedbackTex, i.uvn + float2(one_x, 0.0)).rgb +
- tex2D( _FeedbackTex, i.uvn - float2(one_x, 0.0)).rgb
- ) / 3.0;
- fbb *= feedbackFade;
- fbn = bm_screen(fbn, fbb);
- return half4(fbn*feedbackColor, 1.0);
- (PIXELSHADER4)
- float2 p = i.uvn;
- half3 col = tex2D( _MainTex, i.uvn).rgb; //curent frame
- half3 fbb = tex2D( _FeedbackTex, i.uvn).rgb; //feedback buffer
- col = bm_screen(col, fbb*feedbackAmp);
- // col = col+ fbb*feedbackAmp;
- return half4(col, 1.0);
- (passes)
- mat3.SetTexture("_LastTex", texLast);
- mat3.SetTexture("_FeedbackTex", texFeedback);
- Graphics.Blit (texPass23, texFeedback2, mat3);
- Graphics.Blit (texFeedback2, texFeedback);
- Graphics.Blit (texFeedback, dest);
- //RESHADE CODE START
- (samplers)
- texture2D RFX_backbufferTex : COLOR;
- texture2D VHScurrTex { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
- texture2D VHSprevSingleTex { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
- texture2D VHSprevTex { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
- sampler2D RFX_backbufferColor { Texture = RFX_backbufferTex; };
- sampler2D VHScurrColor { Texture = VHScurrTex; };
- sampler2D VHSprevSingleColor { Texture = VHSprevSingleTex; };
- sampler2D VHSprevColor { Texture = VHSprevTex; };
- (code)
- (From Framework, sorry Medie)
- float4 PS_VHSCopyFrame(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
- {
- return tex2D(RFX_backbufferColor, texcoord);
- }
- (Also from Framework, sorry Medie)
- void PS_VHSCopyPreviousFrame(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 prevSingle : SV_Target0, out float4 prev : SV_Target1)
- {
- prevSingle = tex2D(VHScurrColor, texcoord);
- prev = tex2D(RFX_backbufferColor, texcoord);
- }
- float3 bm_screen(float3 a, float3 b){ return 1.0- (1.0-a)*(1.0-b); }
- (PIXELSHADER3)
- float2 p = texcoord.xy;// gl_FragCoord.xy / iResolution.xy;
- float3 feedbackColor = float3(0.0,0.0,0.0);
- feedbackColor = float3(1.0,0.5,0.0);
- //new feedback value
- float3 fc = tex2D( VHScurrColor, texcoord.xy).rgb; //current frame without feedback
- float3 fl = tex2D( VHSprevSingleColor, texcoord.xy).rgb; //last frame without feedback
- float diff = abs(fl.x-fc.x + fl.y-fc.y + fl.z-fc.z)/3.0; //dfference between frames
- if(diff<feedbackThresh) diff = 0.0;
- float3 fbn = fc*diff*feedbackAmount; //feedback new
- // fbn = float3(0.0, 0.0, 0.0);
- //old feedback buffer
- float3 fbb = float3(0.0, 0.0, 0.0);
- // fbb = tex2D( _FeedbackTex, i.uvn).rgb;
- fbb = ( //blur old bufffer a bit
- tex2D( VHSprevColor , texcoord.xy).rgb +
- tex2D( VHSprevColor, texcoord.xy + float2(PixelSize.x, 0.0)).rgb +
- tex2D( VHSprevColor, texcoord.xy - float2(PixelSize.x, 0.0)).rgb
- ) / 3.0;
- fbb *= feedbackFade;
- fbn = bm_screen(fbn, fbb);
- return float4(fbn*feedbackColor, 1.0);
- (PIXELSHADER4)
- float2 p = texcoord.xy;
- float3 col = tex2D( VHScurrColor, texcoord.xy).rgb; //curent frame
- float3 fbb = tex2D( VHSprevColor, texcoord.xy).rgb; //feedback buffer
- col = bm_screen(col, fbb*feedbackAmp);
- // col = col+ fbb*feedbackAmp;
- return float4(col, 1.0);
- (passes)
- pass HVS3
- {
- VertexShader = VS_PostProcess;
- PixelShader = PS_VHS3;
- }
- pass HVS4
- {
- VertexShader = VS_PostProcess;
- PixelShader = PS_VHS4;
- RenderTarget = VHScurrTex;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement