How to draw a Point Primitive with a world space width?

蓝咒 提交于 2019-12-11 18:21:36

问题


I want to draw a point, to simulate the position of which the light originates, however the issue I am facing now is that it is always the same size, regardless of the distance:

I push literally one vertex to the GPU, my code:

point.vs.glsl

#version 440 core

layout(location = 0) in vec4 position;

layout(location = 0) uniform mat4 model_matrix;
layout(location = 1) uniform mat4 view_matrix;
layout(location = 2) uniform mat4 proj_matrix;

void main(void) {
    gl_PointSize = 100.0;
    gl_Position = proj_matrix * view_matrix * model_matrix * position;
}

point.fs.glsl

#version 440 core

out vec4 color;

void main(void) {
    //create round point
    vec2 p = gl_PointCoord * 2.0 - vec2(1.0);
    if (dot(p, p) > 1.0) {
        discard;
    }

    color = vec4(0.5, 0.0, 0.0, 1.0);
}

Also does the code for creating a round point actually work in 3D? I believe it came from a 2D tutorial if I'm not mistaken.

About the point size again, I know what I am doing wrong, however how would I correctly calcualte the size? I have the information available I think, with view_matrix and somehow I need to get the distance to the point, and scale depending on that.

来源:https://stackoverflow.com/questions/21502130/how-to-draw-a-point-primitive-with-a-world-space-width

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!