Point sprites with sphere shader

I was able to apply a 2D texture on point sprites, but it didnt really make it look like a 3D sphere. I’ve looked over alot of google pages and i didnt find anything about using glsl for making a point sprite appear like a sphere. Anyone know where i could find some infos on how to do this using a .vert and .frag program? Here the code where i’m drawing the point sprites :


void InitPointSprites()
{
	setShaders();
	g_floorLightMapTexture = LoadTexture("Content/Textures/floor_light_map.tga");
    // clear buffer
    // save the initial ModelView matrix before modifying ModelView matrix
    // tramsform camera
    if(vboUsed) // draw cube using VBO
    {
		glEnable( GL_DEPTH_TEST );
		glDepthMask( GL_FALSE );

		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_COLOR, GL_ONE);
		glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboId);

		// enable vertex arrays
		glEnableClientState(GL_NORMAL_ARRAY);
		glEnableClientState(GL_COLOR_ARRAY);
		glEnableClientState(GL_VERTEX_ARRAY);

		// before draw, specify vertex and index arrays with their offsets
		glNormalPointer(GL_FLOAT, 0, (void*)sizeof(vertices));
		glColorPointer(3, GL_FLOAT, 0, (void*)(sizeof(vertices)+sizeof(normals)));
		glVertexPointer(3, GL_FLOAT, 0, 0);
		float quadratic[] =  {1.0f, 0.0f, 0.01f};
		glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, quadratic );
		// Query for the max point size supported by the hardware
		float maxSize = 0.0f;
		glGetFloatv(GL_POINT_SIZE_MAX_ARB, &maxSize );
		if(maxSize > 100.0f)
			maxSize = 100.0f;
		glPointSize(maxSize);
		// The alpha of a point is calculated to allow the fading of points 
		// instead of shrinking them past a defined threshold size. The threshold 
		// is defined by GL_POINT_FADE_THRESHOLD_SIZE_ARB and is not clamped to 
		// the minimum and maximum point sizes.
		glPointParameterfARB(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 60.0f);
		glPointParameterfARB(GL_POINT_SIZE_MIN_ARB, 1.0f);
		glPointParameterfARB(GL_POINT_SIZE_MAX_ARB, maxSize);

		//glEnable(GL_TEXTURE_2D);
		//glBindTexture(GL_TEXTURE_2D, g_floorLightMapTexture);
		glEnable(GL_POINT_SPRITE_ARB);
		glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
			glDrawArrays(GL_POINTS, 0, numPoints);
		glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_FALSE); 
		glDisable(GL_POINT_SPRITE_ARB);
		//glBindTexture(GL_TEXTURE_2D, 0);
		//glDisable(GL_TEXTURE_2D);

		glDisableClientState(GL_VERTEX_ARRAY);  // disable vertex arrays
		glDisableClientState(GL_COLOR_ARRAY);
		glDisableClientState(GL_NORMAL_ARRAY);
		glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
		glDisable(GL_BLEND);
		glDisable( GL_DEPTH_TEST );
		glDepthMask( GL_TRUE );
	}
	ShadersOff();
}

The easiest thing you can make is simply applying a texture which contains the picture of an illuminated sphere.

If you need some more dynamic way then… it is a bit longer story…

Well i’m moving in a 3D space, so i need the texture to be in relation with the position of the light, which is fixed. I don’t want the texture to always face where the user is looking, like point sprites do.

Search for normal mapping and per pixel lighting in glsl.

I’m getting some weird things when using this vert and frag program :


//frag
varying vec3 L;
varying vec3 V;
uniform sampler2D texMap;
void main()
{
	// Simple example, only for diffuse
	vec4 N = texture2D(texMap, gl_TexCoord[0].st);
	vec3 NN = normalize(2.0*N.xyz-1.0);
	vec3 LL = normalize(L);
	float Kd= max(dot(NN, LL), 0.0);
	gl_FragColor=
	Kd*gl_FrontLightProduct[0].diffuse;
}


/* normal map vertex shader */
varying vec3 L; /* light vector in tangent-space coordinates */
varying vec3 V; /* view vector in tangent-space coordinates */
attribute vec3 objTangent; /* tangent vector in object coordinates */
void main()
{
	gl_Position= gl_ModelViewProjectionMatrix*gl_Vertex;
	gl_TexCoord[0] = gl_MultiTexCoord0;
	vec3 eyePosition= vec3(gl_ModelViewMatrix*gl_Vertex);
	vec3 eyeLightPos= vec3(gl_LightSource[0].position);
	/* normal, tangent and binormalin eye coordinates */
	vec3 N = normalize(gl_NormalMatrix*gl_Normal);
	vec3 T = normalize(gl_NormalMatrix*objTangent);
	vec3 B = cross(N, T);
	/* light vector in tangent space */
	L.x= dot(T, eyeLightPos-eyePosition);
	L.y= dot(B, eyeLightPos-eyePosition);
	L.z= dot(N, eyeLightPos-eyePosition);
	L = normalize(L);
	/* view vector in tangent space */
	V.x= dot(T, -eyePosition.xyz);
	V.y= dot(B, -eyePosition.xyz);
	V.z= dot(N, -eyePosition.xyz);
	V = normalize(V);
}

When on the x axis, point sprites on the left are square with an alpha circle in the middle. On the right, they are normal circles. What did i do wrong?

An NVidia CUDA/OpenCL demo called “particles” does this and uses point sprites IIRC:

http://developer.download.nvidia.com/com…Simulation.html

Search down for “particles”. PDF has a pic. You can download the full source with their CUDA or OpenCL distributions. IIRC, seems like the demo source is in their “GPU Computing SDK” package:

http://developer.nvidia.com/object/cuda_3_2_downloads.html

An NVidia CUDA/OpenCL demo called “particles” does this and uses point sprites IIRC:

http://developer.download.nvidia.com/com…Simulation.html

Search down for “particles”. PDF has a pic. You can download the full source with their CUDA or OpenCL distributions. IIRC, seems like the demo source is in their “GPU Computing SDK” package:

http://developer.nvidia.com/object/cuda_3_2_downloads.html
[/QUOTE]
awesome, the shaders from this example are working perfectly in my program.

Well, now i have another problem, the texture of the sphere are showing correctly, but they are rotating with the user. I want to be able to move around the sphere, to see it change color and shadow.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.