着色器翻转输出图像
我一直在努力找出为什么我的图像有时会在着色器运行并输出结果后翻转的问题。
我将位置图像和法线图像放入着色器中以执行基本的照明计算。位置和法线图像的方向正确,但结果输出似乎最终翻转。我的 SSAO 通道也会发生这种情况,其中 SSAO 通道会翻转图像,但 SSAO 的模糊通道会将图像取消翻转回到正常状态。
我已经利用了
vec2(1.0 - uvCoords.x, uvCoords.y);
虽然这确实将图像反转回正常状态,但它也反转了键盘输入和鼠标控制,因此不是理想的解决方案。
着色器输出到一个四边形,该四边形创建为:
std::vector<Vertex> Quad = {
// pos // color //texcoords
{{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, {1.0f, 0.0f}},
{{1.0f, -1.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
{{1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 1.0f}},
{{-1.0f, 1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, {1.0f, 1.0f}},
{{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, {1.0f, 0.0f}},
{{1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 1.0f}},
};
照明通道着色器:
void main() {
vec3 FragPos = texture(gPosition, uvCoords).rgb;
vec3 Normal = texture(gNormal, uvCoords).rgb;
float ambientValue = 0.1;
vec3 ambient = ambientValue * light.LightColor.xyz;
vec3 lightingDirection = normalize(light.LightPosition.xyz - FragPos);
float diffCalc = max(dot(Normal, lightingDirection), 0.0);
vec3 diffuse = diffCalc * light.LightColor.xyz;
vec3 result = (ambient + diffuse) * light.ObjectColor.xyz;
outColor = vec4(result, 1.0);
}
I have been struggling to figure out the problem behind why my images sometimes end up flipping once the shader has run and output the result.
I take in position and normal images into my shader to perform basic lighting calculations. The position and normal images are correctly orientated but the resulting output seems to end up flipping. This also occurs with my SSAO pass where the SSAO pass flips the image but the blurring pass for the SSAO will then un-flip the image back to normal.
I have utilised
vec2(1.0 - uvCoords.x, uvCoords.y);
While this does invert the image back to normal, it also inverts keyboard input and mouse control and therefore not the ideal solution.
The shader outputs to a quad which is created as:
std::vector<Vertex> Quad = {
// pos // color //texcoords
{{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, {1.0f, 0.0f}},
{{1.0f, -1.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
{{1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 1.0f}},
{{-1.0f, 1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, {1.0f, 1.0f}},
{{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, {1.0f, 0.0f}},
{{1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 1.0f}},
};
Lighting pass shader:
void main() {
vec3 FragPos = texture(gPosition, uvCoords).rgb;
vec3 Normal = texture(gNormal, uvCoords).rgb;
float ambientValue = 0.1;
vec3 ambient = ambientValue * light.LightColor.xyz;
vec3 lightingDirection = normalize(light.LightPosition.xyz - FragPos);
float diffCalc = max(dot(Normal, lightingDirection), 0.0);
vec3 diffuse = diffCalc * light.LightColor.xyz;
vec3 result = (ambient + diffuse) * light.ObjectColor.xyz;
outColor = vec4(result, 1.0);
}
I am showing the G-buffer normal in correct orientation and the resulting lighting pass output image which ends up flipping:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎您的X轴在紫外线坐标网中被拨动,
您可以看到POS X = -1.0F映射到TexCoord 1.0F和POS X 1.0F地图至0.0F,因此它确实将X轴翻转。
Seems your x axis in uv coord mesh is flipped
You can see that pos x = -1.0f maps to texcoord 1.0f and pos x 1.0f maps to 0.0f, so it indeed flips the x axis.