Hlsl着色器模型5镶嵌管道 [英] Hlsl shader model 5 tessellation pipeline

查看:78
本文介绍了Hlsl着色器模型5镶嵌管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这是正确的地方,我对使用几何和曲面细分着色器的可能性有疑问。

i hope this is the right place, I have a question about the possibilities using both geometry and tessellation shaders.

从我的内容理解,曲面细分和几何着色器工作"每个补丁"。

From what I understand, both the tessellation and the geometry shader work "per patch".

所以例如我制作以下管道:

a。 2顶点进入顶点着色器 - 输出2个顶点(1个基元)

b。 2个顶点(1个补丁?)进入船体着色器("等值线")设置分割64次(edgeFactor 1,64)。输出2个控制点。

c。 2个顶点被细分64次,在1个patch \ primitive(line)上生成64个点。

d。 1个64点的线条流进入几何着色器作为1个基元。

So for example i make the following pipeline:
a. 2 Vertices go into the vertex shader - output 2 vertices (1 primitive)
b. 2 Vertices (1 patch?) go into the hull shader ("isoline") set split 64 times (edgeFactor 1,64). output 2 control points.
c. 2 Vertices are tessellated 64 times generating 64 points on 1 patch\ primitive (line).
d. 1 line stream of 64 points goes into the geometry shader as 1 primitive.

现在几何着色器有一个限制它可以生成多少点(&每个输入原语的"发出",让我们说这个问题和简单,它也是64分。

这意味着如果我没有错,那我在这种情况下做的是我的极限是每个输入补丁64点,在曲面细分过程中细分,或由几何着色器发出。

Now the geometry shader has a limit of how much points it can generate ("emit") per input primitive, lets say for the sake of this question and simplicity that its also 64 points.
that means if I am not wrong, that what ever i do in this scenario my limit is 64 points per input patch, either tessellated in the tessellation process, or emitted by the geometry shader.

现在回到我的主要问题:

so now coming to my main question:

是否可以将域着色器中的点输出到几何着色器,几何着色器会将每个点视为一个唯一的基元,以便它可以进一步细分它? br />


谢谢,

Amit。

is it possible to output points from the domain shader to the geometry shader that the geometry shader would consider each point a unique primitive so it can further tessellate it?

Thanks,
Amit.

推荐答案

在这里你去:



基本思路:CPU-> GPU一个顶点

" tessellate"每个补丁获得64个点的顶点。每个细分点的
创建0,0,0的广告牌。

(我知道它们是在同一位置绘制的。我的问题如果这完全可以从DM的补丁中运行GS每个"点")

我是这个东西的新手,所以,如果我做了一些完全错误的事情,我就是全部耳朵。

Here you go:

Basic idea: CPU->GPU one vertex
"tessellate" the vertex to get 64 points per patch.
per tesselated point create billboard at 0,0,0.
(i know they are drawn at the same position. My question is if this is at all possible to run the GS per "Point" from the patch of the DM)
I am new to this stuff, so please if I am doing something utterly wrong I am all ears.

struct A2V {
	float4 pos:  POSITION;
};

//VERTEX SHADER
/////////////////////////////////////////////////////

struct V2H {
	float4 pos   :POSITION;
};

V2H main_vs( 	in A2V In,
	        uniform float4x4 wvpMat) {
	
	V2H Out;
	
        Out.pos = mul(wvpMat, In.pos);
	
	return Out;
}

//HULL SHADER
/////////////////////////////////////////////////////


struct HCO {
	float Edges[2]	:SV_TessFactor;
};

//patch constant function
HCO patchConstantFunction( InputPatch<V2H,1> inputPatch ) {
	
	HCO Out;
	
	Out.Edges[0] = 1.0f; //detail = line copy
	Out.Edges[1] = 64.0f; //density = divisions

	return Out;
}

struct H2D {
	float4 pos	:POSITION;
};

//tesselation variables
[domain("isoline")]
[partitioning("integer")]
[outputtopology("point")]
[outputcontrolpoints(1)]
[patchconstantfunc("patchConstantFunction")]
// hull main function
H2D main_hs(	InputPatch<V2H,1> In,
		uint pointID 	:SV_OutputControlPointID,
		uint PrimID 	:SV_PrimitiveID	)	{
	
	H2D Out;
	
	Out.pos = In[pointID].pos;

	return Out;
}

//DOMAIN SHADER
/////////////////////////////////////////////////////

struct D2G {
	float4 pos	:SV_Position;
};

//tesselation variables
[domain("isoline")]
D2G main_ds(	HCO In,
		const OutputPatch<H2D, 1> outPatch,
		float2 uv 	:SV_DomainLocation,
		uint PatchID 	:SV_PrimitiveID	)	{
				
	D2G Out;
	
	Out.pos = outPatch[0].pos;
	
	return Out;
}

//GEOMETRY SHADER
/////////////////////////////////////////////////////

struct G2P {
	float4 pos	:SV_Position;
};

void create_square(	float3 position,
			float3 upVec,
			float3 rightVec,
			uniform float4x4 wvpMat,
			inout TriangleStream<G2P> Out	) {
	
	G2P vA,vB,vC,vD;
	
	vA.pos = mul(wvpMat,float4( upVec+rightVec+position,1));
	vB.pos = mul(wvpMat,float4(-upVec+rightVec+position,1));
	vC.pos = mul(wvpMat,float4(-upVec-rightVec+position,1));
	vD.pos = mul(wvpMat,float4( upVec-rightVec+position,1));
	Out.Append(vA);
	Out.Append(vB);
	Out.Append(vD);
	Out.Append(vC);				
	
}

[maxvertexcount(256)]
void main_gs(	point D2G In[1],
		uint pID	:SV_PrimitiveID,
		inout TriangleStream<G2P> Out,
		uniform float4x4 wvpInvMat,
		uniform float4x4 wvpMat,
		uniform float4x4 vMat,
		uniform float4 viewSize,
		uniform float radius	) {
	
	// for all points
	float pixelSize = radius*In[0].pos.w*.001;
	float4x4 TvMat = transpose(vMat);
	float3 camUp = normalize(float3(TvMat._12,TvMat._22,TvMat._32))*(pixelSize);
	float3 camRight = normalize(float3(TvMat._11,TvMat._21,TvMat._31))*(pixelSize);
				
	float4 targetPos=float4(0,0,0,0);
		
	create_square(targetPos.xyz,camUp,camRight,wvpMat,Out);

}

//PIXEL SHADER
/////////////////////////////////////////////////////

struct P2F{
	float4 col	:SV_Target;
};

P2F main_ps(in G2P In	) {

	P2F Out;

        Out.col = float4(1.0,0.0,0.0,1.0);
	
	return Out;
}

非常感谢你:)


这篇关于Hlsl着色器模型5镶嵌管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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