DirectX 错误总结

写公告板的时候,GeometryShader中写了这样一段代码

cbuffer MatrixBuffer
{
	float4x4 gViewProj;
	float3 gEyePosW;
};


cbuffer cbFixed
{
	float2 gTexC[4] = 
	{
		float2(0.0f, 1.0f),
		float2(0.0f, 0.0f),
		float2(1.0f, 1.0f),
		float2(1.0f, 0.0f)
	};
};


struct VertexOut
{
	float3 CenterW	:	POSITION;
	float2 SizeW	:	SIZE;
};


struct GeoOut
{
	float4 PosH		:	SV_POSITION;
	float3 PosW		:	POSITION;
	float3 NormalW	:	NORMAL;
	float2 Tex		:	TEXCOORD;
};


//将每个点扩展为一个方块(4个顶点),因此顶点数目的最大值为4
[maxvertexcount(4)]
void GS(point VertexOut gin[1] , inout TriangleStream<GeoOut> triStream)
{
	float3 up = float3(0.0f , 1.0f , 0.0f);
	float3 look = gEyePosW - gin[0].CenterW;
	look.y = 0.0f;		//保持方块的中心和眼睛高度一致
	look = normalize(look);

	float3 right = cross(up , look);


	float halfWidth = 0.5f * gin[0].SizeW.x;
	float halfHeight = 0.5f * gin[0].SizeW.y;

	float4 v[4];
	v[0] = float4(gin[0].CenterW + halfWidth * right - halfHeight * up , 1.0f);
	v[1] = float4(gin[0].CenterW + halfWidth * right + halfHeight * up , 1.0f);
	v[2] = float4(gin[0].CenterW - halfWidth * right - halfHeight * up , 1.0f);
	v[3] = float4(gin[0].CenterW - halfWidth * right + halfHeight * up , 1.0f);


	GeoOut gout;
	[unroll]
	for(int i = 0; i < 4; i++)
	{
		gout.PosH		= mul(v[i] , gViewProj);
		gout.PosW		= v[i].xyz;
		gout.NormalW	= look;
		gout.Tex		= gTexC[i];					

		triStream.Append(gout);
	}
}


运行总是运行不出结果~

调试后发现是gout.Tex的问题


然后将代码改为


GeoOut gout;
[unroll]
for(int i = 0; i < 4; i++)
{
	gout.PosH		= mul(v[i] , gViewProj);
	gout.PosW		= v[i].xyz;
	gout.NormalW	<span style="white-space:pre">	</span>= look;


	if(i == 0)
	{
		gout.Tex = float2(0.0f, 1.0f);
	}

	if(i == 1)
	{
		gout.Tex = float2(0.0f , 0.0f);
	}

	if(i == 2)
	{
		gout.Tex = float2(1.0f , 1.0f);
	}

	if(i == 3)
	{
		gout.Tex = float2(1.0f , 0.0f);
	}

	triStream.Append(gout);
}


就可以运行了


原因是cbuffer cbFixed只能在effect framework中使用,所以要么直接在for循环中硬编码(如上),要么从外部传入数据到cbFixed中




还有在运行的时候,只有第一张树的纹理能够显示出来,其他的纹理都是黑色的矩形

原因:Frank的教程中提供的四张树纹理,第一张纹理和后三张的纹理格式不一样,所以要么将其改为同样的格式

    比如将4个纹理的格式由BC1(默认的)改为R8G8B8A8_UNORM

    或者不使用第一张纹理,反正一句话,保证格式一样


Load Texture Array Without D3DX


Problem with Billboarding, Geometry Shader and Texture Array

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值