alienizer at June 26th, 2012 20:47 — #1
I've been searching for hours on how to implement two sided texture on polys but found nothing of good use. Anyone have done this before?
alienizer at June 26th, 2012 21:05 — #2
I draw my scene twice and this works. But, is that the right way to do that? Doesn't OpenGL support texturing both side of a poly?
david_gallagher at June 26th, 2012 22:43 — #3
could you set the cullmode to none, that should make the texture visible on both sides of the poly. not sure if it will give the effect you desire but should work.
alienizer at June 26th, 2012 23:57 — #4
Yes I did that, but It doesn't look like we can set a texture for each side of a poly. Is there?
david_gallagher at June 27th, 2012 00:21 — #5
no i don't think so, the way you described looks like the best way if wanting a unique texture on both sides.
stainless at June 27th, 2012 04:35 — #6
you can do it with shaders, just take use the angle between the surface normal and the camera/pixel ray to swap between textures.
Or if you want a simple solution, just create two polygons a tiny amount apart.
oisyn at June 27th, 2012 05:38 — #7
Why would they need to be a tiny amount apart? They can share vertices. Just make sure you use the appropriate backface culling mode so at any given time only one of the two polygons will render.
It's pretty common to actually have two polygons when rendering doublesided materials anyway. The cost of that couple of extra indices outweighs the cost of the culling mode state change and extra drawprim call.
smile_ at June 27th, 2012 06:31 — #8
You can determine back/front facing in shader (gl_FrontFacing in OpenGL) and then sample different textures.
reedbeta at June 27th, 2012 06:38 — #9
Yes. A similar flag exists in HLSL. Don't forget to negate the normal on the back side as well, to get correct lighting. (Or light from both sides, if you want the impression of a translucent surface.)
thenut at June 27th, 2012 09:51 — #10
Normally I would create two polygons in this instance and let the cull mode determine which one gets drawn in a lazy render. I'm not sure how important it is for you to have a double sided polygon, but I would pretty much do what .oisyn mentioned, although without sharing vertices. I would split the texture coordinates so that the front face maps to the left side of the texture and the back face maps to the right side of the texture (assuming this texture or purpose is specific here). No need for special logic and dot products in the shader. Just race it through the pipeline in a quick and simple draw and let the cull mode do its thing. This is also backwards compatible with ancient hardware.
stainless at June 27th, 2012 16:28 — #11
I would try it out and look at what you get, sharing verts can produce z fighting on some platforms from some view angles.
alienizer at June 28th, 2012 01:08 — #12
Thanks guys for the tips. What I ended up doing is to cull the back faces, draw the front ones, then cull the front and draw the back ones. Works perfect!