Passing geometry information to fragment shader

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
duckwottery
Posts: 1
Joined: Mon Jul 25, 2016 11:59 am

Passing geometry information to fragment shader

Post by duckwottery »

Hey,

I want to create a very simple raytracer in GLSL, that refracts the view rays at a water plane perpendicular to the camera. The shader is really simple. No recursion needed. Right now the intersection point with the water plane is calculated and a new ray is spawned that checks for intersection with each triangle behind the water plane. The shader is ready and works fine with hard coded vertex positions and uv information in the shader.

Now I need to find a way to pass the geometry informations of an object to the fragment shader. How could one do this properly in irrlicht?

What I tried so far:

1) I tried to use a shader callback to pass some test array to irrlicht, but this didn't work:

Code: Select all

 
        
class MyShaderCallBack : public video::IShaderConstantSetCallBack
{
public:
 
    virtual void OnSetConstants(video::IMaterialRendererServices* services,
            s32 userData)
    {
 
        myArray[0] = 2.3;
        myArray[1] = 5.8;
        myArray[2] = 9.1;
        myArray[3] = 5.1;
        myArray[4] = 4.4;
        myArray[5] = 2.3;
        myArray[6] = 5.8;
        myArray[7] = 9.1;
        myArray[8] = 5.1;
        myArray[9] = 4.4;
 
        services->setVertexShaderConstant("myArray",reinterpret_cast<f32*>(&myArray[0]), 10);
 
    }
 
    float myArray[10];
};
 
 
 
2) I tried to figure out if its possible to decode the positions of the vertecies in a texture and pass this texture to the fragment shader. This first seems to work, but then I realized that I only can pass ints between 0...255 to the ITexture->setPixel() function (which makes sense anyway).
 

Code: Select all

 
    // Create a 1x1000 image
    irr::video::IImage *verts = p->smgr->getVideoDriver()->createImage(
        irr::video::ECF_A8R8G8B8, irr::core::dimension2d<irr::u32>(10000, 1));
    
    // Fill Pixels with some values
    verts->setPixel( 0, 0, irr::video::SColorf(255, 255, 0, 0));
    
    // Convert it to texture
    ITexture *ttt = p->smgr->getVideoDriver()->addTexture("verts.png", verts);
 
 

UPDATE: I found out that its possible to create a Texture with floating point color format (e.g. ECOLOR_FORMAT::ECF_R16F). However, when I try to run this code its says "Could not create IImage, format only supported for render target textures". My question now is, when I render to texture, will it be possible to pass this floating point texture to the fragment shader?





3) I read something about unified buffers in openGL. They may would solve the problem. But I cant figure out if they are available in Irrlicht. Is there something like that?

Thanks in advice.
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Passing geometry information to fragment shader

Post by Mel »

I found out that its possible to create a Texture with floating point color format (e.g. ECOLOR_FORMAT::ECF_R16F). However, when I try to run this code its says "Could not create IImage, format only supported for render target textures". My question now is, when I render to texture, will it be possible to pass this floating point texture to the fragment shader?
Yes, Render target textures work like any other texture, the most important detail you might need to keep in mind is that their size should be as close to a power of 2 as posible. internally, the driver will allocate memory as it needs, and with the proper size and alignment. But you can lock and unlock them the same (and that way get to their data) and set them as any other textures to the materials.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Post Reply