Search Unity

Better way to get bounds in shader?

Discussion in 'Shaders' started by tsangwailam, Jul 20, 2016.

  1. tsangwailam

    tsangwailam

    Joined:
    Jul 30, 2013
    Posts:
    280
    HI,

    I am working on a shader which need to get the bounds and center of the mesh (not origin). I manage to get it via attached a script and pass the centre and bounds.

    But any better method to get it just without extra script but using just shader.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    You could store that information in the model itself, like in an extra UV coordinate set or two store the model relative bounds center and either the spherical bounds as the w component or model extents in the second UV set. If you want to be really fancy you can use the last two components of the first UV set and four of another to store the 6 floats you need.

    But it's probably easier to just set it as a shader property.
     
  3. tsangwailam

    tsangwailam

    Joined:
    Jul 30, 2013
    Posts:
    280
    Thanks. But how to do that? Use a script?

    Since i manage to do by filling an extra properties. But i want to do that not using extra script.
     
  4. tsangwailam

    tsangwailam

    Joined:
    Jul 30, 2013
    Posts:
    280
    Thanks. I manage to set the uv of the mesh via script and solve my problem.