Jump to content
  • Advertisement
Sign in to follow this  
cbadboy

OpenGL How to combine multiple materials?

This topic is 3122 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi..I'm fairly new to OpenGL so I have some questions... I'm developing an ASE file importer for a friend. Basics working fine, now i got in some trouble by a model using multiple materials. He modelled a cube using different materials (in the file defined as submaterials) using different texture coordinates and textures comined to the facees of the cube. By this way it's possible to add a smaler texture somewhere on the face on top of another texture (i.e. a smaler logo or text which could be placed and manipulated by the user somewere on a rustysteel plane, or debris after a hit based on collision values). I kow i could use OpenGL multitexturing (later i will use shaders too) to combine textures and different texture coords. But how i could archive this, I.e. on a simple plane? If i got a plane i got 4 Vertices, and for each vertex and multiple texture coordinates in range [0,1]. I.e: Vertex lower left: Pos -5, -5, 0 Texture 1 0,0 Vertex lower right: Pos 5, -5, 0 Texture 1 1,0 Vertex upper right: Pos 5, 5, 0 Texture 1 1,1 Vertex upper left: Pos -5, 5, 0 Texture 1 0,1 Now i twist my mind how i could add a second texture, i. e. in the middle of that plane using another texture definition and not a texture with an alpha range using same coordinates for fix placing. A friend of mine told me that it may a good way to define a subgeometry with an own texture to place it at the correct position .... Is this the only solution? And how i could archive combination of those textures to archive tranparency or color multiplication? Has anyone an idea to point me in the right direction?

Share this post


Link to post
Share on other sites
Advertisement
You can only define a texcoord at a vertex, so if you want to lay a small texture over a small section of that plane, you need to break it up more into smaller vertices.

Using your example, if you wanted to have the big texture cover the whole plane, and a small decal (for example lets say from (2,2) to (3,3)).

Just subdivide the big plane, for simplicity divide it into 100 squares of area 1.

Then you will define your vertices like this:

Pos : UV0 : UV1
(-5,-5) : (-1,-1) : unused
(-5,-4) : (-1,-0.9) : unused
....etc
(2,2) : (0.7,0.7) : (0,0)
(2,3) : (0.7,0.8) : (0,1)
(3,2) : (0.8,0.7) : (1,0)
(3,3) : (0.8,0.8) : (1,1)
(5,5) : (1,1) : unused


You can overlay the two textures or blend them together in the region from (2,2) to (3,3) probably with some fixed-pipeline multitexturing functions, or use a shader where you can sample both textures and use any function you like to arrive at the fragment color.

Share this post


Link to post
Share on other sites
Thanks karwosts! That sounds very logical. And it explains why ASE allows the definition of light colors in each material.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!