Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

[ad_1]

Here’s a fragment shader I wrote that makes use of a seize move to copy an “common coloration” mix mode

Shader "2DSB/VertexColor" 
{
    Properties
    {
        [PerRendererData] _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
        _Color ("Principal Coloration", Coloration) = (1, 1, 1, 1)
    }

    SubShader
    {
        Tags {"Queue"="Clear" "IgnoreProjector"="True" "RenderType"="Clear"}
        ZWrite Off
        Lighting Off
        Cull Off
        Fog { Mode Off }
        //Earlier: Mix SrcAlpha OneMinusSrcAlpha
        Mix SrcAlpha Zero
        LOD 100

        // Add GrabPass to seize the present body buffer
        GrabPass { } // "_GrabTexture" is the title of the grabbed texture
        
        Cross
        {
            CGPROGRAM
            #pragma vertex vert_vct
            #pragma fragment frag_mult
            #pragma fragmentoption ARB_precision_hint_fastest
            #embrace "UnityCG.cginc"

            sampler2D _MainTex;
            float4 _MainTex_ST;
            sampler2D _GrabTexture;
            float4 _GrabTexture_ST;
            float4 _Color;

            struct vin_vct
            {
                float4 vertex : POSITION;
                float4 coloration : COLOR;
                float2 texcoord : TEXCOORD0;
            };

            struct v2f_vct
            {
                float4 vertex : SV_POSITION;
                fixed4 coloration : COLOR;
                float2 texcoord : TEXCOORD0;
                float2 screenspaceUV : TEXCOORD1; // Add display screen area UV
            };

            v2f_vct vert_vct(vin_vct v)
            {
                v2f_vct o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.coloration = v.coloration;
                o.texcoord = v.texcoord;
                o.screenspaceUV = ComputeScreenPos(o.vertex).xy; // Compute display screen area place
                return o;
            }

            fixed4 frag_mult(v2f_vct i) : SV_Target
            {
                fixed4 srcColor = tex2D(_MainTex, i.texcoord) * i.coloration * _Color;
                fixed4 dstColor = tex2D(_GrabTexture, i.screenspaceUV); // Coloration from the body buffer; Use display screen area UV to pattern
                
                // Customized logic to common the colours
                fixed4 finalColor = srcColor;
                if (any(dstColor.rgba > fixed4(0,0,0,0).rgba)) { // Why is that this by no means true, even when there's overlap between sport objects?
                    finalColor = (srcColor + dstColor) * 0.5; // Easy averaging
                    //Take a look at: finalColor = fixed4(1,0,0,1);
                }

                return finalColor;
            }
            
            ENDCG
        } 
    }
}

The large drawback is that the sampled _GrabTexture is at all times empty. I do know this as a result of this block was by no means true.

if (any(dstColor.rgba > fixed4(0,0,0,0).rgba)) { // Why is that this by no means true, even when there's overlap between sport objects?
                    finalColor = (srcColor + dstColor) * 0.5; // Easy averaging
                    //Take a look at: finalColor = fixed4(1,0,0,1);
                }

Nonetheless, this needs to be true for areas the place there are overlapping sport objects. What’s the challenge right here? How do I appropriately pattern the present body buffer’s texture utilizing GrabPass to implement a median colours mix mode?

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *