TGEA 1.8.x possible bug - get Shader Const Handle to a sampler2D shader constant
by Jay Verba · in Torque Game Engine Advanced · 02/13/2009 (12:33 pm) · 2 replies
Put a break point on line 147 of clipMapBlenderCache.cpp to see this in action. All of the shader constant handles that reference sampler2D constants are 0 after the getShaderConstHandle() call.
I believe these should be returning something valid.
I believe these should be returning something valid.
#2
When converting your DirectX/HLSL shaders to OpenGL/GLSL, the texture samplers need special attention. Failure to do this will result in ALL your sampler2D's referencing the same texture.
1. Create a GFXShaderConstHandle for your sampler2D variable
2. Link it with your GLSL sampler2D variable
3. Finally, set it to the sampler number you're using
Enjoy your working texture sampler in OpenGL/GLSL :)
Lorne
07/24/2009 (12:28 am)
I'd just like to add a quick "tutorial" to this thread to drive the point home. I wasted nearly 6 hours today on this tiny issue! (before I saw this thread - doh)When converting your DirectX/HLSL shaders to OpenGL/GLSL, the texture samplers need special attention. Failure to do this will result in ALL your sampler2D's referencing the same texture.
1. Create a GFXShaderConstHandle for your sampler2D variable
GFXShaderConstHandle* myTextureSampler1SC; GFXShaderConstHandle* myTextureSampler2SC;
2. Link it with your GLSL sampler2D variable
myTextureSampler1SC = myShaderData->getShader()->getShaderConstHandle("$MyTextureSampler1");
myTextureSampler2SC = myShaderData->getShader()->getShaderConstHandle("$MyTextureSampler2");3. Finally, set it to the sampler number you're using
mySCB->set(myTextureSampler1SC, (S32)0); //Corresponds to GFX->setTexture( 0, ... mySCB->set(myTextureSampler2SC, (S32)1); //Corresponds to GFX->setTexture( 1, ...
Enjoy your working texture sampler in OpenGL/GLSL :)
Lorne
Associate Alex Scarborough
HLSL hardcodes the sampler number directly in the shader and you are not allowed to change it. In GLSL you cannot put the sampler number in the shader and you must set it.