PDA

View Full Version : backgroundcolor in raycasting(volume renderining)



lobbel
06-17-2009, 05:13 AM
Hello there,
i have a problem with changeing the backgroundcolor
while doing gpu raycasting (volume rendeirng).
When i change the color, the color of the bounding box is still black with the rendered volume inside
but the area around is colored with the backgroundcolor i have set with glClearColor.

Any ideas how to solve this problem?

regards,
lobbel

scratt
06-17-2009, 05:27 AM
No idea without you posting some code of some sort, or more details...

How are you drawing the rendered data, or the bounding box for that matter?

dletozeun
06-17-2009, 05:46 AM
How the background is drawn? Plain color or a skybox?
You need to add the contribution of the background color at the end of the ray you cast minus all attenuation along the ray segment in the volume.

To you can render to a texture the background first then fetch the texture in the raycasting shader.

lobbel
06-18-2009, 02:29 PM
Hello,

here is a part of my code, that show how im doing it.



m_FBO.Bind();
m_FBO.DrawBuffer(GL_COLOR_ATTACHMENT1);
m_FBO.Clear(0.7f, 0.7f, 1.0f, 1.0f,GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
DrawBackface();
m_FBO.Unbind();

m_FBO.Bind();
m_FBO.DrawBuffer(GL_COLOR_ATTACHMENT0);
m_FBO.Clear(0.7f, 0.7f, 1.0f, 1.0f,GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_RayCast.CgFxSetupSampler("backface",bf);
m_RayCast.CgFxSetupSampler("volume",vl);
m_RayCast.CgFxSetParameterFloat1("stepsize",0.004f);
m_RayCast.CgFxBegin("pass0");
DrawFrontface();
m_RayCast.CgFxEnd();
m_FBO.Unbind();

m_RayCast.CgFxSetupSampler("final",fin);
m_RayCast.CgFxBegin("pass1");
m_FBO.DrawFullscreenQuad();
m_RayCast.CgFxEnd();
m_FBO.Unbind();


It is..
1. create front back face texture
2. update shader with these textures
3. raycast the volume
4. draw fullscreenquad and texture it with the raycast result




You need to add the contribution of the background color at the end of the ray you cast minus all attenuation along the ray segment in the volume.
To you can render to a texture the background first then fetch the texture in the raycasting shader.

What do you exactly mean by writing

"You need to add the contribution of the background color at the end of the ray you cast minus all attenuation along the ray segment in the volume."

?

I also thought about to render the background to texture and bind it to the sahder. But what to do then ? I tried Alphablending but that gives very bad results.



float4 opaque = tex2D(background, float2(0.5,0.5));
float4 blend = (1.0 - col_acc.a) * opaque + col_acc.a * col_acc.a;
return col_acc;



regards,
lobbel