Meta pass and Precomputed Realtime GI Question

Hey everyone,

I am writing a shader and I would like to use some special values for the precomputed realtime GI. I am using a vertex fragment shader as it seems that it offers much more controls than a surface shader.

Unfortunately it doesn’t seems possible as the data used in the meta pass are static, I mean they come from the static textures used in the material and the colors or values transformation applied.
As an example, if I make some modification on the self-illumination value in any other pass other than the meta pass, the result is not applied.

Is there a way to use the data calculated in the forwardbase pass or forwardadd pass or from any other pass ? Is there maybe another way to do that maybe using Command buffers ?

If someone could give me a clue it would help me so much because for the moment I don’t see any way to do that.
Thank you very much.

Any idea ?

Shader "Custom/orangeShader"{

    Properties {
        _Color ("Color", Color)=(1,1,1,1)
        _MainTex ("Albedo (RGB)",2D)="white"{}
        _Glossiness ("Smoothness", Range(0,1))=0.5
        _Metallic ("Metallic", Range(0,1))=0.0

        _GIAlbedoColor ("Color Albedo (GI)", Color)=(1,1,1,1)
        _GIAlbedoTex ("Albedo (GI)",2D)="white"{}
    }

    SubShader {
    // ------------------------------------------------------------------
    // Extracts information for lightmapping, GI (emission, albedo, ...)
    // This pass it not used during regular rendering.
        Pass
        {
            Name "META"
            Tags {"LightMode"="Meta"}
            Cull Off
            CGPROGRAM

            #include"UnityStandardMeta.cginc"

            sampler2D _GIAlbedoTex;
            fixed4 _GIAlbedoColor;
            float4 frag_meta2 (v2f_meta i): SV_Target
            {
                // we're interested in diffuse & specular colors,
                // and surface roughness to produce final albedo.
               
                FragmentCommonData data = UNITY_SETUP_BRDF_INPUT (i.uv);
                UnityMetaInput o;
                UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o);
                fixed4 c = tex2D (_GIAlbedoTex, i.uv);
                o.Albedo = fixed3(c.rgb * _GIAlbedoColor.rgb);
                o.Emission = Emission(i.uv.xy);
                return UnityMetaFragment(o);
            }
           
            #pragma vertex vert_meta
            #pragma fragment frag_meta2
            #pragma shader_feature _EMISSION
            #pragma shader_feature _METALLICGLOSSMAP
            #pragma shader_feature ___ _DETAIL_MULX2
            ENDCG
        }
       
        Tags {"RenderType"="Opaque"}
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows nometa
        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input {
            float2 uv_MainTex;
        };
       
        half _Glossiness;
        half _Metallic;
        fixed4 _Color;
       
        void surf (Input IN,inout SurfaceOutputStandard o){
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex)* _Color;
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }

    FallBack "Diffuse"
}

Thank you @KEngelstoft
I am also wondering if there is an easy way to transfer the results calculated in the forwardbase, forwardadd or deferred pass to the meta pass.
The only way to do that in my opinion is to use a new buffer but this will result in calculating the lighting twice and constrain it to screenspace, no ?

To make it quick do you have any clue or idea on how transferring the lighting data to the meta pass (deferred and forward). Because I am trying to send my translucency results calculated in forwardadd and deferred pass to the meta pass.

You should render the translucency information into a render target and sample that as a texture in the meta pass. That way you don’t have to do the lighting calculation twice.

@KEngelstoft Could you be a bit more explicit about the process of using a render target to sample the result of the forward or deferred lighting pass in the meta pass ? I’ve already tried render target but I didn’t really dig into it and I didn’t achieved to make it work. I also didn’t found any tutorial about it.

Just to know, the result will be in screenspace so, everything outside screen won’t be taken into account.

Remember that the meta pass is running in lightmap space, so you have to calculate the translucency results in the same space and there will be a 1-to-1 mapping from your translucency to the meta pass.

@KEngelstoft Thank you for all you help. This might be a little off-topic but as this is the first time I’ll be using RenderTargets, I have some difficulties about understanding the whole process of using it with all the passes (deferred, forwardadd). And there is the lightmap space calculation I need to dig it too. :slight_smile:
I can output the result of those passes to another rendering target in addition to its regular output ? How ?

Thank you again for all the precisions you’re giving. I hope this will be useful to someone else too. :slight_smile: