cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

n0thing
Journeyman III

Using GL_POINT_SPRITE results in blank screen

void ParticleRenderer::Display(DisplayMode mode /* = PARTICLE_POINTS */)
{
switch (mode)
{
case PARTICLE_POINTS:
glColor3f(1, 1, 1);
glPointSize(m_pointSize);

_drawPoints();
break;
case PARTICLE_SPRITES:
default:
{
// setup point sprites
glEnable(GL_POINT_SPRITE_ARB);
glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
glPointSize(m_spriteSize);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);

glUseProgram(m_program);
GLuint texLoc = glGetUniformLocation(m_program, "splatTexture");
glUniform1i(texLoc, 0);

glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, m_texture);

glutReportErrors();

glColor3f(1, 1, 1);

_drawPoints();

glUseProgram(0);

glutReportErrors();

glDisable(GL_POINT_SPRITE_ARB);
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
}
break;
case PARTICLE_SPRITES_COLOR:
{
// setup point sprites
glEnable(GL_POINT_SPRITE_ARB);
glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
glPointSize(m_spriteSize);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);

glUseProgram(m_program);
GLuint texLoc = glGetUniformLocation(m_program, "splatTexture");
glUniform1i(texLoc, 0);

glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, m_texture);

glutReportErrors();

glColor3f(1, 1, 1);

_drawPoints(true);

glUseProgram(0);

glutReportErrors();

glDisable(GL_POINT_SPRITE_ARB);
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
}
break;
}
}

const char vertexShader[] =
{
"void main() \n"
"{ \n"
" float pointSize = 500.0 * gl_Point.size; \n"
" vec4 vert = gl_Vertex; \n"
" vert.w = 1.0; \n"
" vec3 pos_eye = vec3 (gl_ModelViewMatrix * vert); \n"
" gl_PointSize = max(1.0, pointSize / (1.0 - pos_eye.z)); \n"
" gl_TexCoord[0] = gl_MultiTexCoord0; \n"
//" gl_TexCoord[1] = gl_MultiTexCoord1; \n"
" gl_Position = ftransform(); \n"
" gl_FrontColor = gl_Color; \n"
"} \n"
};

const char pixelShader[] =
{
"uniform sampler2D splatTexture; \n"

"void main() \n"
"{ \n"
" vec4 color = (0.6 + 0.4 * gl_Color) * texture2D(splatTexture, gl_TexCoord[0].st); \n"
" gl_FragColor = \n"
" color * mix(vec4(0.0, 0.2, 0.2, color.w), vec4(0.2, 0.7, 0.7, color.w), color.w);\n"
"} \n"
};

Attached code is from Nvidia's oclNBody sample. It only works with GL_POINTS else results in a blank-screen. Tested on radeon 5770 with catalyst 10.2

 

0 Likes
9 Replies
samtha
Journeyman III

Thanks for posting about this, I would love to read more about this topic...........

Cheap Checks
0 Likes

I am not sure what is the right behavior here:

- you do enable point sprite

- you use the right texgen

- however, since you use a GLSL shader, and you have a vertex shader which does write a constant value into gl_TexCoord[0], then we are honoring the vertex shader, and you get a constant value

- if you want to have portable code, then I would suggest to replace gl_TexCoord[0].st with gl_PointCoord.st in your pixel shader

 

regards,

Pierre Boudier

PS: I could not find a place in the spec that defines the interaction with the vertex shader here. clearly, nvidia/amd implementation chose a different interpretation

0 Likes

Thanks! It works now.

0 Likes

 

I'm trying to the NVidia OpenCL particle demo to look decent on AMD, but cannot get the point sprites to look nice. It might be partly because of a NVidia specific extension (GL_VERTEX_PROGRAM_POINT_SIZE_NV)

The shader seems to have no impact on the point size and no texture is used.

 

// vertex shader

const char *vertexShader = STRINGIFY(

uniform float pointRadius;  // point size in world space

uniform float pointScale;   // scale to calculate size in pixels

uniform float densityScale;

uniform float densityOffset;

varying vec3 posEye;

void main()

{

    // calculate window-space point size

    posEye = vec3(gl_ModelViewMatrix * vec4(gl_Vertex.xyz, 1.0));

    float dist = length(posEye);

//    gl_PointSize = pointRadius * (pointScale / dist);

    gl_PointSize = 40.0f;

 

    //gl_TexCoord[0] = gl_MultiTexCoord0;

gl_TexCoord.st = gl_MultiTexCoord0;

    gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_Vertex.xyz, 1.0);

 

    gl_FrontColor = gl_Color;

}

);

 

  gl_PointSize = 40.0f; seems to have no effect.

 

Did you manage to set the point size from a shader, and make them look nice? If so, can you share some small example code?

Thanks,

Erwin

 

0 Likes

I am writing a particle engine using point sprites, and i want to change the size of the points in relation to how far they are from the camera (you know, like in the real world). I've borrowed code from places and it uses glext to get the right functions.

so my questions are:

* How can i change the point size based on how far they are from the camera

* Do i used glext for linux (if it exists) or is there an alternative?

Thanks

candy bars

 

 

0 Likes

Originally posted by: lumb * How can i change the point size based on how far they are from the camera



once you have transformed your point with your mvp in your shader, the distance is the length of the vector (gl_Position - origin). you can have a faster version by just looking at the z value, which is an approximation of the radial distance to the origin with a distance from the near plane.

then you can use something like:

gl_PointSize = minValue + distance * (maxValue - minValue);

Pierre B.

 



 

0 Likes

 

If anyone gets those point sprites to work with ATI Radeon (including size based on distance and nice smooth shading), can you please share the source code of a small project?

 

Thanks a lot,

Erwin

 

0 Likes

OpenGL (Open Graphics Library) is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL was developed by Silicon Graphics Inc. (SGI) in 1992[2] and is widely used in CAD, virtual reality, scientific visualization, information visualization, and flight simulation. It is also used in video games, where it competes with Direct3D on Microsoft Windows platforms (see OpenGL vs. Direct3D). OpenGL is managed by a non-profit technology consortium, the Khronos Group.

Postcard Printing

0 Likes

Originally posted by: erwincoumans  

I'm trying to the NVidia OpenCL particle demo to look decent on AMD, but cannot get the point sprites to look nice. It might be partly because of a NVidia specific extension (GL_VERTEX_PROGRAM_POINT_SIZE_NV)

The shader seems to have no impact on the point size and no texture is used.

 

do you have the following line ?

glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);



Pierre B.

0 Likes