vertex shader must minimally write all four components of POSITION

本文介绍了解决像素着色器(ps_2_0)无法读取顶点着色器输出的位置数据的问题方法。通过将位置数据标记为TEXCOORD0而非POSITION,使像素着色器能够正确使用该数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

Though the POSITION semantic must be written out by the vertex shader, it cannot be read in by the pixel shader in ps_2_0. So, the fix is to write out the position twice, but one of those is not labeled as POSITION, it is instead labeled as a TEXCOORD0. Then, the pixel shader does not use the POSITION semantic variable, but uses the TEXCOORD0 instead. To the compiler it effectively means that the POSITION input to the pixel shader can be ignored.

 

right code:

 

float4x4 ViewProjection;

struct VS_INPUT
{
float4 Position : POSITION0;
float3 Normal : NORMAL0;
float2 tcBase:TEXCOORD0;
};

struct VS_OUTPUT
{
float4 Position : POSITION0;
float3 Normal : TEXCOORD1;
float2 tcBase:TEXCOORD2;
};

}

VS_OUTPUT vs_main( VS_INPUT Input )
{
VS_OUTPUT Output;

Output.Position = mul( Input.Position, ViewProjection );
Output.Normal = Input.Normal;
Output.tcBase = Input.tcBase;
return( Output );
}

 

sampler AmbOcclusion;
sampler DiffuseEnvironment;

struct PS_OUTPUT
{
float4 Position : TEXCOORD0;
float3 Normal : TEXCOORD1;
float2 tcBase:TEXCOORD2;
};

float4 ps_main(PS_OUTPUT Input) : COLOR0
{
// Sample the filtered environment map
float4 ambient = texCUBE(DiffuseEnvironment, Input.Normal);

// Sample the ambient occlusion map
float ambientOcclusion = tex2D(AmbOcclusion, Input.tcBase).r;
return ambient * ambientOcclusion;
}

 

转载于:https://www.cnblogs.com/alps/p/7257282.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值