3

Basically, i want to give 3 textures for each corner of a triangle, and interpolate from one texture to another, just like the colors would be interpolated with glColor() on the corners.

Edit: Since this doesnt seem to be possible via texture combiners, i am willing to do it with shaders.

This is the fragment shader code that i have now:

vec4 c = gl_Color;
gl_FragColor = texture2D(Texture0, TexCoord0)*c.r+texture2D(Texture1, TexCoord1)*c.g+texture2D(Texture2, TexCoord2)*c.b;

Im using the glColor(); to push colors (1,0,0), (0,1,0), (0,0,1) to the corners of each triangle, and then i read the color to see how much which texture i need to blend accordingly.

Now the problem is that i cant use colors on my vertices anymore, so im asking, what is the best approach for telling my fragment shader how to blend the textures + being able to use glColor() on each corner of the triangle to apply some coloring?

Edit2: i managed to get it work by sending a 3d texcoord that tells the blending ratios, but is this the best approach? i would like to hear more ideas on this.

Rookie
  • 3,753
  • 5
  • 33
  • 33

1 Answers1

1

I don't think this is possible without using shaders. In your OpenGl code, I don't see anyway OpenGl could know which texture to affect to each corner. That would require a vertex property (other than color or texture coordinates), which is not possible without shaders.

However, maybe it can be possible with two textures, by using alpha blending (picking alpha value from the vertex color) on the second texture. but I'm not sure.

neodelphi
  • 2,706
  • 1
  • 15
  • 22
  • yeah i thought about drawing 3 triangles on top of each: first solid, then the rest two with opposite corner colors with zero alpha. but this will take 3 times more pixels to draw, so it can get really slow... also the problem with this approach is that i cant use a fourth texture on them, or i could, but then i need to draw it on ALL of the 3 triangles, which results total 6x slower rendering.lol. – Rookie Aug 08 '11 at 17:42
  • 1
    That's not what I really meant. Using two texture with one triangle, not two triangles, but I've never done multitexturing without shaders - Don't know if its possible. Just a question: why can't you use shaders ? Are you developping on an embeded platform ? – neodelphi Aug 08 '11 at 17:44
  • i want to provide non-shader version since this will be a main part of the game graphics, so if shaders arent available, the game will still look bearable. – Rookie Aug 08 '11 at 17:47
  • Ok, I understand. Personnally, I did the choice to always use shaders, since it requires lot of development to support old graphic cards or exotic platforms. – neodelphi Aug 08 '11 at 17:52
  • I managed to make a shader for it, but there are some problems. Im giving each vertex colors (1,0,0), (0,1,0), (0,0,1). then i do: `gl_FragColor = tex1*r+tex2*g+tex3*b`, but the problem is that i cant then use glColor for my vertices at all now. Is there some other way to imitate the mechanics of glColor so it blends the values between vertices? Or perhaps any better method for blending values between the corners to get the intensity of each texture? – Rookie Aug 08 '11 at 20:55
  • @Rookie: this is not a forum. If you have a new question, then create a new question. – Nicol Bolas Aug 08 '11 at 21:31
  • @Nicol, its still the same question... i could edit my question though since i guess i have to do it via shaders. – Rookie Aug 08 '11 at 22:11
  • You should not use immediate mode with shaders for what you want to do. Instead, use vertex array objects and vertex buffer objects - that will allow you to completely control the properties of a vertex (for example, if you want, you can assign two colors per vertex, or a color with 6 components...). Note that this is modern techniques - maybe there is another way to do which can be compatible with old hardware. – neodelphi Aug 11 '11 at 06:30
  • then how do i assign two colors per vertex? glVertexAttr() ? these will be interpolated per vertex? o.O - btw i know VBO and im using them i only said glColor so you understand what its results should be like. – Rookie Aug 11 '11 at 16:06
  • The function glBufferData allow you to specify the size in memory of one vertice. Then glEnableVertexAttribArray and glVertexAttribPointer will help you to configure which bytes of a vertex are attributed to which shader input. In the shader, you can use custom vertex attributes for color instead of gl_Color. – neodelphi Aug 12 '11 at 06:16
  • so glattribute will scale like color, thats what i wanted to hear. – Rookie Aug 12 '11 at 15:04
  • In modern OpenGl, there are no position or color concept, all you give to the shaders are floating point vectors. You can give as many as you want (up to the hardware limit of course), and decide their functionality. That's why you can have three colors per vertex. Maybe three alpha components may be best for performances if you want the same RGB for all textures - that's up to you to decide. – neodelphi Aug 12 '11 at 16:12