8
\$\begingroup\$

I use dynamic vertex lighting on 2D sprites. On larger sprites the lighting is uglier than on smaller ones. This is because every sprite is just a quad of two triangles. Not enough vertices there for lighting on larger areas.

Is there a way to use more triangles on a sprite? Maybe even depending on how much screen space they cover?

\$\endgroup\$
8
  • 1
    \$\begingroup\$ It sounds like you want to subdivide your quad? If that's the case I there are some good examples in pseudo code for accomplishing this. Afaik Unity will let you access a game objects mesh (and its triangles/vertices) which should allow to to accomplish what you want. Here is one such example here on gamedev for subdiving quads: How to subdivide a quad? . Is this along the lines of what you were looking for? \$\endgroup\$
    – Logham
    Sep 15, 2014 at 10:52
  • \$\begingroup\$ Yes, subdividing a quad is the approach I am looking for. This includes winding and UVs I guess. That way I would have more triangles. \$\endgroup\$
    – aggsol
    Sep 16, 2014 at 8:02
  • \$\begingroup\$ Have you tried using a tessellation shader when drawing your sprite? docs.unity3d.com/Manual/SL-SurfaceShaderTessellation.html answers.unity3d.com/questions/583960/… \$\endgroup\$ Sep 18, 2014 at 19:14
  • 2
    \$\begingroup\$ When you tessellate the quad, the lighting values for the vertices are going to be just interpolated. The quad is flat, so with more vertices, the interpolation will be just linear across the entire quad. How will adding more triangles fix this issue. This sounds like something that should be solved with a pixel shader. \$\endgroup\$
    – Arun R
    Sep 19, 2014 at 22:06
  • \$\begingroup\$ @ArunR Good point, but if e.g. the quad is larger than the range of a point light then the triangle will use light if the vertext is not lightes anymore. Using the pixel shader is sadly not an option on all devices. \$\endgroup\$
    – aggsol
    Sep 22, 2014 at 8:28

1 Answer 1

2
\$\begingroup\$

Sounds like you need to create your own game object and use a custom triangulation algo to handle the detail based on some size related math.

Maybe something like this could help ...

http://forum.unity3d.com/threads/tessellation-algorithms-for-polygons.228051/

Others options might be to use a smarter shader and a bump map with your sprite ... vertex displacement type approaches.

It's hard to say without knowing exactly what it is you are trying to achieve as to what might fit best. Hopefully one of these helps.

\$\endgroup\$
6
  • \$\begingroup\$ The idea is to use vertex light on sprites as it is way faster than pixel lights. Especially some mobile platforms have low spec graphic chips. \$\endgroup\$
    – aggsol
    Sep 15, 2014 at 13:44
  • \$\begingroup\$ So your saying you have a large quad that you want to split then per vertex light the result? You could get a much better and faster result by using per pixel lighting on the existing low res quad IMO but if thats what you want then go for it. Splitting a quad shouldn't be too hard right? \$\endgroup\$
    – War
    Sep 15, 2014 at 13:52
  • \$\begingroup\$ Bear in mind that what you save by per pixel lighting you would effectively lose by having larger vertex buffers ... the other option of course is to have some math in the vertex shader to pass a light level to the pixel shader based on a portion of the vertex so you still get a small VB and don't per pixel light. \$\endgroup\$
    – War
    Sep 15, 2014 at 13:54
  • \$\begingroup\$ scrap that idea ... that won't work ... hmmmm \$\endgroup\$
    – War
    Sep 15, 2014 at 13:56
  • 1
    \$\begingroup\$ If you need clarification on the question, post a comment on the question. \$\endgroup\$
    – House
    Sep 15, 2014 at 15:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .