Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
avatar image
0
Question by FreakyDevA · Apr 17, 2018 at 11:16 AM · shaderrenderingimage effectsvertex shadergeometry shader

Screen shaders that alter geometry at runtime or through camera

Hello people,

I am new to shaders and have read a few tutorials covering basic concepts but I found it really hard to find information about shaders that alter geometry through the camera or at runtime.

I want something like an image effect that doesn't actually change any textures but distorts the environment. For example I would like every object in the scene that the camera sees to change direction by a certain amount. Down the road I would like the distortion to change as the player moves in the environment.

I was able to make the following shader that moves individual objects along the xyz line.

 Shader "Vertex Modifier" {
     Properties{
         _MainTex("Texture", 2D) = "white" {}
         _Amount("Height", Float) = 1.0
     }
     SubShader{
         Tags{ "RenderType" = "Opaque" }
         CGPROGRAM
         #pragma surface surf Lambert vertex:vert
         struct Input {
             float2 uv_MainTex;
         };
         float _Amount;
 
         void vert(inout appdata_full v) {
             v.vertex.xyz += 0.1*_Amount;
         }
 
         sampler2D _MainTex;
         void surf(Input IN, inout SurfaceOutput o) {
             o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
         }
         ENDCG
     }
     Fallback "Diffuse"
 }

My first problem is that I don't know how to pass this as a screen shader/image effect.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Remy_Unity · Apr 17, 2018 at 11:38 AM

First, an image effect won't do what your want. It's ment to be applied after rendering, so the closest you could do with it is distortion.

To do what you're talking about, you should make a shader that affect all the objects you want, and use the camera position or the view space to alter the geometry.

Do some research on matrix math in shaders, and look at this doc page https://docs.unity3d.com/Manual/SL-UnityShaderVariables.html. You'll find some interesting UNITY_MATRIX_MV : Current model * view matrix that will allow you to calculate the vertex position in view space.

Comment
Add comment · Show 7 · Share
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 FreakyDevA · Apr 18, 2018 at 06:58 AM 0
Share

Thank you for your answer. From what I understand I have to make a shader and put it on each object? What if I have hundreds of objects? Isn't there a way to attach the shader to the camera or trigger it with the start function?

avatar image Remy_Unity FreakyDevA · Apr 18, 2018 at 07:49 AM 0
Share

Well, if you really don't want to change the shader used by your objects you could still use replacement shader : https://docs.unity3d.com/$$anonymous$$anual/SL-ShaderReplacement.html

But if it's the only thing that you're rendering, and are not doing something fancy on your objects, it's probably best to simply assign them a material using this shader.

avatar image FreakyDevA Remy_Unity · Apr 18, 2018 at 08:32 AM 0
Share

Thank you. Shader replacement seems like a good idea. I lost you on the last sentence. What do you mean assign them a material using this shader. Which shader are you referring to?

Show more comments

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

129 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 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 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 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 avatar image

Related Questions

Fade object transparency evenly from the edge inward 0 Answers

Reading from Gbuffers 4-7 in a shader 1 Answer

How can I make the most efficient SDF Shader in unity 1 Answer

Image Effect - Screen coordinates 1 Answer

separate vert and frag shader functions in two distinct URP Render Features 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