Git Product home page Git Product logo

urp_blitrenderfeature's Introduction

Blit Renderer Feature

  • Used to apply fullscreen image effects to camera (or other source/destination) using a shader/material.
  • Tested with 2021.2 and 2021.3 (~ URP v12). For other versions, see branches.
  • Note : Unity/URP 2022.2+ now has a Fullscreen Graph and built-in Fullscreen Pass Renderer Feature which essentially replaces this feature when blitting using camera targets. (But if you want more injection points and different destinations see the 2022.1 branch)
  • This version uses CommandBuffer.Blit so will not work in Single-Pass Instanced VR. Try using cmd-DrawMesh version instead.

Setup:

  • Install via Package Manager → Add package via git URL :
    • https://github.com/Cyanilux/URP_BlitRenderFeature.git
  • Alternatively, download and put the folder in your Assets

Usage :

  • Adds "Blit" option to Renderer Features list on Forward/Universal asset (and 2D Renderer if in 2021.2+)
  • The shader/material used should sample _MainTex to obtain source. Will work with Shader Graphs too (as long as you set the texture Reference in the Blackboard / Node Settings)
  • Feature allows specific access to selecting the source and destination targets (via Camera, TextureID or Render Texture object)
  • Some usage examples :
    • Could be used with Camera for both source/destination to apply an shader/material as an image effect / post process
    • Could be used to copy the camera source to a TextureID. Similar to what the Opaque Texture / Scene Color does. (When TextureID is used in destination it automatically creates a Temporary Render Texture, and should also set it as a global texture so it can be obtained in shaders rendered later. May want to avoid using IDs that already exist)
    • Could be used with Render Texture object source (rendered by a second camera) and Camera destination to apply it to the Main Camera

Additional Features :

  • Option to set an _InverseView matrix (cameraToWorldMatrix), for shaders that might need it to handle calculations from screen space to world. For example, reconstructing world position from depth, see : https://twitter.com/Cyanilux/status/1269353975058501636
  • (2020.2/v10+) Enabling generation of DepthNormals (_CameraNormalsTexture)

Author / Sources :

urp_blitrenderfeature's People

Contributors

cyanilux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

urp_blitrenderfeature's Issues

cmd-drawMesh and depth texture

I just tried switching to cmd-drawMesh but can't figure out how to get the depth texture. It seems that the screenmesh is included somehow?

Fixing obsolete and deprecated warnings using RTHandle

I get the following warning on compile:

'RenderTargetHandle' is obsolete: 'Deprecated in favor of RTHandle'

'ScriptableRenderPass.Blit(CommandBuffer, RenderTargetIdentifier, RenderTargetIdentifier, Material, int)' is obsolete: 'Use RTHandles for source and destination'

'ScriptableRenderer.cameraColorTarget' is obsolete: 'Use cameraColorTargetHandle'

The last one is easy to fix, simply switching to "cameraColorTargetHandle" works.

Changing m_TemporaryColorTexture and m_DestinationTexture are similarly easy, following this guide:

https://forum.unity.com/threads/rendertargethandle-is-obsolete-deprecated-in-favor-of-rthandle.1211052/

But any further change proved extremely hard to fix and debug.

It seems transparent material can't work

I have a shader like this

Shader "Custom/AnimeLine"
{
    Properties
    {
        _BaseColor("BaseColor", Color) = (1, 1, 1, 1)
        _SecondColor("Second Color", Color) = (1,1,1,1)
//        _thirdColor("Third Color", Color) = (1,1,1,1)
        _BaseMap("BaseMap", 2D) = "white" {}
        _Center ("Center", Vector) = (0.5, 0.5, 0, 0)
        _RotateSpeed ("Rotate Speed", Range(0,5)) = 0.2
        _RayMultiply ("RayMultiply", Range(0.001, 10)) = 7.5
        _RayPower ("RayPower", Range(0, 15)) = 3.22
        _Threshold ("Threshold", Range(0, 1)) = 1
    }

    SubShader
    {
        Tags { "Queue" = "Transparent" "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True" }

        Pass
        {
            Tags {"LightMode" = "UniversalForward"}
            
            Blend SrcAlpha OneMinusSrcAlpha
            ZWrite Off

            HLSLPROGRAM
	        #pragma vertex vert
            #pragma fragment frag

            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

            struct Attributes
            {
                float4 positionOS : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct Varyings
            {
                float2 uv : TEXCOORD0;
                float4 positionHCS : SV_POSITION;
            };

            TEXTURE2D(_BaseMap);
            SAMPLER(sampler_BaseMap);

            CBUFFER_START(UnityPerMaterial)
                float4 _BaseMap_ST;
                half4 _BaseColor;
                half4 _SecondColor;
                // half4 _thirdColor;
                half4 _Center;
                half _RotateSpeed;
                half _RayMultiply;
                half _RayPower;
                half _Threshold;
            CBUFFER_END

            Varyings vert(Attributes IN)
            {
                Varyings OUT;
                VertexPositionInputs vertexInput = GetVertexPositionInputs(IN.positionOS.xyz);
                OUT.positionHCS = vertexInput.positionCS;
                OUT.uv = TRANSFORM_TEX(IN.uv, _BaseMap);
                return OUT;
            }

            half4 frag(Varyings IN) : SV_Target
            {
                half2 uv = IN.uv - _Center.xy;

                half angle = radians(_RotateSpeed * _Time.y);

                half sinAngle, cosAngle;
                sincos(angle, sinAngle, cosAngle);

                half2x2 rotateMatrix0 = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle);
                half2 normalizedUV0 = normalize(mul(rotateMatrix0, uv));

                half2x2 rotateMatrix1 = half2x2(cosAngle, sinAngle, -sinAngle, cosAngle);
                half2 normalizedUV1 = normalize(mul(rotateMatrix1, uv));
                
                half4 textureMask = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, normalizedUV0) * SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, normalizedUV1);

                half uvMask = pow(_RayMultiply * length(uv), _RayPower);

                half mask = smoothstep(_Threshold - 0.1, _Threshold + 0.1, textureMask.r * uvMask);

                half mask2 = smoothstep(_Threshold - 0.1, _Threshold + 0.1, textureMask.g * 2 * uvMask);

                // half mask3 = smoothstep(_Threshold - 0.1, _Threshold + 0.1, textureMask.b * 50 * uvMask);

                // half4 res = lerp(lerp(half4(_BaseColor.rgb, mask * _BaseColor.a), half4(_SecondColor.rgb, mask2 * _SecondColor.a), mask2 - mask), half4(_thirdColor.rgb, mask3 * _thirdColor.a), mask3 - mask2 - mask);
                 half4 res = lerp(half4(_BaseColor.rgb, mask * _BaseColor.a), half4(_SecondColor.rgb, mask2 * _SecondColor.a), mask2 - mask);

                return res;
            }
            ENDHLSL
        }
    }
}

