• Create Account

# Normal oriented elliptical shapes (surfels) using point sprites.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

No replies to this topic

### #1Ender1618  Members   -  Reputation: 242

Like
0Likes
Like

Posted 10 December 2013 - 02:45 PM

I am trying to reproduce this effect with point sprites (given vertices with a position and normal).

http://imageshack.com/a/img36/7057/5t7b.jpg

Essentially discarding fragments of a point sprite, dependent on the normal of that point, to produce an an elliptical shape tangent to the point normal (essentially approximated ortho projection of a 3D circle to a 2D ellipse).

From the equation I found d = -(n.x/n.z)*x-(n.y/n.z)*y, where a fragment is discarded if the world space distance from the point center to a point (x,y,d) is greater that the disk radius (as indicated by the text above the image).

I am trying to figure the right way of doing this in my GLSL vertex and fragment shaders, using point sprites.

in my  shaders I am doing something like this, which isn't working:

//vertex shader
#version 400

layout (location = 0) in vec3 VertexPosition;
layout (location = 1) in vec3 VertexNormal;

out vec3 Color;
flat out vec3 PtPosition;
flat out vec3 PtNormal;
out vec3 FragPosition;

uniform mat4 MVP;
uniform float heightMin;
uniform float heightMax;

uniform mat4 MV;
uniform float pointSize;
uniform float viewportDim;

float perspPtSize(vec3 ptPos, mat4 mv, float ptWorldSize, float viewportDim)
{
vec3 posEye = vec3(mv * vec4(ptPos, 1.0));
return ptWorldSize * (viewportDim / length(posEye));
}

void main()
{
Color = vec3(1.0,1.0,1.0);
PtPosition = vec3(MV * vec4(VertexPosition,1.0));
FragPosition = PtPosition;
PtNormal = vec3(MV * vec4(VertexNormal,1.0));
gl_Position = MVP * vec4(VertexPosition,1.0);

gl_PointSize = perspPtSize(VertexPosition.xyz,MV,pointSize,viewportDim);
}

#version 400

layout( location = 0 ) out vec4 FragColor;

in vec3 Color;
flat in vec3 PtPosition;
flat in vec3 PtNormal;

void main()
{
vec2 ptC = gl_PointCoord- vec2(0.5);
float depth = -PtNormal.x/PtNormal.z*ptC.x -
PtNormal.y/PtNormal.z*ptC.y;
float sqrMag = ptC.x*ptC.x + ptC.y*ptC.y + depth*depth;

if(sqrMag > 0.25)
else
{ fragColor = vec4(color, 1.0); }
}

Has anyone successfully implemented an effect like this? I tried doing this in world space as well but ended up getting incorrect results, I figured if i left it all in point sprite expressed space it might be easier.

I think I am missing some basic concept for doing this, any suggestions?

Edited by Ender1618, 10 December 2013 - 02:50 PM.