Search Unity

  1. We want you to join us at GDC this year! We've added new sessions to Unity Central, space is limited so sign up now!
    Dismiss Notice
  2. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  3. Unity 2017.3 has arrived! Read about it here.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Tell us about your experience here and you’ll get early access to the 2018 Game Studios report + more goodies.
    Dismiss Notice
  6. Be the first to take a peek at upcoming 2D Animation Preview. Drop into the forum and check it out!
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Displacing vertex

Discussion in 'Shaders' started by jan1984, Jun 13, 2008.

  1. jan1984


    May 30, 2008
    hi guys i have this simple shader wherein i want to displace the vertices but i get the error "" on line 23.Cud somebody point out wat i'm doing wrong?

    Shader "Underwater Effect" {
    Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Base (RfGB)", 2D) = "white" {}

    Pass {

    #pragma vertex vert

    #include "UnityCG.cginc"
    #include "AutoLight.cginc"

    uniform float4 _MainTex_ST;

    vert (appdata_base v)
    float Waviness = 5.0f;
    v.vertex.x += Mathf.Sin(Time.time + v.vertex.y * 0.1f) * Waviness;


    Fallback "Diffuse"


    another side question..
    do i need uniform float4 _MainTex_ST;?
    wat is that for?i actually copied my code from another shader and went on removing unwanted stuff.the above variable was not getting used even in that shader but with a lot of things happening behind the curtains in shaderlab i didnt want to remove this 1
  2. Eric5h5


    Volunteer Moderator Moderator

    Jul 19, 2006
    Have you read the responses in your other topic? Really, you need to read the shaderlab docs. That code's not even Cg; there's no way it will come close to working.

  3. Aras


    Graphics Plumber Unity Technologies

    Nov 7, 2005
    Your shader like this gives 5 errors (no SubShader block, and the rest in Cg code).

    Here is how it should be (I removed Properties block as well, you said you want minimal shader):
    Code (csharp):
    2. Shader "Underwater Effect" {
    3. SubShader {
    4. Pass {
    7. #pragma vertex vert
    8. #include "UnityCG.cginc"
    10. float4 vert (appdata_base v) : POSITION
    11. {
    12.     float Waviness = 5.0f;
    13.     v.vertex.x += sin(_Time.y + v.vertex.y * 0.1f) * Waviness;
    14.     return mul(glstate.matrix.mvp, v.vertex);
    15. }
    16. ENDCG
    18. }
    19. }
    20. }
    Basically, like someone replied in another thread, inside of shaders you don't have access to .NET calls (so no Time.time or Mathf.Sin there). Cg has a built-in function to calculate sine ("sin"). Time value can either be passed manually from your script, or you can use _Time built-in variable.

    If you don't use it in the shader, then you don't need it. Variables ending with _ST are used by built-in Unity shaders to apply texture's tiling offset values. As your shader does not use textures, there's no tiling&offset to apply.
  4. jan1984


    May 30, 2008
    Thx dude that helped.Although not including the subshader part was my bad.i do have it in place.thx again
  5. jan1984


    May 30, 2008
    hey i lost track of that post for some reason and i checked it only after reading this 1.i apologize for that

    well i did search for shaderlab docs but cudnt find 1 proper have any link where i cud find 1?i know cg but using it along with shaderlab has me confused and i feel like u cud combine the features for more powerful shaders.but yeah a shaderlab doc will definitely help as i'm totally new to it.