And the result is
无标题

I change event to "Before Rendering Post Processing" and it shows my shader works without my expectation. If I set the event to "After Rendering Opaques" it shows nothing.

Can it blend with background?

Single pass VR Support

Hi,

This feature works fine in mono rendering. But for Stereo rendering for VR it just draws a solid colour.
I'm not sure if its a shader issue or not, but im using shader graph.
Unity 2019.4.21f1
URP 7.3.1

Using runtime RenderTexture

Hello, I am using a Render Texture that is generated at runtime when the resolution of the screen changes (I think it is better to render at the native resolution and not above since it will be full screen).

At first, I was using a canvas and a Raw Image, but that didn't feel like the correct way to put the Render Texture onto the screen.

Then I found about this, and It works perfectly with an asset Render Texture but if I change it at runtime unity complains about “Type Mismatch”.
I think it's because the URP Renderer is an asset, and I'm trying to make it reference something that is not an asset.

How can use a runtime Render Texture as a source ?

Avoiding double blit when rendering as image effect

Hi, sorry for the new issue so soon, but diving into the code it's apparent that my usage of the project requires one blit to apply the material, and then another to move back the new data to the main render texture

Is there a simple way to avoid this problem and minimize the number of blits required?

Changing Blit material in run time

Hi, this feature is working fine on my project :)

but I want to ask if there have a way to change blit material in run time through script?
I am not familiar with scriptable render pipeline and I can't find any useful information about it.

It will be a big thanks if you can tell me about it!

White render with cmd-drawMesh

Hey. First, awesome work! I'm trying to setup your WatercolourShaders with an occulus quest 2, and because of XR, I switched the blitRenderFeature to the cmd-drawMesh version.

Without the cmd-drawMesh version,

  • if I play in the editor (processed by the computer and sent to the headset for display), everything is working fine.
  • if I build and play (processed directly by android on the headset), I'm having huge weird color lines over the render in the headset (but I guess it's because of the incompatibility with XR)

With the cmd-drawMesh version,

  • In both case, I'm having only the "outlines" rendered (the ones created by the edge detection in the shadergraph), but everything else is white (sure the effect is cool, but not what I expect ;) ). I'm using the BlitDirectly shader in the "always include" graphic setting, and I can't understand why I'm having this issue...

Any idea how to solve this issue?
Thanks in advance!

Screenshot_1

Possibly broken on 2021.2.2f1, no output at all.

On Unity 2021.2.2f1, the Blit feature does not work. Strangely, it seems to work in the preview window. I have seen this happen with the original blit feature and now it does not work anymore. Is there a fix to this?

Package installation fails with URP 14.0.3 and unity 2022.2.0b10

Tried to add ECS to my project, upgraded URP and unity

Sadly whenever the package manager tries to install BitRenderFeature, it fails with this error

[Package Manager Window] Error adding package: com.cyanilux.urp-blitrenderfeature@https://github.com/Cyanilux/URP_BlitRenderFeature.git.
ENOTEMPTY: directory not empty, rmdir 'pojectdir\Library\PackageCache\.tmp-13968-EFB7LJGCNbRz'
UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()

Rendering artifacts on Quest 2

Hey. Sorry opening another issue and I am uncertain if this is the right place to ask. But I tested the shaders on my machine and pcvr setups. But I also build my game for the Quest 2 but I get these weird "artifacts" when turning the screen white, I also use a fragment shader to do a small "screenshake" but that makes the whole game visually jitter. It feels like the renderer on the oculus does something with / to it.

I am using the 'cmd-drawMesh' branch.

Some added pictures:
image
image

Here you can see the weird lines appearing:
5aba0b27293ecbc1531ae0f5e097b956

ScriptableRenderPass.Blit has been deprecated with 2023.x

Looks like ScriptableRenderPass.Blit is no longer supported with 2023.x. I just tried upgrading to 2023.1.8 (URP-15.0.6) from 2022.3.7 (URP-14.0.8), and am getting the following error message starting on line 115 in the Execute method of URP_BlitRenderFeature/Blit.cs:

ScriptableRenderPass.Blit(...) is obsolete: 'Use RTHandles for source and destination'

ScriptableRenderer.cameraColorTarget, and RendererTargetHandle have been marked as deprecated as well, but aren't yet throwing an error.

z split cam

would you know how this can be used to render foreground (0.1 to 20 units) at normal resolution and background (20 unit to 100) at 1/16 resolution?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.