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 /
avatar image
0
Question by howlbrett · Apr 19, 2019 at 04:42 AM · shadercolorvertex shadervertex colorvertexcolor

How do I adapt this vertex manipulation shader so that my object (point cloud) keeps its original colouring?

Hello!

(Photos attached below might help to better explain)

I am currently attempting to use this vertex manipulation shader on a point cloud object:

 Shader "Tutorial/015_vertex_manipulation" {
     //show values to edit in inspector
     Properties {
         _Color ("Tint", Color) = (0, 0, 0, 1)
         _MainTex ("Texture", 2D) = "white" {}
         _Smoothness ("Smoothness", Range(0, 1)) = 0
         _Metallic ("Metalness", Range(0, 1)) = 0
         [HDR] _Emission ("Emission", color) = (0,0,0)
 
         _Amplitude ("Wave Size", Range(0,1)) = 0.4
         _Frequency ("Wave Freqency", Range(1, 8)) = 2
         _AnimationSpeed ("Animation Speed", Range(0,5)) = 1
     }
     SubShader {
         //the material is completely non-transparent and is rendered at the same time as the other opaque geometry
         Tags{ "RenderType"="Opaque" "Queue"="Geometry"}
 
         CGPROGRAM
 
         //the shader is a surface shader, meaning that it will be extended by unity in the background 
         //to have fancy lighting and other features
         //our surface shader function is called surf and we use our custom lighting model
         //fullforwardshadows makes sure unity adds the shadow passes the shader might need
         //vertex:vert makes the shader use vert as a vertex shader function
         //addshadows tells the surface shader to generate a new shadow pass based on out vertex shader
         #pragma surface surf Standard fullforwardshadows vertex:vert addshadow
         #pragma target 3.0
 
         sampler2D _MainTex;
         fixed4 _Color;
 
         half _Smoothness;
         half _Metallic;
         half3 _Emission;
 
         float _Amplitude;
         float _Frequency;
         float _AnimationSpeed;
 
         //input struct which is automatically filled by unity
         struct Input {
             float2 uv_MainTex;
         };
 
         void vert(inout appdata_full data){
             float4 modifiedPos = data.vertex;
             modifiedPos.y += sin(data.vertex.x * _Frequency + _Time.y * _AnimationSpeed) * _Amplitude;
             
             float3 posPlusTangent = data.vertex + data.tangent * 0.01;
             posPlusTangent.y += sin(posPlusTangent.x * _Frequency + _Time.y * _AnimationSpeed) * _Amplitude;
 
             float3 bitangent = cross(data.normal, data.tangent);
             float3 posPlusBitangent = data.vertex + bitangent * 0.01;
             posPlusBitangent.y += sin(posPlusBitangent.x * _Frequency + _Time.y * _AnimationSpeed) * _Amplitude;
 
             float3 modifiedTangent = posPlusTangent - modifiedPos;
             float3 modifiedBitangent = posPlusBitangent - modifiedPos;
 
             float3 modifiedNormal = cross(modifiedTangent, modifiedBitangent);
             data.normal = normalize(modifiedNormal);
             data.vertex = modifiedPos;
         }
 
         //the surface shader function which sets parameters the lighting function then uses
         void surf (Input i, inout SurfaceOutputStandard o) {
             //sample and tint albedo texture
             fixed4 col = tex2D(_MainTex, i.uv_MainTex);
             col *= _Color;
             o.Albedo = col.rgb;
             //just apply the values for metalness, smoothness and emission
             o.Metallic = _Metallic;
             o.Smoothness = _Smoothness;
             o.Emission = _Emission;
         }
         ENDCG
     }
     FallBack "Standard"
 }

This successfully creates the wave-like effect on the object i wanted. However, the problem is that when I do this it replaces the vertexcolor shader on the point cloud and so the point cloud goes black and no longer retains its original colouring.

This is the code for the vertexcolor shader:

 Shader "Custom/VertexColor" {
     SubShader {
     Pass {
         LOD 200
               
                  
         CGPROGRAM
         #pragma vertex vert
         #pragma fragment frag
   
         struct VertexInput {
             float4 v : POSITION;
             float4 color: COLOR;
         };
          
         struct VertexOutput {
             float4 pos : SV_POSITION;
             float4 col : COLOR;
         };
          
         VertexOutput vert(VertexInput v) {
          
             VertexOutput o;
             o.pos = UnityObjectToClipPos(v.v);
             o.col = v.color;
              
             return o;
         }
          
         float4 frag(VertexOutput o) : COLOR {
             return o.col;
         }
  
         ENDCG
         } 
     }
  
 }
 

Is there any way I can adapt the vertexmanipulation shader so that the point cloud retains its original colouring (like it does with the vertexcolour shader) whilst still creating the wave-like effect I wanted?

I hope this makes sense - I’m sorry I’m relatively new to shader coding in unity. Below I have attached a couple of screenshots which might make it clearer.

Any help would be massively appreciated!

Many thanks in advance,

Tom

alt text

This is the point cloud with the vertexcolor shader - when you can see its colouring.

alt text

And this is the point cloud with the vertex manipulation shader - it creates the wave-effect I want but makes the point cloud completely black.

screenshot-2019-04-18-at-213054.png (383.9 kB)
screenshot-2019-04-18-at-213250.png (419.7 kB)
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

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

168 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 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

Changing vertex colors and mesh leak fix 1 Answer

Can I get the whitest point of an image within a shader, and use it for white balancing the image? 1 Answer

Material doesn't have a color property '_Color' 4 Answers

Quad vertex color shader 0 Answers

Changes to Mesh Vertex Colors Reset on Build 1 Answer


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