AO and vertex animation

Your feedback is very important to us. We are listening.

AO and vertex animation

Postby marten » Wed Sep 28, 2016 1:30 pm

Hello!
I was just playing around with Amplify Occlusion in my game and it looks very good. However, I use a lot of vertex animation (surface shaders for now) for things and was just wondering if there's an easy way to get them to work together? To avoid results like this:
Image

as you can see the AO is applied to how the geometry looked before the vertices are modified.
marten
 
Posts: 5
Joined: Wed Sep 28, 2016 1:14 pm

Re: AO and vertex animation

Postby Ricardo Teixeira » Wed Sep 28, 2016 1:45 pm

marten wrote:Hello!
I was just playing around with Amplify Occlusion in my game and it looks very good. However, I use a lot of vertex animation (surface shaders for now) for things and was just wondering if there's an easy way to get them to work together? To avoid results like this:
Image

as you can see the AO is applied to how the geometry looked before the vertices are modified.


Hello Marten,

Thank you for reporting the problem, we really appreciate it. It shouldn't be an issue, what shader are you currently using? In the Amplify Occlusion camera component, what value do you use for Per-Pixel Normals? Deferred or Forward rendering?

Thanks!
Sales & Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Ricardo Teixeira
 
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm

Re: AO and vertex animation

Postby marten » Wed Sep 28, 2016 6:13 pm

Thanks for your quick response. My shader is a custom one which colors the mesh with vertex colors and does some vertex displacing:

Code: Select all
Shader "City/Vertex colored animated" {
     Properties {
         _Color ("Color", Color) = (1,1,1,1)
         _MainTex ("Albedo (RGB)", 2D) = "white" {}
         _Smoothness ("Smoothness", Range(0,1)) = 0.5
         _Stretch ("Stretch", Range(-0.5,0.5)) = 0
         _Bend ("Bend", Range(-0.5,0.5)) = 0
         _SubmeshOffset ("Submesh Offset", Vector) = (0,0,0,0)

     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         LOD 200
         
         CGPROGRAM
         #pragma surface surf Standard vertex:vert addshadow
         #pragma target 3.0

         struct Input {
             float2 uv_MainTex;
             float3 vertexColor; // Vertex color stored here by vert() method
         };

         float _Stretch;
         float _Bend;
         float3 _SubmeshOffset;
 
         void vert (inout appdata_full v, out Input o) {
             UNITY_INITIALIZE_OUTPUT(Input,o);
             // Save the Vertex Color in the Input for the surf() method
             o.vertexColor = v.color;

             //vertex displacing
             float y = v.vertex.y + _SubmeshOffset.y;
             float x = v.vertex.x + _SubmeshOffset.x;

             v.vertex.y += y * _Stretch - (x * y) * _Bend;
             v.vertex.x += (v.vertex.x + _SubmeshOffset.x) * -_Stretch + y * y * _Bend;
             v.vertex.z += (v.vertex.z + _SubmeshOffset.z) * -_Stretch;
         }
 
         sampler2D _MainTex;
         half _Smoothness;
         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;
              // Combine normal color with the vertex color
             o.Albedo = c.rgb * IN.vertexColor;
             o.Smoothness = _Smoothness;
             o.Alpha = c.a;

         }
         ENDCG
   }
}


And here are my current settings for the effect. I have tried to fiddle with the settings but nothing seems to help with the problem.
Image
marten
 
Posts: 5
Joined: Wed Sep 28, 2016 1:14 pm

Re: AO and vertex animation

Postby Ricardo Teixeira » Thu Sep 29, 2016 11:01 am

marten wrote:Thanks for your quick response. My shader is a custom one which colors the mesh with vertex colors and does some vertex displacing:

Code: Select all
Shader "City/Vertex colored animated" {
     Properties {
         _Color ("Color", Color) = (1,1,1,1)
         _MainTex ("Albedo (RGB)", 2D) = "white" {}
         _Smoothness ("Smoothness", Range(0,1)) = 0.5
         _Stretch ("Stretch", Range(-0.5,0.5)) = 0
         _Bend ("Bend", Range(-0.5,0.5)) = 0
         _SubmeshOffset ("Submesh Offset", Vector) = (0,0,0,0)

     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         LOD 200
         
         CGPROGRAM
         #pragma surface surf Standard vertex:vert addshadow
         #pragma target 3.0

         struct Input {
             float2 uv_MainTex;
             float3 vertexColor; // Vertex color stored here by vert() method
         };

         float _Stretch;
         float _Bend;
         float3 _SubmeshOffset;
 
         void vert (inout appdata_full v, out Input o) {
             UNITY_INITIALIZE_OUTPUT(Input,o);
             // Save the Vertex Color in the Input for the surf() method
             o.vertexColor = v.color;

             //vertex displacing
             float y = v.vertex.y + _SubmeshOffset.y;
             float x = v.vertex.x + _SubmeshOffset.x;

             v.vertex.y += y * _Stretch - (x * y) * _Bend;
             v.vertex.x += (v.vertex.x + _SubmeshOffset.x) * -_Stretch + y * y * _Bend;
             v.vertex.z += (v.vertex.z + _SubmeshOffset.z) * -_Stretch;
         }
 
         sampler2D _MainTex;
         half _Smoothness;
         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;
              // Combine normal color with the vertex color
             o.Albedo = c.rgb * IN.vertexColor;
             o.Smoothness = _Smoothness;
             o.Alpha = c.a;

         }
         ENDCG
   }
}


And here are my current settings for the effect. I have tried to fiddle with the settings but nothing seems to help with the problem.
Image


Hello,

There's a Unity issue that prevents it from working under certain combinations. In this case, it works with all settings, using your shader, except with Forward Rendering when using Camera Per-Pixel Normals. Altering the Normals value in the Amplify Occlusion component should resolve the problem.

Let us know if that is not the case, we would be happy to help if that is not the case. Our apologies for the inconvenience.
Sales & Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Ricardo Teixeira
 
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm

Re: AO and vertex animation

Postby marten » Thu Sep 29, 2016 12:00 pm

Thank you!
That did seem to work!

I realized I seem to have another problem, which probably isn't related to the AO at all which was what confused me. The part that affects light in the displaced model seems to be updated incorrectly.
Image
marten
 
Posts: 5
Joined: Wed Sep 28, 2016 1:14 pm

Re: AO and vertex animation

Postby Ricardo Teixeira » Thu Sep 29, 2016 1:17 pm

marten wrote:Thank you!
That did seem to work!

I realized I seem to have another problem, which probably isn't related to the AO at all which was what confused me. The part that affects light in the displaced model seems to be updated incorrectly.
Image


Hi,

Awesome, happy to hear it. Do you see the same issue with other depth based effects such as DoF?
If possible, please send a download link for the asset used in your screenshot to [email protected], we would be happy to test it on our side as soon as possible.

Thanks!
Sales & Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Ricardo Teixeira
 
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests