Re: [osg-users] passing uniforms to compute shader
Hi, ok, maybe it is easier in that way. Here are the uniforms of the compute shader: Code: struct PointLight { vec4 position; vec4 color; vec4 paddingAndRadius; }; // Shader storage buffer objects layout(std140) uniform LightBuffer { PointLight data[1024]; } ; layout (binding = 0, r32f) writeonly uniform image2D targetTex; // Uniforms uniform sampler2D depthMap; uniform vec2 screenSize; uniform int lightCount; uniform mat4 projectionMatrix; uniform mat4 viewMatrix; // Shared values between all the threads in the group shared uint minDepthInt; shared uint maxDepthInt; shared uint visibleLightCount; shared vec4 frustumPlanes[6]; shared mat4 viewProjection; #define TILE_SIZE 1 layout(local_size_x = TILE_SIZE, local_size_y = TILE_SIZE, local_size_z = 1) in; And the uniforms of the fragment shader: Code: struct PointLight { vec4 position; vec4 color; vec4 paddingAndRadius; }; // Shader storage buffer objects layout(std140) uniform LightBuffer{ PointLight data[1024]; } ; uniform sampler2D VisibleLightIndicesBuffer; uniform int numberOfTilesX; uniform int totalLightCount; And how I bind them to the compute shader: Code: computeShaderStateset->addUniform(new osg::Uniform("depthMap",2)); computeShaderStateset->setTextureAttributeAndModes(2,depthTexture, osg::StateAttribute::ON); computeShaderStateset->addUniform(new osg::Uniform("screenSize", osg::Vec2(windowWidth, windowHeight))); computeShaderStateset->addUniform(new osg::Uniform("lightCount", (int) lights->size())); computeShaderStateset->getOrCreateUniform("projectionMatrix", osg::Uniform::FLOAT_MAT4)->set(projectionMatrix); computeShaderStateset->getOrCreateUniform("viewMatrix", osg::Uniform::FLOAT_MAT4)->set(viewMatrix); //indices osg::ref_ptr indexTexture = new osg::Texture2D; indexTexture->setTextureSize(1024, 1024); indexTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture2D::LINEAR); indexTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture2D::LINEAR); indexTexture->setInternalFormat(GL_R32F); indexTexture->setSourceFormat(GL_RED); indexTexture->setSourceType(GL_FLOAT); indexTexture->bindToImageUnit(0, osg::Texture::WRITE_ONLY); computeShaderStateset->addUniform(new osg::Uniform("targetTex", (int)0)); computeShaderStateset->setTextureAttributeAndModes(0, indexTexture.get()); //lights std::vector byteLights = convertLightVector(lights); osg::ByteArray* bytes = new osg::ByteArray([0], [sizeof(byteLights) * sizeof(char) * byteLights.size()]); osg::UniformBufferObject* uboLights = new osg::UniformBufferObject; uboLights->setUsage(GL_STATIC_DRAW); uboLights->setDataVariance(osg::Object::STATIC); bytes->setBufferObject(uboLights); osg::UniformBufferBinding* ubbLights = new osg::UniformBufferBinding(10, uboLights, 0, bytes->size()); computeShaderStateset->setAttributeAndModes(ubbLights, osg::StateAttribute::ON); computeShaderProgram->addBindUniformBlock("LightBuffer", 10); And to the fragment shader: Code: //Uniforms mStateset->addUniform(new osg::Uniform("numberOfTilesX", (int) ((windowWidth + (windowWidth % 16)) / 16) )); mStateset->addUniform(new osg::Uniform("totalLightCount", (int) lights->size())); //indices mStateset->addUniform(new osg::Uniform("VisibleLightIndicesBuffer",1)); mStateset->setTextureAttributeAndModes(1,indices, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); //lights std::vector byteLights = convertLightVector(lights); osg::ByteArray* bytes = new osg::ByteArray([0], [sizeof(byteLights) * sizeof(char) * byteLights.size()]); osg::UniformBufferObject* uboLights = new osg::UniformBufferObject; uboLights->setUsage(GL_STATIC_DRAW); uboLights->setDataVariance(osg::Object::STATIC); bytes->setBufferObject(uboLights); osg::UniformBufferBinding* ubbLights = new osg::UniformBufferBinding(0, uboLights, 0, bytes->size()); mStateset->setAttributeAndModes(ubbLights, osg::StateAttribute::ON); lightShader->addBindUniformBlock("LightBuffer", 0); The part how I pass the lights is the same, but in the case of compute shader nothing happens, no light arrives. All uniforms have a reasonable value in the fragment shader, but they are always 0 (or empty), except the image2D targetTex object, in the compute shader. I checked all variables in the code, and I know, that their value is ok, so the mistake is surely in binding, but I don't know where. Thank you for any help! Cheers, Mary-Ann -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=69184#69184 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] passing uniforms to compute shader
Hi everyone, I am trying to write a functional compute shader, but the uniforms dont't want to work. I have a compute and a usual shader program currently. The compute shader has to write a texture, which can be read by the usual shader. This part works fine. But I would like to pass some (custom) uniforms (lights, amount of the light sources, projection/view matrix etc.). I use the same method by the two shaders, , but the data seems to arrive only by the usual shader program. I thought something could be wrong with the compute shader, but the texture data is there, so the communication is working. Should I pass the uniforms in an other way, when I have to send data to a compute shader? I can't figure it out, where is the mistake... Thanks a lot :) Mary-Ann -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=69145#69145 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] convert std::vector to osg::BufferObject
Hi guys, I have some problems with passing an std::vector to my shader as a uniform, and I was wondering, if anyone has some idea, how to do this. So my issue is that an std::vector of a custom defined data type have to get bound to the shader. I have an osg::UniformBufferObject and I would like to fill it with addBufferData(myVector). The problem is, that this method expects an osg BufferObject, and I can not figure it out, how I could convert my custom vector. I thought it should be possible, to create an osg::Array with any (custom) data type. But it seems, that you can only use the from osg predefined objects. So is there maybe an other way, to convert a vector to a BufferObject or am I doing something wrong? :/ Thank you! Cheers, Mary -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=68847#68847 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Attaching children to the prerender camera
Hi Nick, Thank you for your answer. I have a callback now, which prints every time the texture image to file, when the framebuffer is rendered. I also added a debug line to the fragment shader, so I can see, that my shader is able to render. But it still can not see the objects in the scene graph, although I am sure, that the view and projection matrix is set properly. May you have any idea, where I am doing a mistake? Thanks for your help! Mary-Ann -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=68684#68684 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Attaching children to the prerender camera
Hi, I am pretty new in OSG, so sorry if I am asking a bit noob question. But I am stuck on this problem, and have no idea how I could solve it. So I would like to prerender my scene into a framebuffer to have a depth map. I tested everything, my shader seems to work if I am using it in my main rendering pass, and it is being called in my prerender pass too. But for some reason it can not see the objects of the scene, so the depthmap gets black (I do linearize the depth values in the fragment shader too). I think the problem is, that I do not attach the subgraph to the framebuffer camera properly, but I can not figure it out, what I am missing. So please help, I do not have any new ideas anymore :( Here is the code: Code: camera = new osg::Camera;; camera->setViewport(0, 0, m_textureSizeX, m_textureSizeY); camera->setClearColor( osg::Vec4() ); camera->setClearMask( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT ); camera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT, osg::Camera::PIXEL_BUFFER_RTT ); camera->setRenderOrder( osg::Camera::PRE_RENDER ); camera->setReferenceFrame( osg::Transform::ABSOLUTE_RF ); camera->setProjectionMatrix( osg::Matrix::ortho2D(0.0, 1.0, 0.0, 1.0) ); camera->setViewMatrix( osg::Matrix::identity() ); m_depthTexture = new osg::Texture2D; m_depthTexture->setTextureSize(m_textureSizeX, m_textureSizeY); m_depthTexture->setInternalFormat(GL_RGBA); m_depthTexture->setDataVariance(osg::Object::DYNAMIC); m_depthTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR); m_depthTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); m_depthTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); m_depthTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT); m_depthTexture->setResizeNonPowerOfTwoHint(false); m_texImage = new osg::Image; m_texImage->allocateImage(m_textureSizeX, m_textureSizeY, 1, GL_RGBA, GL_UNSIGNED_BYTE); camera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER), m_texImage); m_depthTexture->setImage(0, m_texImage); //m_DBRoot is filled by init(), I checked and the subgraph is there camera->addChild(m_DBRoot.get()); //the root of the scene graph root->addChild(camera.get()); Thank you! Cheers, Mary-Ann -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=68663#68663 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org