Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by MightyBox · Nov 03, 2015 at 02:19 PM · shadersimage effects

Can an image effect work on vertices displaced by other shaders?

I am trying to use a vertex displacement shader which moves the vertices of an object in the x-z plane. I also have an edge detection effect on the camera (using Roberts Cross Depths Normals). The problem is that the edge detection seems to ignore the vertex displacement created by the shader and draws an edge where the edges of the objects were originally. I have tried to change the Queue tag of the shader but that didn't help. It's not a problem with the vertex displacement shader - I've also tried several other vertex shaders (which I didn't write myself), but the same thing happens with the edge detection. It seems to me that the edge detection is happening before the vertex deformation, but I couldn't find any means of controlling the order. Could anybody please help?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Statement · Nov 03, 2015 at 03:07 PM 0
Share

Well, I don't know exactly how your setup or how your shader code looks like, but if it's an image effect then it would need normals and depth I would presume. That information has to be written to a normal and depth buffer, otherwise the image shader won't have any information to work with.

I guess if you do your own displacement, Unity won't know which normals you used (unless perhaps you implemented a surface shader (?)). If you wrote your own vertex and fragment shader then you're basically not using the surface system so I would presume you'd have to update the depth/normal buffer with replacement shaders so that your image effect has the information it needs.

It's a bit vague, sorry, but chipping in with some thoughts.

avatar image MightyBox Statement · Nov 03, 2015 at 03:30 PM 0
Share

Thanks for the reply. I used a surface shader, but to displace vertices i had to add a vertex program. Anything simple will exhibit this, for example (just the CG part):

 CGPROGRA$$anonymous$$
         #pragma surface surf Standard fullforwardshadows vertex:vert
         sampler2D _$$anonymous$$ainTex;
         struct Input {
             float2 uv_$$anonymous$$ainTex;
         };
         half _Glossiness;
         half _$$anonymous$$etallic;
         fixed4 _Color;
         float _Amount;
         void vert(inout appdata_full v) {
             float4 worldPos = mul(_Object2World, v.vertex);
             worldPos.x += _Amount*sin(worldPos.x);
             worldPos.z += _Amount*cos(worldPos.z);
             v.vertex = mul(_World2Object, worldPos);
         }
         void surf (Input IN, inout SurfaceOutputStandard o) {
             fixed4 c = tex2D (_$$anonymous$$ainTex, IN.uv_$$anonymous$$ainTex) * _Color;
             o.Albedo = c.rgb;
             o.$$anonymous$$etallic = _$$anonymous$$etallic;
             o.Smoothness = _Glossiness;
             o.Alpha = c.a;
         }
         ENDCG

This will just shift in the x-z plane. I'm not specifically setting depth nor normals; in this case normals are unchanged, and depth I was expecting that the compiled shader would take care of it. I don't know how to specifically write to the depth buffer in a surface shader.

avatar image Statement Statement · Nov 03, 2015 at 04:19 PM 0
Share

Well, beats me. I would assume that the image shader uses the same depth buffer as rendered geometry. However, if Unity is generating depth + normal buffers as a separate pass, it requires at least normals to be output to a render buffer. Unfortunately I don't know by heart if Unity solves this with the surface shaders (I would had assumed so) or if geometry is rendered with another shader. That shader then obviously need to deform the mesh exactly like your vertex program or it would output wrong depth values.

$$anonymous$$eh, I'll leave this to someone with more/fresher experience with image effects.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

32 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

CRT Shader how optimize?! 1 Answer

Black Hole Image Effect warping objects in front of the black hole. How can I fix this? 0 Answers

Correct way to add custom image effects to camera? 0 Answers

Transparency of a specific area 0 Answers

Distortion Shader for a Black Hole 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges