简体   繁体   中英

OpenGL Per Pixel Coloring with GLSL Shaders

Is it possible using a GLSL shader to calculate the color of vertices per pixel instead of per vertex? Because it looks a bit like per vertex lighting(kinda ugly).

For example

What I have: 在此处输入图片说明

What it should look like: 在此处输入图片说明

Is it possible using a GLSL shader to calculate the color of vertices per pixel [...]

"Color of vertices per pixel" does not really make sense. What one does calculate is the color of fragments (which are the results of the rasterisation for the pixel raster, but did not yet affect the framebuffer pixels). And that color is always calculated per fragment - in a "per-vertex lighting" setup, that color is just calculated by interpolating the colors from the lighting at each vertex of the primitive (aka. Gouraud Shading), possibly further manipulating it (eg by texture mapping).

What you probably mean here is "Is it possible using a GLSL shader to calculate the lighting euqation per fragment (Phong Shading, per-pixel lighting)?" And the answer to that is: yes. That can be done in the fragment shader.

Because it looks a bit like per vertex lighting(kinda ugly).

What looks that way? Fixed-function GL? Yes, it is specified that way. The old fixed-function lighting is done per vertex, and only flat and Gouraud shading were supported back then. Shaders did change that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM