Hi there,
I`m completely new in OpenGl and I need to implement a kind of fluideffect like in Portal 2 for my study.
The task is to:
-first: implement a particlesystem (I did that)
-second: implement a geometryshader to do the billboarding stuff (I did that either)
-third: implement a raycasting in the fragmentshader from camera to every fragment (every fragment on billboards passed from geometryshader) to find out if the ray is within an isosurface.
with that it should look like a kind of metaballeffect.
my fragmentshader looks like this:
vec4 color;
vec4 ndcPos;
ndcPos.xy = ((2.0 * gl_FragCoord.xy) - (2.0 * viewport.xy)) / (viewport.zw) - 1;
ndcPos.z = (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far) /
(gl_DepthRange.far - gl_DepthRange.near);
ndcPos.w = 1.0;
vec4 clipPos = ndcPos / gl_FragCoord.w;
vec4 eyePos = invPersMatrix * clipPos;
vec3 ray_origin = vec3(0,0,0);
vec3 ray_direction = normalize(eyePos).xyz;
vec3 ray_pos = ray_origin;
for(int i = 1; i <= 100; i++)
{
float stepDistance = 0.4f;
ray_pos += ray_direction * stepDistance;
if(isInScalarField(ray_pos))
{
color = vec4(ray_pos, 1.0f);
break;
}
else
{
color = vec4(ray_pos, 0.0f);
}
}
outputColor = color;
the isInScalarField() function tests if the ray intersects with the implicitsurface (i don`t know if that is the right vocabulary for that in english )
it looks like this:
bool isInScalarField(vec3 x)
{
float isoWert = 0.5f;
float k = 7;
float s = 0.0f;
for(int j = 0; j < 8; j++)
{
float distance = length(x - neighbours[j]);
s += exp( -k * distance);
}
if(s > isoWert)
{
return true;
}
return false;
}
neighbours are the neighbourparticles for each particle which has been passed to vertexshader. I pass them to fragmentshader as a uniform array.
My problem ist, that it doesnt look like it should. With this code the billboards, which are quads created by geometryshader, are weird cutted. I think that my vectors are messed up or the neighbours are wrong. I googled hours and hours and tried everything to get this working, but I failed ;( and now I need some help to get this working.
I made a quick video to show my problem:
thank you in advance