Hi everybody, I've a strange problem with passing some data via a 1d float texture to a shader. There are two debug outputs, one after the image initialization and the other after the texture creation. On both I get correct values. The problem is, the values I get in the shader are always zero. I checked the texture coordinates with a simple gradient texture loaded from file, they seem to look fine. In a previous version of my code I used float textures without problem (only multidimensional). There must be something I'm obviously doing wrong now, but I couldn't figure out what it is. So I'm kind of loss with this problem at the moment.:/ I would be really glad for any help on that issue.
Thanks in advance, Bastian Here's the code: Shader: std::string MainWindow::_vp_program = //"varying vec2 tc;\n" "varying float tc;\n" "void main()\n" "{\n" //"tc = gl_MultiTexCoord0.st;\n" "tc = gl_MultiTexCoord0.s;\n" "gl_Position = ftransform();\n" "}\n"; std::string MainWindow::_fp_program = //"uniform sampler2D curv;\n" "uniform sampler1D curv;\n" //"varying vec2 tc;\n" "varying float tc;\n" "void main()\n" "{\n" //reading value from texture(error!!! value is always 0.0) //"vec3 curvature = texture2D(curv, tc);\n" "vec3 value = texture1D(curv, tc);\n" "vec4 color;\n" //texture coordinates are fine (checked with a simple gradient texture loaded from file) //"color = texture1D(tex, tc);\n" "if(value.x == 0.0 && value.y == 0.0)\n" "{\n" "color = vec4(1.,1.,0.,1.);\n" "}\n" "else{\n" "color = vec4(1.,0.,0.,1.);}\n" "gl_FragColor = color;\n" "}\n"; Programm: . . . //get the geometry positions in triangles std::vector<OSG::Pnt3f> meshData = _dataObject->getMeshData(); OSG::GeometryRecPtr geo = OSG::Geometry::create(); //the new geometry OSG::GeoUInt8PropertyRecPtr type = OSG::GeoUInt8Property::create(); type->addValue(GL_TRIANGLES); OSG::GeoUInt32PropertyRecPtr length = OSG::GeoUInt32Property::create(); length->addValue(meshData.size()); OSG::GeoPnt3fPropertyRecPtr pos = OSG::GeoPnt3fProperty::create(); //OSG::GeoVec2fPropertyRecPtr texCoords = OSG::GeoVec2fProperty::create(); OSG::GeoVec1fPropertyRecPtr texCoords = OSG::GeoVec1fProperty::create(); //fill geometry and texture coordinate data float step = 1.0 / static_cast<float>(meshData.size()); for (unsigned int i = 0; i<meshData.size(); ++i) { pos->addValue(meshData[i]); float texCoord = static_cast<float>(i)*step; //texCoords->addValue(OSG::Vec2f(texCoord, 0.0)); texCoords->addValue(OSG::Vec1f(texCoord)); } OSG::SimpleMaterialRecPtr mat = OSG::SimpleMaterial::create(); geo->setMaterial(mat); geo->setTypes(type); geo->setLengths(length); geo->setPositions(pos); geo->setTexCoords(texCoords); . . . ui.statusBar->showMessage(tr("Initialising shader..."), 3000); OSG::ImageRecPtr someImage = OSG::Image::create(); std::vector<float> data1 = _dataObject->getData1(); std::vector<float> data2 = _dataObject->getData2(); // initialize image data unsigned int size = _dataObject->getSize()*3; OSG::Real32* imageData = new OSG::Real32[size]; int k = 0; for(unsigned int i = 0; i < size; i+=3) { //set r value imageData[i] = data1[k]; //set g value imageData[i+1] = data2[k]; //set b value imageData[i+2] = 0.0; k++; } someImage->set(OSG::Image::OSG_RGB_PF, _dataObject->getSize(), 1, 1, 1, 1, 0, reinterpret_cast<OSG::UInt8*>(imageData), OSG::Image::OSG_FLOAT32_IMAGEDATA); //debug output1: returns valid values float* data = (float*)someImage->getData(); for (int i = 0; i < _dataObject->getSize()*3 ; i++) { qDebug() << data[i]; } OSG::TextureObjChunkRecPtr tex = OSG::TextureObjChunk::create(); tex->setImage(someImage); tex->setMinFilter(GL_NEAREST); tex->setMagFilter(GL_NEAREST); tex->setWrapS(GL_CLAMP); tex->setWrapT(GL_CLAMP); tex->setInternalFormat(GL_RGB32F_ARB); //debug output2: returns valid values float* data = (float*)tex->getImage()->getData(); for (int i = 0; i < _dataObject->getSize()*3 ; i++) { qDebug() << data[i]; } OSG::ChunkMaterialRefPtr cmat = OSG::ChunkMaterial::create(); _shl = OSG::SimpleSHLChunk::create(); _shl->setVertexProgram (_vp_program); _shl->setFragmentProgram(_fp_program); //add the float texture _shl->addUniformVariable("curv", 0); cmat->addChunk(tex); cmat->addChunk(_shl); geo->setMaterial(cmat); OSG::NodeRefPtr node = OSG::Node::create(); node->setCore(geo); node->updateVolume(); ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Opensg-users mailing list Opensg-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensg-users