Home Technical Talk

Limit the draw area of a polygon in OpenGL based off of UV?

OddlyOrdinary
polycounter lvl 9
Offline / Send Message
OddlyOrdinary polycounter lvl 9
Hey Guys,
I'm working on problem and wanted to see if anyone had a suggestion. I'm trying to prevent OpenGL from rendering outside the 0-1 uv space. My mesh is larger and currently requires me to clamp the edges to not have the extra parts of the mesh redrawn with a texture mirror. Or I have to redraw the outter bounds with black.

Anyone have a suggestion on how to limit the range rendered? There's nothing behind my mesh so I don't have to worry about depth or transparency, I'm just trying to increase performance.

Replies

  • OddlyOrdinary
    Options
    Offline / Send Message
    OddlyOrdinary polycounter lvl 9
    This was probably too specific of an idea but in case someone finds themselves in this situation or finds this thread from a search I thought I'd post how I fixed the issue.

    What I ended up doing was generating an additional UV set at runtime, I'd look at the meshes and generate a list of polygons that were over the boundaries. So if a polygon had some vertices outside the boundary and some inside I would add it to a list.

    Then I would find the closest two UV values for that polygon and build a scalar to warp the other points by.
    Say we originally have a triangle with three UV values
    [-.5, -.2, .3] I'd chose the -2, and .3

    In the second UV set the .3 would be 1.0 and the -.2 would be -.66. The -.5 would be -1.66. The scalar being .33=(1/(.3 * 10)).

    Then in the shader I clamped the textcoord.x values of the second uv set to 0 or 1, this generates an immediate cutoff at the boundary, without being a harsh curve and also takes into account the different sizes of each polygon.
  • CrazyButcher
    Options
    Offline / Send Message
    CrazyButcher polycounter lvl 18
    You can also clamp textures to live only within 0-1 by changing the texture's sampler state:
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER)
    and you specify the border color, as "black")

    edit: actually as you are using shaders, why not just "not" sample the texture when uvs are outside of 0,1, though probably didn't fully understand what you were after
Sign In or Register to comment.