点精灵 Alpha 混合问题

Point Sprite Alpha Blending Issue

我正在尝试使用点精灵在 3D space 中渲染大量星星。就 alpha 通道而言,我的纹理图像绝对是 'good'。它作为四边形渲染得非常好,但是当我渲染很多点精灵时,我可以看到图像的方形边框覆盖了一些图像。

上图显示了在我的立方体顶部很好地渲染的星星。在右下角,我希望在绘制的 'flower' 图案中看到连续的星星图像轨迹。

我做错了什么?

片段着色器:

#version 140

#extension GL_ARB_explicit_attrib_location : enable

precision mediump float;

uniform sampler2D uTexture;

void main( void )
{    
  gl_FragColor = texture2D( uTexture, gl_PointCoord );
}

顶点着色器:

#version 140

#extension GL_ARB_explicit_attrib_location : enable

precision mediump float;

layout (location = 0) in float aTheta; 

uniform float uK;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main( void )
{
  float x = cos( uK * aTheta ) * sin( aTheta );
  float y = cos( uK * aTheta ) * cos( aTheta );

  gl_Position  = projection * view * model * vec4( x, y, 0.0, 1.0 );
  gl_PointSize = 64.0;
}

代码:

void CPoint::Render( void )
{
  g_PointProgram.UseProgram();

  glEnable( GL_PROGRAM_POINT_SIZE );
  glEnable( GL_POINT_SPRITE );

  // Set the alpha blending function
  glEnable( GL_BLEND );
  glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
  glBlendEquation( GL_FUNC_ADD );

  glBindBuffer( GL_ARRAY_BUFFER, m_VBO );

  glm::mat4 Model = glm::mat4( 1.0 );

  Model = glm::translate( Model, glm::vec3( 2.0f, 0.0f, 4.0f ) );

  glm::mat4 Projection = g_Camera.GetProjection();
  glm::mat4 View       = g_Camera.GetView();

  g_PointProgram.SetUint( "uTexture", g_ImgStar.m_Texture );

  g_PointProgram.SetMatrix4fv( "model", Model );
  g_PointProgram.SetMatrix4fv( "view", View );
  g_PointProgram.SetMatrix4fv( "projection", Projection );

  g_PointProgram.SetFloat( "uK", m_Emitter.k );

  glActiveTexture( GL_TEXTURE0 );
  glBindTexture( GL_TEXTURE_2D, g_ImgStar.m_Texture );
  glEnable( GL_TEXTURE_2D );

  // Attributes
  glVertexAttribPointer( 0,                // 1st attribute array (only have 1)
                         1,                                        // One theta angle per particle
                         GL_FLOAT,                                 // Data is floating point type
                         GL_FALSE,                                 // No fixed point scaling
                         sizeof( Particle ),                       // No gaps in data
                         (void*) 0 );      // Start from "theta" offset within bound buffer


  glEnableVertexAttribArray( 0 );

  glDrawArrays( GL_POINTS, 0, NUM_PARTICLES );

  glDisableVertexAttribArray( 0 );
  glBindBuffer( GL_ARRAY_BUFFER, 0 );

  glDisable( GL_TEXTURE_2D );
}

也许深度剔除在耍你?在渲染精灵时尝试 glDepthMask(false)