[Solved] Fluid Renderable Position help

Topper

15-02-2011 16:37:20

Hi,

i want to use the fluid position renderable from critter. but i don't understand how to use it.

i know it holds the hadware vertex buffer with all positions but i don't know how to get or use it. i tried a material with geometry shader but it doesn't work. i am not very familiar with geometry shader.

Maybe someone can help to make quads out of these points.

GEOMETRY SHADER:

#extension GL_EXT_geometry_shader4 : enable

uniform float sphere_radius;

varying out vec3 vertex_light_position;
varying out vec4 eye_position;
void main()
{
float halfsize = 0.5;//sphere_radius * 0.5;

gl_TexCoord[0] = gl_TexCoordIn[0][0];
gl_FrontColor = gl_FrontColorIn[0];

vertex_light_position = normalize(gl_LightSource[0].position.xyz);
eye_position = gl_PositionIn[0];

// Vertex 1
gl_TexCoord[0].st = vec2(-1.0,-1.0);
gl_Position = gl_PositionIn[0];
gl_Position.xy += vec2(-halfsize, -halfsize);
gl_Position = gl_ProjectionMatrix * gl_Position;
EmitVertex();

// Vertex 2
gl_TexCoord[0].st = vec2(-1.0,1.0);
gl_Position = gl_PositionIn[0];
gl_Position.xy += vec2(-halfsize, halfsize);
gl_Position = gl_ProjectionMatrix * gl_Position;
EmitVertex();

// Vertex 3
gl_TexCoord[0].st = vec2(1.0,-1.0);
gl_Position = gl_PositionIn[0];
gl_Position.xy += vec2(halfsize, -halfsize);
gl_Position = gl_ProjectionMatrix * gl_Position;
EmitVertex();

// Vertex 4
gl_TexCoord[0].st = vec2(1.0,1.0);
gl_Position = gl_PositionIn[0];
gl_Position.xy += vec2(halfsize, halfsize);
gl_Position = gl_ProjectionMatrix * gl_Position;
EmitVertex();

EndPrimitive();
}


Material:

geometry_program ParticleGS glsl
{
source ParticleGS.glsl
input_operation_type point_list
output_operation_type triangle_strip
max_output_vertices 4

default_params
{
param_named sphere_radius float 0.5
}
}

Topper

16-02-2011 11:04:24

Hi,

i managed to correct my geometry shader and now it works fine. here are the material and the shader's.

Material

vertex_program ParticleVS glsl
{
source ParticleVS.glsl

}

geometry_program ParticleGS glsl
{
source ParticleGS.glsl
input_operation_type point_list
output_operation_type triangle_strip
max_output_vertices 5

default_params
{
param_named width float 1.0
param_named height float 1.0
}
}


fragment_program ParticleFS glsl
{
source ParticleFS.glsl
}
material GeometryShader
{
technique
{
pass
{
vertex_program_ref ParticleVS
{
}

geometry_program_ref ParticleGS
{
}

fragment_program_ref ParticleFS
{
}

}

}
}


ParticleVS( Vertex Shader)

void main(void)
{
gl_Position = gl_ModelViewMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
}


ParticleGS (Geoemtry Shader)

#version 120
#extension GL_EXT_geometry_shader4 : enable

uniform float width;
uniform float height;

void main()
{
vec2 halfsize = vec2(width,height) * 0.5;


vec2 pos[4];
pos[0] = vec2(-1.0,+1.0);
pos[1] = vec2(-1.0,-1.0);
pos[2] = vec2(+1.0,+1.0);
pos[3] = vec2(+1.0,-1.0);

for (int i = 0; i < 4; ++i)
{
gl_TexCoord[0].st = pos;
gl_FrontColor = gl_FrontColorIn[0];
gl_Position = gl_PositionIn[0];
gl_Position.xy += pos * halfsize;
gl_Position = gl_ProjectionMatrix * gl_Position;
EmitVertex();
}

}


ParticleFS (Fragment Shader)

void main(void)
{
gl_FragColor = vec4(1.0);
}


have fun :)

nathaliamn

18-05-2011 21:36:14

Hi,

I try to use these shaders, but the particles are all white.

I dont know if im doing right, look

NxOgre::Fluid* mFluid = mRenderSystem->createFluid(desc,"GeometryShader", Critter::Enums::FluidType_OgreParticle);
Critter::ParticleRenderable* pr = (Critter::ParticleRenderable*)mFluid->getRenderable();
pr->getParticleSystem()->setDefaultDimensions(radius*6,radius*6);

Anyone use these shaders?

nathaliamn

18-05-2011 23:21:09

i just realized i was using direct3d, so i changed to openGl.
Then i ran, and the particles didn't appeared.

so im lost again.