Two sided texture

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Jun 27, 2012 at 00:47

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?

Thanks.

11 Replies

Please log in or register to post a reply.

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Jun 27, 2012 at 01:05

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?

5000fdaaeeeb9f038be93cf67eb3b130
0
David_Gallagher 102 Jun 27, 2012 at 02:43

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.

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Jun 27, 2012 at 03:57

Yes I did that, but It doesn’t look like we can set a texture for each side of a poly. Is there?

5000fdaaeeeb9f038be93cf67eb3b130
0
David_Gallagher 102 Jun 27, 2012 at 04:21

no i don’t think so, the way you described looks like the best way if wanting a unique texture on both sides.

B5262118b588a5a420230bfbef4a2cdf
0
Stainless 151 Jun 27, 2012 at 08:35

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.

340bf64ac6abda6e40f7e860279823cb
0
_oisyn 101 Jun 27, 2012 at 09:38

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.

6eaf0e08fe36b2c23ca096562dd7a8b7
0
__________Smile_ 101 Jun 27, 2012 at 10:31

You can determine back/front facing in shader (gl_FrontFacing in OpenGL) and then sample different textures.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Jun 27, 2012 at 10:38

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.)

6837d514b487de395be51432d9cdd078
0
TheNut 179 Jun 27, 2012 at 13:51

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.

B5262118b588a5a420230bfbef4a2cdf
0
Stainless 151 Jun 27, 2012 at 20:28

I would try it out and look at what you get, sharing verts can produce z fighting on some platforms from some view angles.

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Jun 28, 2012 at 05:08

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!