Ogre Version: 14-3-4
Operating System: Kubuntu 24.10 (running on X11)
Render System: OpenGL Rendering Subsystem
Hello guys!
This is my first post on this forum.
I have applied a fragment shader to an entity using GPU Program Scripts. This works fine and the shader appears on the entity’s mesh and is displayed correctly. However, I would now like to use Shared Parameters to send Shader Storage Buffer Objects containing voxel data from the CPU to the GPU.
Let’s keep things simple. Rather than create a buffer, I’ll try to simply define a simple integer as a shared parameter, similarly to how this example project does it:
MyMaterial.material:
Code: Select all
shared_params YourSharedParamsName
{
shared_param_named mySharedParam1 uint 1
}
fragment_program MyFragmentShader glsl
{
source MyShader.glsl
default_params
{
param_named alpha_value float 0.4
param_named_auto time time_0_x 100
shared_params_ref YourSharedParamsName
}
}
material MyMaterial
{
technique
{
pass
{
lighting off
fragment_program_ref MyFragmentShader
{
}
}
}
}
MyShader.glsl:
Code: Select all
#version 400
uniform float alpha_value;
uniform float time;
buffer YourSharedParamsName
{
uint mySharedParam1;
};
out vec4 fragColor;
void main()
{
uint counter = atomicAdd(mySharedParam1, 1);
uint myValue = counter;
vec4 color;
color.x = 1.0; // Red
color.y = myValue == 0 ? 0.0 : 1.0; // Green
color.z = 0.0; // Blue
fragColor = color;
}
I initialize mySharedParam1
to 1 in the material script and atomically increment it by 1 in the shader itself, and yet the result looks like this:
I would have expected the cube to appear yellow (since the green channel should be 1.0), but it’s red, instead.
Changing the value of the mySharedParam1
variable in the C++ code like this also has no effect:
Code: Select all
auto material = Ogre::MaterialManager::getSingleton().getByName("MyMaterial");
Ogre::GpuProgramManager::getSingleton()
.getSharedParameters("YourSharedParamsName")
->setNamedConstant("mySharedParam1", 10);
auto* ogreEntity = sceneMan->createEntity("cube.mesh");
auto* ogreNode = sceneMan->getRootSceneNode()->createChildSceneNode();
ogreNode->attachObject(ogreEntity);
ogreEntity->setMaterial(material);
I’ve had the same exact experience with all other data types I’ve tried (integers, floats, vectors, arrays). I’ve also tried defining the shared parameters programmatically using Ogre::GpuProgramManager::getSingleton().createSharedParameters()
, but to no avail. The uniform values (alpha_value
and time
) have the correct, value, though, and I do not see any shader-related errors in the console output.
What am I missing?