OpenGL glsl 实现hdr效果,写出顶点着色器和片元着色器,分别说明着色器中参数的取值范围
时间: 2023-01-11 12:55:36 浏览: 797
OPenGL着色器语言(GLSL)
5星 · 资源好评率100%
顶点着色器:
```
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTexCoords;
out vec2 TexCoords;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
gl_Position = projection * view * model * vec4(aPos, 1.0);
TexCoords = aTexCoords;
}
```
片元着色器:
```
#version 330 core
out vec4 FragColor;
in vec2 TexCoords;
uniform sampler2D hdrBuffer;
uniform float exposure;
void main()
{
vec3 hdrColor = texture(hdrBuffer, TexCoords).rgb;
vec3 hdrColorAdapted = vec3(1.0) - exp(-hdrColor * exposure);
FragColor = vec4(hdrColorAdapted, 1.0);
}
```
- 顶点着色器中,uniform mat4 model, view, projection 是视图矩阵、模型矩阵和投影矩阵,它们都是4x4的矩阵。
- 片元着色器中,uniform sampler2D hdrBuffer 是存储高动态范围纹理的纹理单元,uniform float exposure 是曝光值,它取值范围为大于0的实数。
阅读全文