Page 1 of 3

GrabPass in Deferred

PostPosted: Mon Jun 25, 2018 5:20 pm
by Cyntherius
Hi,

is there a way to use a Grab Pass in a Deferred only Shader? I got only a grey Plane. I will create a deferred water surface with refractions but deferred doesn't support transparency. Thanks!

Re: GrabPass in Deferred

PostPosted: Tue Jun 26, 2018 11:32 am
by Ricardo Teixeira
Hello,

Please disregard the previous answer, from your description it seemed to refer to another issue.

The Grab Pass should work as expected in deferred, you might simply need to adjust its Queue Index.

Let us know if the problem persists, we would be more than happy to examine a sample on our side.

Thanks!

Re: GrabPass in Deferred

PostPosted: Tue Jun 26, 2018 1:38 pm
by Cyntherius
Hi, thanks for your reply!

I've testet a bunch of queue indices (stepwise 0 till 3000, on 2501 the object disappears because its deferred mode and cant render semi-transparent). Unfortunately I have no clue whats the problem.

With the "Only Forward" Render Path all things seems to be right. In "Deferred Only" gray/dark/black.

Re: GrabPass in Deferred

PostPosted: Tue Jun 26, 2018 1:47 pm
by Ricardo Teixeira
Cyntherius wrote:Hi, thanks for your reply!

I've testet a bunch of queue indices (stepwise 0 till 3000, on 2501 the object disappears because its deferred mode and cant render semi-transparent). Unfortunately I have no clue whats the problem.

With the "Only Forward" Render Path all things seems to be right. In "Deferred Only" gray/dark/black.


Thank you for getting back to us, can you share a sample shader for further examination?

Thanks!

Re: GrabPass in Deferred

PostPosted: Tue Jun 26, 2018 2:16 pm
by Cyntherius
This is the simplest version of the GrabPass with normal map "distorsion". I want to use the pre-rendered geometry to fake transparency in deferred(!).

Code: Select all
// Made with Amplify Shader Editor
// Available at the Unity Asset Store - http://u3d.as/y3X
Shader "Custom/Deferred Grab Pass"
{
   Properties
   {
      [Normal]_SurfaceNormal("Surface Normal", 2D) = "bump" {}
      _Smoothness("Smoothness", Range( 0 , 1)) = 0
      _Metallic("Metallic", Range( 0 , 1)) = 0
      [HideInInspector] _texcoord( "", 2D ) = "white" {}
      [HideInInspector] __dirty( "", Int ) = 1
   }

   SubShader
   {
      Tags{ "RenderType" = "Opaque"  "Queue" = "Geometry+0" }
      Cull Back
      GrabPass{ }
      CGPROGRAM
      #pragma target 3.0
      #pragma surface surf Standard keepalpha addshadow fullforwardshadows exclude_path:forward
      struct Input
      {
         float4 screenPos;
         float2 uv_texcoord;
      };

      uniform sampler2D _GrabTexture;
      uniform sampler2D _SurfaceNormal;
      uniform float4 _SurfaceNormal_ST;
      uniform float _Metallic;
      uniform float _Smoothness;


      inline float4 ASE_ComputeGrabScreenPos( float4 pos )
      {
         #if UNITY_UV_STARTS_AT_TOP
         float scale = -1.0;
         #else
         float scale = 1.0;
         #endif
         float4 o = pos;
         o.y = pos.w * 0.5f;
         o.y = ( pos.y - o.y ) * _ProjectionParams.x * scale + o.y;
         return o;
      }


      void surf( Input i , inout SurfaceOutputStandard o )
      {
         float4 ase_screenPos = float4( i.screenPos.xyz , i.screenPos.w + 0.00000000001 );
         float4 ase_grabScreenPos = ASE_ComputeGrabScreenPos( ase_screenPos );
         float4 ase_grabScreenPosNorm = ase_grabScreenPos / ase_grabScreenPos.w;
         float2 uv_SurfaceNormal = i.uv_texcoord * _SurfaceNormal_ST.xy + _SurfaceNormal_ST.zw;
         float4 screenColor1 = tex2D( _GrabTexture, ( ase_grabScreenPosNorm + float4( UnpackNormal( tex2D( _SurfaceNormal, uv_SurfaceNormal ) ) , 0.0 ) ).xy );
         o.Albedo = screenColor1.rgb;
         o.Metallic = _Metallic;
         o.Smoothness = _Smoothness;
         o.Alpha = 1;
      }

      ENDCG
   }
   Fallback "Diffuse"
   CustomEditor "ASEMaterialInspector"
}
/*ASEBEGIN
Version=15401
-1073;142;1066;1198;1244.813;865.6038;1.708548;True;False
Node;AmplifyShaderEditor.SamplerNode;4;-655.0253,26.25768;Float;True;Property;_SurfaceNormal;Surface Normal;0;1;[Normal];Create;True;0;0;False;0;None;1b497a628063d62448e26bf495fd985a;True;0;True;bump;Auto;True;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;5;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.GrabScreenPosition;2;-605.5768,-439.6083;Float;False;0;0;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.SimpleAddOpNode;3;-261.8863,-131.3553;Float;False;2;2;0;FLOAT4;0,0,0,0;False;1;FLOAT3;0,0,0;False;1;FLOAT4;0
Node;AmplifyShaderEditor.RangedFloatNode;5;-288,144;Float;False;Property;_Metallic;Metallic;2;0;Create;True;0;0;False;0;0;0;0;1;0;1;FLOAT;0
Node;AmplifyShaderEditor.RangedFloatNode;6;-288,224;Float;False;Property;_Smoothness;Smoothness;1;0;Create;True;0;0;False;0;0;0;0;1;0;1;FLOAT;0
Node;AmplifyShaderEditor.ScreenColorNode;1;-52.77116,-135.7114;Float;False;Global;_GrabScreen0;Grab Screen 0;0;0;Create;True;0;0;False;0;Object;-1;False;False;1;0;FLOAT2;0,0;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.StandardSurfaceOutputNode;0;210,-128;Float;False;True;2;Float;ASEMaterialInspector;0;0;Standard;Custom/Deferred Grab Pass;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;Back;0;False;-1;0;False;-1;False;0;False;-1;0;False;-1;False;0;Opaque;0.5;True;True;0;False;Opaque;;Geometry;DeferredOnly;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;0;False;-1;False;0;False;-1;255;False;-1;255;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;False;2;15;10;25;False;0.5;True;0;0;False;-1;0;False;-1;0;0;False;-1;0;False;-1;-1;False;-1;-1;False;-1;0;False;0;0,0,0,0;VertexOffset;True;False;Cylindrical;False;Relative;0;;-1;-1;-1;-1;0;False;0;0;False;-1;-1;0;False;-1;0;0;16;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;2;FLOAT3;0,0,0;False;3;FLOAT;0;False;4;FLOAT;0;False;5;FLOAT;0;False;6;FLOAT3;0,0,0;False;7;FLOAT3;0,0,0;False;8;FLOAT;0;False;9;FLOAT;0;False;10;FLOAT;0;False;13;FLOAT3;0,0,0;False;11;FLOAT3;0,0,0;False;12;FLOAT3;0,0,0;False;14;FLOAT4;0,0,0,0;False;15;FLOAT3;0,0,0;False;0
WireConnection;3;0;2;0
WireConnection;3;1;4;0
WireConnection;1;0;3;0
WireConnection;0;0;1;0
WireConnection;0;3;5;0
WireConnection;0;4;6;0
ASEEND*/
//CHKSM=6246CBFDEF93CB10312CB4E526B00A21E5FDC790

