> Ah, great! Good luck with your presentation! What was it about?
Someone asked me if we could visualize volume data, neutron flux in a
reactor chamber (scalar field)
..so I took the opportunity to play around with GLSL shader, especially
geometry shader ^_^
I replaced every point in my discrete space inside the chamber by a small
corner, this results in dividing the space in boxes..
This is surely not the most intelligent thing one can do, but it looks nice
(and still real time, yay!) and was a fun exercice :)
What I needed to update was the clipping plane variable in the shader.
First I tried to use the OpenSG cliping plane chunk, but it does not work
with my custom shader, I will investigate it later if I have time, I
suspect it might relate to my vertex program:
// vertex shader program
varying out mat4 model;
varying out vec2 tc;
void main( void ) {
tc = gl_MultiTexCoord0.xy;
model = gl_ModelViewProjectionMatrix;
gl_Position = gl_Vertex;
}
Here the rest if someone is interested: (one should replace
the getDataFromMap function, mine works, but is not very good)
//fragment prog
void main( void )
{
if(gl_Color.w < 1e-6) discard;
gl_FragColor = gl_Color;
}
//geometry prog
#version 150
#extension GL_EXT_geometry_shader4 : enable
layout (points) in;
layout (triangle_strip, max_vertices = 36) out;
uniform float s0;//voxel number
uniform float s1;//voxel number
uniform float s2;//voxel number
uniform float voxel;
uniform float scale;//texture size
uniform sampler2D displacementMap;
in mat4 model[];
in vec2 tc[];
ivec2 tco[7];
vec4 co[7];
vec4 po[7];
vec4 Vox[3];
int i;
//clipping plane ax + by + cz + d
uniform vec4 cpeq;//clipping plane
// Compute the distance between the vertex and the clip plane
float getCPDist(vec4 pos) {
float df;
df = dot(cpeq.xyz, pos.xyz) + cpeq.w;
return df;
}
//---------------------------------------------------------------------------------GET
DATA FROM TEXTURE
float getDataFromMap( ivec2 tc ) {
vec4 c;
float df;//float
c = texelFetch(displacementMap, tc, 0);
df = c.x + c.y*0.00392156862745 + c.z*1.53787004998e-05;
return df;
}
void main() {
vec2 ftc = tc[0];
ivec2 itc;
itc.x = int(ftc.x);
itc.y = int(ftc.y);
//Prepare texture coords from the cube
for (i=0;i<4;i++) {
tco[i] = itc;
}
if (tco[0].x < (s0-1.0)*s1) {
tco[1] += ivec2(1.0, 0.0);
tco[2] += ivec2(s0 + 1.0, 0.0);
tco[3] += ivec2(s0, 0.0);
}
tco[4] = tco[0];
tco[5] = tco[1];
tco[6] = tco[3];
if (tco[0].y < s2) {
for (i=4;i<7;i++) {
tco[i] += ivec2(0.0, 1.0);
}
}
//get the colors from the map
for (i=0;i<7;i++) {
float val = getDataFromMap(tco[i]);
co[i] = vec4(1.0, 0.0, 0.0, val*scale);
}
//Positions, points, primitives
for (i=0;i<3;i++) {
Vox[i] = vec4(0.0, 0.0, 0.0, 0.0);
}
Vox[0][0] = voxel;
Vox[1][2] = voxel;
Vox[2][1] = voxel;
po[0] = gl_PositionIn[0];
po[1] = po[0] + Vox[0];
po[2] = po[1] + Vox[2];
po[3] = po[0] + Vox[2];
po[4] = po[0] + Vox[1];
po[5] = po[4] + Vox[0];
po[6] = po[4] + Vox[2];
//clipping plane
for (i=0;i<7;i++) {
float dist = getCPDist(po[i]);
if (dist < 0.0) co[i] = vec4(1.0, 0.0, 0.0, 0.0);
}
for (i=0;i<7;i++) {
po[i] = model[0]*po[i];
}
gl_Position = po[0];
gl_FrontColor = co[0];
EmitVertex();
gl_Position = po[1];
gl_FrontColor = co[1];
EmitVertex();
gl_Position = po[3];
gl_FrontColor = co[3];
EmitVertex();
EndPrimitive();
EmitVertex();
gl_Position = po[2];
gl_FrontColor = co[2];
EmitVertex();
gl_Position = po[1];
gl_FrontColor = co[1];
EmitVertex();
EndPrimitive();
EmitVertex();
gl_Position = po[5];
gl_FrontColor = co[5];
EmitVertex();
gl_Position = po[4];
gl_FrontColor = co[4];
EmitVertex();
EndPrimitive();
EmitVertex();
gl_Position = po[6];
gl_FrontColor = co[6];
EmitVertex();
gl_Position = po[3];
gl_FrontColor = co[3];
EmitVertex();
EndPrimitive();
EmitVertex();
gl_Position = po[4];
gl_FrontColor = co[4];
EmitVertex();
gl_Position = po[0];
gl_FrontColor = co[0];
EmitVertex();
EndPrimitive();
EmitVertex();
gl_Position = po[1];
gl_FrontColor = co[1];
EmitVertex();
gl_Position = po[4];
gl_FrontColor = co[4];
EmitVertex();
EndPrimitive();
}
Yours,
Victor
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users