Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Teq · May 01, 2011 at 12:23 PM · shadernormalsvertexnormaldiffuse

Problem of color in custom vertex shader

Hi,

I need to change the position of a lot of vertex in real-time, so I wanted to do that with shader ( is my first time with shader, be kind with me please ^^ ), I copie a simple example of shader of unity ( toonBasic ) and modify it for change the height of my vertex. My problem now is the color is not change with the normal so is very difficult to see the vertices moves, I try to compute my new normal, but still nothing change, so I try to add a pass of the built-in Diffuse shader, when I do that the color are well compute with the normal but I vertices go back to the original position ! is like it use just the pass of Diffuse and not my shader after.

if somebody now how I can change my position of my vertices and after compute the good color for have a diffuse affect, that will be so helpfull ^^ thanks

My shader code :

Shader "Toon/TestShader" { Properties { _Color ("Main Color", Color) = (.5,.5,.5,1) _MainTex ("Base (RGB)", 2D) = "white" {} _ToonShade ("ToonShader Cubemap(RGB)", CUBE) = "" { Texgen CubeNormal } _Wave("Wave", float) = .0 _Xhole("Xhole", float) = .0 _Yhole("Yhole", float) = .0 }

 SubShader {
     Tags { "RenderType"="Opaque" }


     UsePass "Diffuse"
     Pass {
         Name "BASE"
         Cull Off

         CGPROGRAM

         #pragma vertex vert
         #pragma fragment frag
         #pragma fragmentoption ARB_precision_hint_fastest 

         #include "UnityCG.cginc"

         sampler2D _MainTex;
         samplerCUBE _ToonShade;
         float4 _MainTex_ST;
         float4 _Color;
         float _Wave;
         float _Xhole;
         float _Yhole;

         struct appdata {
             float4 vertex : POSITION;
             float2 texcoord : TEXCOORD0;
             float3 normal : NORMAL;
         };

         struct v2f {
             float4 pos : POSITION;
             float2 texcoord : TEXCOORD0;
             float3 cubenormal : TEXCOORD1;
         };

         v2f vert (appdata v)
         {


             float3 worldPos = mul (_Object2World, v.vertex).xyz;


             float4 hole;
             hole[0] = _Xhole;
             hole[1] = .0;
             hole[2] = _Yhole;
             hole[3] = .0;

             float4 VectDist;
             VectDist[0] =  worldPos[0] - hole[0];
             VectDist[1] =  0.0f; //worldPos[1] - hole[1];
             VectDist[2] =  worldPos[2] - hole[2];
             VectDist[3] =  0.0;

             float dist;
             dist = sqrt(dot(VectDist,VectDist));

             if(dist > 3.0)
             {
                 dist = 3.0;
             }
             float coef;
             coef = (1.0f - (dist/ 3.0)) ;
             if(coef < 0.0)
             {
                 coef = 0.0;
             }
             v.vertex.y += -5.0*coef;

             if( coef > 0 )
             {
                 worldPos = mul (_Object2World, v.vertex).xyz;

                 VectDist[0] =  hole[0] - worldPos[0];
                 VectDist[1] =  hole[1] - worldPos[1];
                 VectDist[2] =  hole[2] - worldPos[2];
                 VectDist[3] =  0.0;

                 v.normal = normalize( VectDist );
             }

             v2f o;
             o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
             o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
             o.cubenormal = mul (UNITY_MATRIX_MV, float4(v.normal,0));


             return o;
         }

         float4 frag (v2f i) : COLOR
         {
             float4 col = _Color * tex2D(_MainTex, i.texcoord);
             float4 cube = texCUBE(_ToonShade, i.cubenormal);
             return col; // float4(2.0f * cube.rgb * col.rgb, col.a);
         }

         ENDCG           
     }

     //UsePass "Diffuse/BASE"
 } 

 Fallback "Diffuse"

}

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

No one has followed this question yet.

Related Questions

Getting vertex data from lighting function in shaders. 1 Answer

Assigning vertex normal in Surface program to o.Normal brakes lighting? 0 Answers

Curved + Diffuse Shader??? 0 Answers

Cubemap Diffuse / Heightmap Shader Issues. 1 Answer

How to calculate light from behind a quad? (and other light positions) 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