Re: GrabPass in Deferred

PostPosted: Fri Jun 29, 2018 6:53 pm
by Cyntherius
Something new about the GP in only deferred?

Re: GrabPass in Deferred

PostPosted: Sat Jun 30, 2018 5:02 pm
by Ricardo Teixeira
Cyntherius wrote:Something new about the GP in only deferred?


Hello,

Apologies for the inconvenience, our developers were a bit overloaded this week.

We'll get back to you with additional information as soon as possible.

Thank you for understanding.

Re: GrabPass in Deferred

PostPosted: Mon Jul 02, 2018 1:50 pm
by Ricardo Teixeira
Cyntherius wrote:This is the simplest version of the GrabPass with normal map "distorsion". I want to use the pre-rendered geometry to fake transparency in deferred(!).

Code: Select all
// Made with Amplify Shader Editor
// Available at the Unity Asset Store - http://u3d.as/y3X
Shader "Custom/Deferred Grab Pass"
{
   Properties
   {
      [Normal]_SurfaceNormal("Surface Normal", 2D) = "bump" {}
      _Smoothness("Smoothness", Range( 0 , 1)) = 0
      _Metallic("Metallic", Range( 0 , 1)) = 0
      [HideInInspector] _texcoord( "", 2D ) = "white" {}
      [HideInInspector] __dirty( "", Int ) = 1
   }

   SubShader
   {
      Tags{ "RenderType" = "Opaque"  "Queue" = "Geometry+0" }
      Cull Back
      GrabPass{ }
      CGPROGRAM
      #pragma target 3.0
      #pragma surface surf Standard keepalpha addshadow fullforwardshadows exclude_path:forward
      struct Input
      {
         float4 screenPos;
         float2 uv_texcoord;
      };

      uniform sampler2D _GrabTexture;
      uniform sampler2D _SurfaceNormal;
      uniform float4 _SurfaceNormal_ST;
      uniform float _Metallic;
      uniform float _Smoothness;


      inline float4 ASE_ComputeGrabScreenPos( float4 pos )
      {
         #if UNITY_UV_STARTS_AT_TOP
         float scale = -1.0;
         #else
         float scale = 1.0;
         #endif
         float4 o = pos;
         o.y = pos.w * 0.5f;
         o.y = ( pos.y - o.y ) * _ProjectionParams.x * scale + o.y;
         return o;
      }


      void surf( Input i , inout SurfaceOutputStandard o )
      {
         float4 ase_screenPos = float4( i.screenPos.xyz , i.screenPos.w + 0.00000000001 );
         float4 ase_grabScreenPos = ASE_ComputeGrabScreenPos( ase_screenPos );
         float4 ase_grabScreenPosNorm = ase_grabScreenPos / ase_grabScreenPos.w;
         float2 uv_SurfaceNormal = i.uv_texcoord * _SurfaceNormal_ST.xy + _SurfaceNormal_ST.zw;
         float4 screenColor1 = tex2D( _GrabTexture, ( ase_grabScreenPosNorm + float4( UnpackNormal( tex2D( _SurfaceNormal, uv_SurfaceNormal ) ) , 0.0 ) ).xy );
         o.Albedo = screenColor1.rgb;
         o.Metallic = _Metallic;
         o.Smoothness = _Smoothness;
         o.Alpha = 1;
      }

      ENDCG
   }
   Fallback "Diffuse"
   CustomEditor "ASEMaterialInspector"
}
/*ASEBEGIN
Version=15401
-1073;142;1066;1198;1244.813;865.6038;1.708548;True;False
Node;AmplifyShaderEditor.SamplerNode;4;-655.0253,26.25768;Float;True;Property;_SurfaceNormal;Surface Normal;0;1;[Normal];Create;True;0;0;False;0;None;1b497a628063d62448e26bf495fd985a;True;0;True;bump;Auto;True;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;5;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.GrabScreenPosition;2;-605.5768,-439.6083;Float;False;0;0;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.SimpleAddOpNode;3;-261.8863,-131.3553;Float;False;2;2;0;FLOAT4;0,0,0,0;False;1;FLOAT3;0,0,0;False;1;FLOAT4;0
Node;AmplifyShaderEditor.RangedFloatNode;5;-288,144;Float;False;Property;_Metallic;Metallic;2;0;Create;True;0;0;False;0;0;0;0;1;0;1;FLOAT;0
Node;AmplifyShaderEditor.RangedFloatNode;6;-288,224;Float;False;Property;_Smoothness;Smoothness;1;0;Create;True;0;0;False;0;0;0;0;1;0;1;FLOAT;0
Node;AmplifyShaderEditor.ScreenColorNode;1;-52.77116,-135.7114;Float;False;Global;_GrabScreen0;Grab Screen 0;0;0;Create;True;0;0;False;0;Object;-1;False;False;1;0;FLOAT2;0,0;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.StandardSurfaceOutputNode;0;210,-128;Float;False;True;2;Float;ASEMaterialInspector;0;0;Standard;Custom/Deferred Grab Pass;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;Back;0;False;-1;0;False;-1;False;0;False;-1;0;False;-1;False;0;Opaque;0.5;True;True;0;False;Opaque;;Geometry;DeferredOnly;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;0;False;-1;False;0;False;-1;255;False;-1;255;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;False;2;15;10;25;False;0.5;True;0;0;False;-1;0;False;-1;0;0;False;-1;0;False;-1;-1;False;-1;-1;False;-1;0;False;0;0,0,0,0;VertexOffset;True;False;Cylindrical;False;Relative;0;;-1;-1;-1;-1;0;False;0;0;False;-1;-1;0;False;-1;0;0;16;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;2;FLOAT3;0,0,0;False;3;FLOAT;0;False;4;FLOAT;0;False;5;FLOAT;0;False;6;FLOAT3;0,0,0;False;7;FLOAT3;0,0,0;False;8;FLOAT;0;False;9;FLOAT;0;False;10;FLOAT;0;False;13;FLOAT3;0,0,0;False;11;FLOAT3;0,0,0;False;12;FLOAT3;0,0,0;False;14;FLOAT4;0,0,0,0;False;15;FLOAT3;0,0,0;False;0
WireConnection;3;0;2;0
WireConnection;3;1;4;0
WireConnection;1;0;3;0
WireConnection;0;0;1;0
WireConnection;0;3;5;0
WireConnection;0;4;6;0
ASEEND*/
//CHKSM=6246CBFDEF93CB10312CB4E526B00A21E5FDC790



Hello,

Apologies for the delayed reply, I had to confirm with the team before providing additional information.

Unfortunately, the Grab Pass node is Forward Only, we're going to update the wiki information in order to best describe its limitations.

The shader can't be set to Deferred only if you intend to use it, our apologies for the inconvenience.

Re: GrabPass in Deferred

PostPosted: Wed Jul 04, 2018 2:38 pm
by Cyntherius
Okay, thank your for the informations. :(

Any other way in Unity to 'simulate' transparency (for water) for an 'only Deferred' shader? I want to use post processing for the screen space reflection.

My plan was using GrabPass to grab the background and distort it.

Re: GrabPass in Deferred

PostPosted: Thu Jul 05, 2018 10:14 am
by Amplify_Borba
Hey there!

Is there a specific reason why you want to use Deferred only?

You could consider setting the Render Path to All in the Output Node's parameters, in order to have a shader with Forward + Deferred, which would provide much more flexibility.

Having a shader with Deferred only will result in all sorts of issues with transparency, as it does not handle it properly, unlike the Forward render path.