Jump to content


Two sided texture


11 replies to this topic

#1 Alienizer

    Member

  • Members
  • PipPipPipPip
  • 440 posts

Posted 27 June 2012 - 12:47 AM

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.

#2 Alienizer

    Member

  • Members
  • PipPipPipPip
  • 440 posts

Posted 27 June 2012 - 01:05 AM

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?

#3 David Gallagher

    New Member

  • Members
  • PipPip
  • 69 posts

Posted 27 June 2012 - 02:43 AM

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.

#4 Alienizer

    Member

  • Members
  • PipPipPipPip
  • 440 posts

Posted 27 June 2012 - 03:57 AM

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

#5 David Gallagher

    New Member

  • Members
  • PipPip
  • 69 posts

Posted 27 June 2012 - 04:21 AM

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

#6 Stainless

    Member

  • Members
  • PipPipPipPip
  • 610 posts
  • LocationSouthampton

Posted 27 June 2012 - 08:35 AM

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.

#7 .oisyn

    DevMaster Staff

  • Moderators
  • 1842 posts

Posted 27 June 2012 - 09:38 AM

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.
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.

#8 }:+()___ (Smile)

    Member

  • Members
  • PipPipPip
  • 169 posts

Posted 27 June 2012 - 10:31 AM

You can determine back/front facing in shader (gl_FrontFacing in OpenGL) and then sample different textures.
Sorry my broken english!

#9 Reedbeta

    DevMaster Staff

  • Administrators
  • 5344 posts
  • LocationSanta Clara, CA

Posted 27 June 2012 - 10:38 AM

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.)
reedbeta.com - developer blog, OpenGL demos, and other projects

#10 TheNut

    Senior Member

  • Moderators
  • 1719 posts
  • LocationCyberspace

Posted 27 June 2012 - 01:51 PM

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.
http://www.nutty.ca - Being a nut has its advantages.

#11 Stainless

    Member

  • Members
  • PipPipPipPip
  • 610 posts
  • LocationSouthampton

Posted 27 June 2012 - 08:28 PM

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

#12 Alienizer

    Member

  • Members
  • PipPipPipPip
  • 440 posts

Posted 28 June 2012 - 05:08 AM

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!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users