admin管理员组文章数量:1356948
I'm very new to shader programming, so five me for any knowledge gaps or mistakes I've made.
I am currently following a technique discussed in Nvidia's GPU Gems: .
In here, it is mentioned that they passed the depth buffer into the pixel shader as a texture to find the world space positions of objects.
I've started my project using Visual Studio's Universal C++ template of a DirectX11 application that gave me the following vertex shader starter program:
cbuffer ModelViewProjectionConstantBuffer : register(b0)
{
matrix model;
matrix view;
matrix projection;
};
struct VertexShaderInput
{
float3 pos : POSITION;
float3 color : COLOR0;
};
struct PixelShaderInput
{
float4 pos : SV_POSITION;
float3 color : COLOR0;
};
PixelShaderInput main(VertexShaderInput input)
{
PixelShaderInput output;
float4 pos = float4(input.pos, 1.0f);
pos = mul(pos, model);
pos = mul(pos, view);
pos = mul(pos, projection);
output.pos = pos;
output.color = input.color;
return output;
}
Along with the following starter pixel shader program:
struct PixelShaderInput
{
float4 pos : SV_POSITION;
float3 color : COLOR0;
};
float4 main(PixelShaderInput input) : SV_TARGET
{
return float4(input.color, 1.0f);
}
And in the Nvidia Article, the following pixel shader code snippet:
// Get the depth buffer value at this pixel.
float zOverW = tex2D(
depthTexture,
texCoord); // H is the viewport position at this pixel in the range -1 to 1.
float4 H = float4(texCoord.x * 2 - 1, (1 - texCoord.y) * 2 - 1, zOverW,
1); // Transform by the view-projection inverse.
float4 D = mul(
H, g_ViewProjectionInverseMatrix); // Divide by w to get the world position.
float4 worldPos = D / D.w;
seems to imply that their pixel shader was already set up to access the "depth buffer texture". I'm not sure what I need to do to access the depth buffer value in my code.
本文标签: cPassing depth buffer values as a texture to pixel shaderStack Overflow
版权声明:本文标题:c++ - Passing depth buffer values as a texture to pixel shader - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744064032a2584657.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论