Search Unity

[SOLVED] Vertex shader problem with quads/planes

Discussion in 'Shaders' started by komoka, Sep 23, 2019.

  1. komoka

    komoka

    Joined:
    Jun 22, 2013
    Posts:
    4
    Hi!

    I've been only messing with shaders for two days , so it's entirely possible that i'm missing something really obvious.
    So i just basically tried to make a waving grass vertex shader.

     v.vertex.x = v.vertex.x + v.vertex.y * sin(_Time.y);

    This is all i wrote before the UnityObjectToCLipPos thing, but i get really weird and inconsistent results on planes and quads. In some cases it works how i would expect it to, and sometimes not. It seems to depend on where i view it from. It seems to work fine with cubes though. I've been modifying a two sided shader i got from the asset store, but the same thing happens with the standard unity unlit shader. (the one you create by rightclick-->create-->shaders-->unlitshader)
    Here is a gif demonstrating it(The white quads are just a material with the same shader, but no texture for testing).
    As i zoom in and back out the behaviour of the grass blades changes. Also i turned on the wireframe. It seems like the wireframe always behaves correctly, even when the texture itself starts moving wildly. Also when i change one of the mesh filters to cube, suddenly two other quads fix themselves magically. This is so weird that i can't even begin to reason about it.

    edit: I'm using 2019.2.2f1, but tried upgrading to 2.6 and it was the same
    edit2: While im not using the unity quad mesh, even if i change to unity's quad, the problem persists

     
    Last edited: Sep 23, 2019
  2. DBarlok

    DBarlok

    Joined:
    Apr 24, 2013
    Posts:
    268
  3. komoka

    komoka

    Joined:
    Jun 22, 2013
    Posts:
    4
    Okay weird. I tried it in a whole new project with quads and it works consistently there. Once i get home ill make additional tests, to see what the difference is.

    Edit: Okay so i cant recreate this in a new project for some reason, but in my main project i did this:
    1.Created new unlit shader and a material for it
    2. added this line v.vertex.x = v.vertex.x + v.vertex.y * sin(_Time.y) to the shader
    3. created a new scene
    4.spawned a quad with the material(shader) It worked fine
    5. I spawned another one, then it started moving in a unexpected way again.
    It kind of seems like it happens when theres more than one, but i have no idea why it doesnt happen in the other project.
    Just to clarify, the movement i expect is the one where it just stretches, but doesn't actually move.
    I just really dont understand why spawning another one for example changes the behavior.
    https://hatebin.com/pyvbiwaqsr Heres the shader, but there's really just one line changed.
     
    Last edited: Sep 24, 2019
  4. komoka

    komoka

    Joined:
    Jun 22, 2013
    Posts:
    4
    Okay i finally fixed the problem i think. I had to add "DisableBatching"="True" tag.