Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
transparent blended textures
08-20-2011, 03:41 PM,
transparent blended textures
if i have a couple of stacked transparent objects shouldn't they both show up blended on the background texture? i was looking at the starting grid at montreal and i noticed the starting position doesn't display because the skid marks are on top of it. the skid marks get blended onto the background asphalt texture but i would expect the grid marks to show where the skids texture is transparent which is not the case. i think this is a bug (and i don't know if it ever used to work).

08-25-2011, 12:29 AM,
What is probably happening is the asphalt gets drawn first (along with all other opaque objects), and then the skid marks just happen to get drawn before the starting grid (writing to the z-buffer), and because the skid marks are on top of the grid, the grid polygon fails the z-buffer test. I could disable z-buffer write when drawing transparent objects. This might cause other artifacts, but they're probably not as noticeable. I checked this change into the data repo, R885, let me know if you spot anything really terrible.
08-25-2011, 01:37 AM,
better, but not perfect. now the grid shows up but the skid marks get drawn under the grid. ideally i would like the skid marks to show up on top of the grid with everything drawn on the asphalt (with the grid being visible where the skid marks are transparent, of course). is this possible?

08-26-2011, 12:03 AM,
It seems we need to be able to control the order in which these objects are drawn. Hum... what happens if you reorder the entries in the list.txt to put the skid marks at the end?
08-26-2011, 01:34 PM,
indeed, if i move the grid markings before the skids then the skids get drawn on top of the grid marks. what's really strange this seems to happen only for transparent blended objects. if the start line is not a transparent blended object then the skids get drawn on top of the start line and then both are drawn on top of the road. if i make the start line a transparent blended object then i need to have it before the skid marks in order to have the skid marks drawn on top of the line.

in blender the objects are stacked correctly. shouldn't the objects be drawn in reverse order of how they are stacked from a given point of view? i.e., if i look from the top ideally the road gets drawn first (the background) and then the marks (they are below the skids) and last the skid marks. this reordering of the objects list, although it works, is problematic.

08-27-2011, 11:35 AM,
This is a pretty good explanation of what's going on:

VDrift already draws all opaque objects before translucent ones (A First Quick Fix). If you turn off the transparent blended flag, then VDrift will use alpha testing (Another Good Trick), and each pixel of the texture will be judged either fully opaque or fully transparent. That adds hard edges to the texture, but it allows the zbuffer to work properly, where each pixel gets a depth value and on subsequent draws, pixels will only be drawn over the existing color if the depth is closer. Otherwise (with transparent blended flag on), if some pixel is partially translucent, we don't know what value to put in the zbuffer. If we put a value in there, we get problems like you originally saw when you started the thread: if (due to draw order) you draw a skid mark first (and write to the z buffer), and it's closer than the starting grid, then when the starting grid gets drawn, it's further away than the value in the zbuffer from the skid, so doesn't get drawn. If we don't put a value in the z buffer for transparent blended flagged objects (Disabling Z-write for Translucent Polygons), which is the fix in R885, then the depth of the translucent objects isn't considered relative to each other (only relative to opaque objects), and you get situations like you mentioned where the draw order controls layering. VDrift doesn't do the "depth sorting" step from the link because it can be slow and also gives inconsistent results. I think the best way to do it is to have it like it is now, where z writes are off and the layering is controlled by ordering. Or, if you can accept the artifacts of turning off transparent blended for even one of the two objects, that would fix it too.
08-27-2011, 12:04 PM,
depth sorting is what i had in mind. i know it could be expensive but i was wondering if we could this once at the beginning when we load the objects instead of having to sort things manually in the list. not sure if it's feasible though.

08-28-2011, 09:54 PM,
So maybe sort at load by the y (height) coordinate of the object's bounding box center?
08-29-2011, 10:15 AM,
joevenzon Wrote:So maybe sort at load by the y (height) coordinate of the object's bounding box center?
that's what i was thinking. i wonder if it will cause problems with the horizon as it is also a transparent blended texture drawn onto the sky?

08-30-2011, 10:44 AM,
I think I'm drawing the skybox and skybox transparent objects in separate passes from the normal opaque and transparent stuff already, so they should be OK.

Forum Jump:

Users browsing this thread: 1 Guest(s)