开发者

How to draw a triangle with own texture on each corner?

开发者 https://www.devze.com 2023-03-26 12:54 出处:网络
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.

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号