Hi!
I have create a IAnimatedMeshSceneNode to load a animatedMesh, and wrote a lighting shader and a shadow shader with GLSL. Now I need to add both lighting effect and shadow effect to the same animatedMeshSceneNode using setMaterialType(). I tried to call setMaterialType() twice. But the second will cover the first type I set. How can I realize it.
If anynone have a good idea, please let me know. Thanks a lot!
How can I set more than one material type for the node
-
- Competition winner
- Posts: 523
- Joined: Tue Jan 15, 2013 6:36 pm
Re: How can I set more than one material type for the node
Has to be in the same shader. So just make your shader into one file.
Re: How can I set more than one material type for the node
Sorry, both the gl_position and gl_FragColor are diffent in the two shaders. How can I put them into one file. Maybe I can use if...else... in the shader. If I do this, How can I give the flag number in the OnsetConstants().
If anyone knows, please let me know. Thank you very much!
If anyone knows, please let me know. Thank you very much!
Re: How can I set more than one material type for the node
Please no cross-posting th same question into several threads - otherwise the discussion get's split all over the forum which makes it always very hard to talk about a topic. So I'm going to remove your other post.
I don't get yet what exactly you try to do, but you can pass additional parameters between a vertex and a fragment shader. If that is not sufficient you might need to do multiple stages. Which means you render intermediate results into a rendertarget texture. Then you render your scene several times switching materials in between the rendering. And as last stage you have a shader that combines those intermediate textures. That last step is usually done by putting them on a quad mesh (2 triangles) which has the screen-size and then pass the intermediate textures as textures for that quad. I heard XEffects also works like that, so you might take a look at that.
I don't get yet what exactly you try to do, but you can pass additional parameters between a vertex and a fragment shader. If that is not sufficient you might need to do multiple stages. Which means you render intermediate results into a rendertarget texture. Then you render your scene several times switching materials in between the rendering. And as last stage you have a shader that combines those intermediate textures. That last step is usually done by putting them on a quad mesh (2 triangles) which has the screen-size and then pass the intermediate textures as textures for that quad. I heard XEffects also works like that, so you might take a look at that.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 40
- Joined: Sat Feb 06, 2010 9:00 pm
- Location: Ohio, USA
Re: How can I set more than one material type for the node
I think I see what you're really looking for here, how to implement multiple GL textures in the fragment shader, yes? I ran into this issue myself when I was new with Irrlicht and OpenGL, trying to have multiple texture samplers in the fragment shader, such as:yuange wrote:Hi!
I have create a IAnimatedMeshSceneNode to load a animatedMesh, and wrote a lighting shader and a shadow shader with GLSL. Now I need to add both lighting effect and shadow effect to the same animatedMeshSceneNode using setMaterialType(). I tried to call setMaterialType() twice. But the second will cover the first type I set. How can I realize it.
If anynone have a good idea, please let me know. Thanks a lot!
sampler2D texA;
sampler2D texB;
...and then making texture() calls to both, to mix multiple image textures.
If I'm getting you right, what you want is *ONE* Irrlicht material, which has a different graphic image texture on different layers. If you look at the SMaterial class, you'll see that an Irrlicht material has more than one layer. If you haven't re-compiled the engine and are using a regular release build you downloaded, you probably have a limit of 4 layers max for any Irrlicht material. (By editing the configuration header and tweaking a #define, you can bump it all the way up to 8, assuming your graphics card supports it.)
So look at the SMaterial interface, the functions is has for stuff with the different layers, you should be able to figure it out. Finally, after setting up your material with multiple layers, you call setMaterial() with the one, multi-layered material, and so forth (if you need more help further than that, just ask)...
EDIT: Whoops! My fault, I read your post too quickly. For shadows, you want a shadow sampler in the shader, not a standard one.
Take a look at: http://www.opengl.org/sdk/docs/man4/index.php and choose the entry "texture" from the index on the left pane, and read about how it applies to shadow samplers.
Another helpful resource: http://www.opengl.org/wiki/Sampler_%28GLSL%29
- - - -
"Destructavator" Dave: Developer of OS GPL VST "ScorchCrafter" Audio Plug-ins, contributer to UFO AI, Day Job: Guitar Luthier (Customize musical instruments, repainting w/ custom artwork, graphics, logos, decals, etc.)
"Destructavator" Dave: Developer of OS GPL VST "ScorchCrafter" Audio Plug-ins, contributer to UFO AI, Day Job: Guitar Luthier (Customize musical instruments, repainting w/ custom artwork, graphics, logos, decals, etc.)