Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Blending in fragment shader

  1. #1
    Intern Newbie
    Join Date
    Sep 2010
    Posts
    36

    Blending in fragment shader

    Hi guys

    I rendering a volume, that I writing a shader for coloring the volume. The volume is a sampler3D and a transfer function is a sampler3D, but I don't success, because all a cube is colored, ex. gray, I dicovered that lack a composition

    Any idea for implementing a blending in my shader ?

    My initial fragment code is:


    uniform sampler3D VOL;
    uniform sampler1D TF;

    void main(void){

    float pos;
    pos = texture3D(VOL, gl_TexCoord[0].xyz).r;
    gl_FragColor = texture1D(TF, pos);

    }

  2. #2
    Member Regular Contributor
    Join Date
    Apr 2010
    Posts
    493

    Re: Blending in fragment shader

    Blending is usually ordering dependent, i.e. you need to make sure that you render either from front to back or back to front. The usual way to get this for volume rendering is to just draw the front faces of a cube. In the fragment shader for each fragment reconstruct where the ray from the eye position enters and leaves the volume and manually (i.e. with a loop in the fragment shader) trace that ray through the volume.
    Since you are moving along a view ray and basically sample the volume at various points you can easily do this from the furthest to the closest point and blend the values accordingly.

  3. #3
    Intern Newbie
    Join Date
    Sep 2010
    Posts
    36

    Re: Blending in fragment shader


    You are referring to raycasting algorithm, truth? what combinations of blend (source, dest) I can use ? any example ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •