GLSL Shader SColorf passing

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

GLSL Shader SColorf passing

Post by Seven »

Is there a simpler method than this to pass an SColorf variable?

Code: Select all

			SColorf c = m_Level->getSmgr()->getAmbientLight();
			float ac[4];
			ac[0] = c.getRed();
			ac[1] = c.getBlue();
			ac[2] = c.getGreen();
			ac[3] = c.getAlpha();
			services->setVertexShaderConstant(m_AmbientLightID, ac, 4);
thanks in advance,
Seven
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: GLSL Shader SColorf passing

Post by CuteAlien »

As SColorf already has 4 floats inside so I suppose you could also pass c directly instead of copying. I suppose packing shouldn't really get in the way with 4 32 bit values (just mentioning it as it's probably the main difference - it's 4 independent floats instead of an array, but I don't suppose there is a platform which would add packing bytes for this case).
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
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: GLSL Shader SColorf passing

Post by Seven »

Thanks. I am beginning my shader journey and so far am enjoying it.
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: GLSL Shader SColorf passing

Post by Seven »

sorry, but another shader parameter passing question.

I would like to pass a texture to a shader from within the callback function. I create the ITexture* in the shader callback. In this particular case, I do not want the texture to be a member of node's material, ( I can pass those around fine) but rather a stand alone texture that the shader can use in addition to the textures that are part of the ode's material.

I cant find a method to do this though. Is there such a method in irrlicht?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: GLSL Shader SColorf passing

Post by CuteAlien »

Not really. Badly missing feature in Irrlicht so far. Irrlicht trunk allows at least to use more textures (up to 8) in SMaterial, but all other textures can only be accessed with some hacks.
Basically you have to work around Irrlicht and use OpenGL/Direct3D directly. And then bind textures to numbers above _IRR_MATERIAL_MAX_TEXTURES_.
Generally I try to avoid it and just set SMaterial textures.

edit: Some solution which we have in our project (one of DevSH's guys helped us there once).
Note, instead of hacking around accessing Irrlicht internals you can also look at the corresponding functions and just directly use OpenGL functions (cleaner code, this solution is not really the way to use a library usually).

Code: Select all

// Include source headers from Irrlicht engine 
#include "../source/Irrlicht/COpenGLDriver.h"
#include "../source/Irrlicht/COpenGLCommon.h"
#include "../source/Irrlicht/COpenGLCoreTexture.h"
#include "../source/Irrlicht/COpenGLCacheHandler.h"

// Now you can directly cast to the COpenGLDriver from the IVideoDriver* (assuming you actually use opengl)
video::COpenGLDriver* gldriver = static_cast<video::COpenGLDriver*>(videoDriver);

// create some texture
irr::u32 GL_randomTexture = 0;
irr::u32 RAND_TEX_SZ = 64u;
GLubyte* pixels = new GLubyte[RAND_TEX_SZ * RAND_TEX_SZ];	// should be filled with some colors probably
gldriver->extGlCreateTextures(GL_TEXTURE_2D, 1, &GL_randomTexture);
gldriver->extGlTextureStorage2D(GL_randomTexture, GL_TEXTURE_2D, (GLsizei)(log2(RAND_TEX_SZ) + 1.5f), GL_R8, RAND_TEX_SZ, RAND_TEX_SZ);
gldriver->extGlTextureSubImage2D(GL_randomTexture, GL_TEXTURE_2D, 0, 0, 0, RAND_TEX_SZ, RAND_TEX_SZ, GL_RED, GL_UNSIGNED_BYTE, pixels);
gldriver->extGlTextureParameteri(GL_randomTexture, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
gldriver->extGlTextureParameteri(GL_randomTexture, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gldriver->extGlTextureParameteri(GL_randomTexture, GL_TEXTURE_WRAP_S, GL_REPEAT);
gldriver->extGlTextureParameteri(GL_randomTexture, GL_TEXTURE_WRAP_T, GL_REPEAT);
if (gldriver->queryOpenGLFeature(irr::video::COpenGLExtensionHandler::IRR_EXT_texture_filter_anisotropic) || gldriver->Version >= 406)
	gldriver->extGlTextureParameteri(GL_randomTexture, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16);
gldriver->extGlGenerateTextureMipmap(GL_randomTexture, GL_TEXTURE_2D);
delete[] pixels;

// bind it
GLenum randTexTarget = GL_TEXTURE_2D;
gldriver->extGlBindTextures(_IRR_MATERIAL_MAX_TEXTURES_ + 1, 1, &GL_randomTexture, &randTexTarget);

// delete it
if (GL_randomTexture)
{
	glDeleteTextures(1, &GL_randomTexture);
	GL_randomTexture = 0;
}
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
Post Reply