sienaiwun

01-19-2016, 07:32 AM

Dear all:

I want to drew a screen image mesh (by subdividing a screen quad into a mesh with resolution w*h). When I draw a tiny small triangle (for example, at one corner of the screen), I expect three pixels would appear, but only one pixel would be rasterized. I would like to know the reason.(depth culling and back face culling are turned off).

In other words, I generate a triangle, whose vertexes are exactly located at the center points of a pixel, another pixel on the right, and another pixel on the top in image space. I would expect three pixels would appear, but instead only one appears. I would like to know the theory of how a triangle with vertexes exactly on the sample point is rasterized.

VBO generate code:

for(int x = 0;x<rasterWidth;x++)

for(int y = 0;y<rasterHeight;y++)

{

if(x==0&&y==0)

;

else

continue; // hear we only draw one triangle， others are invalid

Vertices[PointId++] = make_float2((float)(x+0.5)/rasterWidth,(float)(y+0.5)/rasterHeight);

Vertices[PointId++] = make_float2((float)(x+1.5)/rasterWidth,(float)(y+0.5)/rasterHeight);

Vertices[PointId++] = make_float2((float)(x+1.5)/rasterWidth,(float)(y+1.5)/rasterHeight);

Vertices[PointId++] = make_float2((float)(x+0.5)/rasterWidth,(float)(y+0.5)/rasterHeight);

Vertices[PointId++] = make_float2((float)(x+1.5)/rasterWidth,(float)(y+1.5)/rasterHeight);

Vertices[PointId++] = make_float2((float)(x+0.5)/rasterWidth,(float)(y+1.5)/rasterHeight);

}

glGenBuffers(1,&VBO);

glBindBuffer(GL_ARRAY_BUFFER,VBO);

glBufferData(GL_ARRAY_BUFFER,sizeof(float2)* rasterWidth *rasterHeight * 6,(GLvoid*)Vertices,GL_STATIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER,0);

vertex shader:

#version 430

layout (location = 0) in vec2 position;

void main(){

gl_Position.xy = (position.xy- 0.5) * 2.0;

gl_Position.z = -0.1; //just not clip the vertex

gl_Position.w = 1;

}

pixel shader:

#version 430

layout (location = 0) out vec4 color0;

void main()

{

color0 = vec4(1,0,0,1); //only the pixel at the left bottom is ra

}

result:only the pixel at the left bottom is rasterized red.

I want to drew a screen image mesh (by subdividing a screen quad into a mesh with resolution w*h). When I draw a tiny small triangle (for example, at one corner of the screen), I expect three pixels would appear, but only one pixel would be rasterized. I would like to know the reason.(depth culling and back face culling are turned off).

In other words, I generate a triangle, whose vertexes are exactly located at the center points of a pixel, another pixel on the right, and another pixel on the top in image space. I would expect three pixels would appear, but instead only one appears. I would like to know the theory of how a triangle with vertexes exactly on the sample point is rasterized.

VBO generate code:

for(int x = 0;x<rasterWidth;x++)

for(int y = 0;y<rasterHeight;y++)

{

if(x==0&&y==0)

;

else

continue; // hear we only draw one triangle， others are invalid

Vertices[PointId++] = make_float2((float)(x+0.5)/rasterWidth,(float)(y+0.5)/rasterHeight);

Vertices[PointId++] = make_float2((float)(x+1.5)/rasterWidth,(float)(y+0.5)/rasterHeight);

Vertices[PointId++] = make_float2((float)(x+1.5)/rasterWidth,(float)(y+1.5)/rasterHeight);

Vertices[PointId++] = make_float2((float)(x+0.5)/rasterWidth,(float)(y+0.5)/rasterHeight);

Vertices[PointId++] = make_float2((float)(x+1.5)/rasterWidth,(float)(y+1.5)/rasterHeight);

Vertices[PointId++] = make_float2((float)(x+0.5)/rasterWidth,(float)(y+1.5)/rasterHeight);

}

glGenBuffers(1,&VBO);

glBindBuffer(GL_ARRAY_BUFFER,VBO);

glBufferData(GL_ARRAY_BUFFER,sizeof(float2)* rasterWidth *rasterHeight * 6,(GLvoid*)Vertices,GL_STATIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER,0);

vertex shader:

#version 430

layout (location = 0) in vec2 position;

void main(){

gl_Position.xy = (position.xy- 0.5) * 2.0;

gl_Position.z = -0.1; //just not clip the vertex

gl_Position.w = 1;

}

pixel shader:

#version 430

layout (location = 0) out vec4 color0;

void main()

{

color0 = vec4(1,0,0,1); //only the pixel at the left bottom is ra

}

result:only the pixel at the left bottom is rasterized red.