1
\$\begingroup\$

I am using LWJGL libraries to code myself a game. I want to be able to import a project from blender to my game. I have the wavefront .obj reader and it works perfectly for my needs. Although because my model uses multiple images I do not know how to set that up in my game engine. All it does is stretch the first image I send to the shaders across the entire model. Then I ran across a couple videos that makes me doubt that GLSL can support multiple images. Also, I found a couple solutions but they were depreciated because I use LWJGL 3 with slick-util 3 to load the image.

So I would first like to know, does GLSL support rendering multiple images on a single object?

If GLSL can support rendering multiple images on a single object, how would I proceed conceptually to perform this feat?

P.S. Let me know if want images or anything to better understand my question. Thank you all!

\$\endgroup\$
2
\$\begingroup\$

"Multitexturing" is an OpenGL feature from before programmable shaders; shaders pretty much made the concept obsolete, and it was quickly deprecated. Any websites you read which talk about "multitexturing" probably predate programmable shaders.

With programmable shaders (GLSL), you can just define multiple texture samplers in your fragment shader and use them however you want.

To do something like what OpenGL's "multisampling" used to do, you'd just create two or more texture samplers in your fragment shader, bind textures to each of them from your engine, and then have your shader read color values from them and combine those color values however you want. Add them together, subtract them, mix between them, or whatever else you want. You can even sample multiple times from the same texture using different texture coordinates, if you want.

There's really nothing fancy to it; it's an awful lot simpler and more flexible than multisampling ever was. Read any tutorial on GLSL and you'll get the gist of it. If you know how to do texture mapping, just do that twice inside the same shader and you've got your equivalent of multitexturing.

\$\endgroup\$
3
  • \$\begingroup\$ Alright, thanks! I am able to send multiple images to the shader. Although now, I have no idea how to set up the color values so that they may show in their respective areas. In Blender, they show up in their respective areas. When I add the color values together, I get a super bright white but when I multiply them together I get a dark texture. Do you know how I am able to manipulate the color values so that the image textures show up in their respective areas? \$\endgroup\$ – Abdallah Hasan Mar 8 '17 at 3:34
  • \$\begingroup\$ @AbdallahHasan multiply the texture samples with a weight before adding them. That weight can depend on various things like the angle between the lights and the reflected eye vector, some vertex attributed passed from the vertex shader,... \$\endgroup\$ – ratchet freak Mar 9 '17 at 10:27
  • \$\begingroup\$ @AbdallahHasan One usual thing to do is to simply blend between color samples, often by using GLSL's builtin mix( colorValueA, colorValueB, 0.5). In my game, I have transparency in my textures, and use the alpha channel of one texture to opaquely layer it "on top" of the previous texture so that they appear to be layers. The lower layer "shows through" the higher layer's transparent bits, simply by doing mix( colorValue A.rgb, colorValueB.rgb, colorValueB.a ). All sorts of other things you can do; the shader is fully programmable, after all. Only limit is what you can think of. \$\endgroup\$ – Trevor Powell Mar 9 '17 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.