另一个视口的gl_FragCoord [英] gl_FragCoord of another viewport

查看:119
本文介绍了另一个视口的gl_FragCoord的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试在LWJGL中实现阴影贴图,但遇到了问题,现在卡住了。我已经完成了深度映射,渲染到纹理等但是我被困在最重要的部分,使用所说的阴影贴图,我的问题是,我需要找出我正在着色的片段在阴影贴图上的位置。 br />


例如:

我有一个名为A的片段,它位于坐标X,Y,Z处。

它从灯光的视口渲染到我的阴影贴图上。



当我从另一台摄像机渲染场景时,坐标为S,T,U。例如,我现在需要在阴影贴图上找到片段A的位置,因此我可以从中获取Z值,并将其与我将使用渲染的原始相机的坐标生成的另一个Z值进行比较。阴影贴图。



问题是我不知道如何在阴影贴图上获得A的位置,这意味着我无法分辨是不是它在阴影中。如果有人能帮我计算一个点的阴影贴图坐标,那将非常感激。



对不起,如果它有点长而且过于复杂,但我是试图尽可能详细地解释我的情况。如果你想要一个更简单的解释我想要得到的东西:我基本上需要替换gl_FragCoord,可以用于不同的相机/视口的位置/大小/等。找出一个片段在渲染到纹理的位置。



再一次,我知道这太长了,我很抱歉,并提前感谢任何人谁可以帮忙!

Hi there, I am trying to implement shadow mapping in LWJGL, but have run into a problem, and am now stuck. I have done depth-mapping, render to texture etc. but I am stuck at the most vital part, using said shadow map, my problem is, I need to find out where the fragment I am shading is located on the shadow map.

For example:
I have a fragment called A, it's located at coordinates X,Y,Z.
It is rendered from the light's viewport onto my shadow map.

When I render the scene from a different camera, at coordinates S,T,U. for example, I now need to find out the location of the fragment A on the shadow map, so I can get the Z value from it, and compare it to another Z value I will generate using the coordinates of the original camera that rendered the shadow map.

The issue is that I don't have a clue of how I would get the location of A on the shadow map, meaning I can't tell wether or not it's in shadow. If anyone could help me to calculate shadow map coordinates of a point, that would be much appreciated.

Sorry if it's a bit long and over-complicated, but I am trying to explain my situation in as much detail as possible. If you want a simpler explanation of what I am trying to get: I basically need a replacement of gl_FragCoord that can be used in relation to a different camera/viewport's location/size/etc. to find out the location of a fragment on a render to texture.

Again, I know this is waaaaayyy too long, and my apologies, and thanks in advance to anyone who can help!

推荐答案

这篇关于另一个视口的gl_FragCoord的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