Hello Marcel,
On 05/04/2014 02:34 PM, Marcel Weiler wrote:
> I am trying to use compute shaders in OpenSG but can't make them work.
> The compute shader should modify the texture of a plane, but it never
> gets activated.
do you mean there is no OpenGL call to launch the compute shader or is
the texture simply unchanged?
> My current setup is as follows: I load the OSGContribComputeBase Library
> using OSG::preloadSharedObject("OSGContribComputeBase") Snippet before I
> call osgInit(argc, argv). Then I set up my scene. The root has two
> children: a node with a geometry core which consists of a plane with a
> texture (ChunkMaterial with MaterialChunk, TextureObjectChunk and
> TextureEnvChunk) and node with an AlgorithmComputeElement core which
> holds the compute shader. The compute shader setup looks as follows
> Snippet
>
> NodeRecPtr computeNode = Node::create();
> AlgorithmComputeElementRecPtr computeElement =
> AlgorithmComputeElement::create();
> ComputeShaderAlgorithmRecPtr computeAlgorithm =
> ComputeShaderAlgorithm::create();
> _comp = OSG::ComputeShaderChunk::create();
> _comp->addUniformVariable("destTex", (int)
> bottom_tex->getGLId());
This looks suspect. I haven't used compute shaders (through OpenSG or
otherwise), but normally texture uniforms are set to the texture unit
the texture is bound to, not the OpenGL id.
Shouldn't bottom_tex be added to MFTextureImages of computeAlgorithm
(this makes sure the texture is activated before executing the shader)?
The id returned by getGLId() is _not_ an OpenGL object name, it is
simply an id OpenSG uses to access the actual OpenGL object on different
contexts. You can use that id together with a context (i.e. OSG::Window)
to get the "real" OpenGL object name (Window::getGLObjectId()).
> _comp->addUniformVariable("roll", 0.0f);
>
> _comp->setComputeProgram(_compute_program);
> TextureImageChunkRecPtr tiChunk =
> TextureImageChunk::create();
> tiChunk->setTexture(bottom_tex);
> tiChunk->setAccess(GL_WRITE_ONLY);
> tiChunk->setFormat(GL_RGBA32F);
> MFUnrecTextureImageChunkPtr * tiChunks =
> computeAlgorithm->editMFTextureImages();
> tiChunks->push_back(tiChunk);
>
> computeAlgorithm->setDispatchConfig(OSG::Vec3i(64, 64, 1));
> computeAlgorithm->setComputeShader(_comp);
> computeElement->setAlgorithm(computeAlgorithm);
> computeNode->setCore(computeElement);
> _scene->addChild(computeNode);
>
> The ComputeShaderChunk _comp is declared as global variable so that I
> can change its uniform variables easily, and bottom_tex is the
> TextureObejctChunk of the plane's material.
The rest looks ok to me, I would double check the texture setup first.
Cheers,
Carsten
------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos. Get
unparalleled scalability from the best Selenium testing platform available.
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users