Forum

DX11 - Converting fx to gsfx: new geometry missing in gsfx while fx is perfect

devvvv

#1

Hi guys, I am building this sweet point extrusion dx11 shader which creates extrusions according to any spread of xyz coordinates(rather than triangles). It works really well in fx shader format but having problem converting it to pure gsfx to do lighting/shading in a different shader. It seems that in gsfx format my shader doesn’t pass the new geometry created by geometry shader but only the incoming input geometry… My gsfx technique is VALID and I think the gsfx code is right, I feel that I am missing something in the actual v4p patch, maybe something to do the input layout or topology?

Anyway have attached a screenshot of the v4p patch itself, please note you can see both gsfx and fx version of extrusion shader and on the right render window you can see it works fine in fx format… Thankx a lot guys. Peace

GSFX Shader code:

float4x4 tWVP: WORLDVIEWPROJECTION;
float4x4 tVI : VIEWINVERSE;
Texture2D texture2d;

SamplerState g_samLinear : IMMUTABLE
{
	Filter = MIN_MAG_MIP_LINEAR;
	AddressU = Wrap;
	AddressV = Wrap;
};

float2 g_texcoords[4](4): IMMUTABLE =
{
	float2(0, 1),
	float2(1, 1),
	float2(0, 0),
	float2(1, 0),
};

float r <String uiname = "Extrude Radius"; > = 0.01f;
bool t <String uiname = "Taper"; > = false;
StructuredBuffer<float3> iPo <String uiname = "Input Positions"; >;
struct vsIn
{
	float4 pos : POSITION;
	uint vertexId : SV_VertexId;
};

struct gsIn
{
	float4 pos: POSITION;
	uint vertexIdPassed : VERTEXID;
};

struct psIn
{
	float3 nor: NORMAL;
	float4 pos: POSITION;
	float2 uv: TEXCOORD0;
};

gsIn VS(vsIn input)
{
	gsIn output;
	output.pos = input.pos;
	output.vertexIdPassed = input.vertexId;
	return output;
}

float3 vP(float3 d){
	float3 re = { 0, 0, 0 };
	//derived from this abstract idea & given arbitrary x2 and y2: z2 = (-x1 * x2 - y1 * y2) / z1
	//re.x and re.y being x2 and y2
	re.x = 1;
	re.y = 1;
	re.z = normalize[-abs(re.x*d.x) - abs(re.y*d.y)](https://vvvv.org/documentation/abs(re.x*d.x)---abs(re.y*d.y));
	if (t){
		re.z = abs(re.z);
	}
	return re;
}

[maxvertexcount(12)](maxvertexcount(12))
void GS_Extrude(point gsIn input[1](1), inout TriangleStream<psIn> SpriteStream)
{
	psIn output;
	for (uint i = 0; i<12; i++)
	{
		float3 po;
		int index = input[0](0).vertexIdPassed + 1;
		float3 dd = iPo[index](index).xyz - input[0](0).pos.xyz;
		float3 goR = vP(dd);
		float3 goD = cross(dd, goR);

		if (i == 0){
			po = input[0](0).pos.xyz;
		}
		else if (i == 1){
			po = iPo[index](index);
		}
		else if (i == 2){
			po = input[0](0).pos.xyz + goR*r;
		}
		else if (i == 3){
			po = iPo[index](index) + goR*r;
		}
		else if (i == 4){
			po = input[0](0).pos.xyz + goR*r + goD*r;
		}
		else if (i == 5){
			dd = iPo[index + 1](index + 1).xyz - iPo[index](index).xyz;
			goR = vP(dd);
			goD = cross(dd, goR);
			po = iPo[index](index) + goR*r + goD*r;
		}
		else if (i == 6){
			po = input[0](0).pos.xyz + goD*r;
		}
		else if (i == 7){
			dd = iPo[index + 1](index + 1).xyz - iPo[index](index).xyz;
			goR = vP(dd);
			goD = cross(dd, goR);
			po = iPo[index](index) + goD*r;
		}
		else if (i == 8){
			po = input[0](0).pos.xyz + goD*r;
		}
		else if (i == 9){
			po = input[0](0).pos.xyz;
		}
		else if (i == 10){
			dd = iPo[index + 1](index + 1).xyz - iPo[index](index).xyz;
			goR = vP(dd);
			goD = cross(dd, goR);
			po = iPo[index](index) + goD*r;
		}
		else if (i == 11){
			po = iPo[index](index);
		}
		if (i<4){
			output.uv = g_texcoords[i](i);
			float2x2 ro = { 0.0f, 1.0f, 1.0f, 0.0f };
			output.uv = mul(output.uv, ro);
		}
		else if (i >= 4 && i<8){
			output.uv = g_texcoords[i - 4](i - 4);
			float2x2 ro = { 0.0f, 1.0f, 1.0f, 0.0f };
			output.uv = mul(output.uv, ro);
		}
		else{
			output.uv = g_texcoords[i - 8](i - 8);
		}
		output.pos = mul(float4(po, 1.0f), tWVP);
		float3 d1 = iPo[index + 1](index + 1).xyz - output.pos.xyz;
		//NORMAL calculation is probably wrong, doesn't matter yet though
		output.nor = cross(d1,goR);
		SpriteStream.Append(output);
	}
	//SpriteStream.RestartStrip();
}

GeometryShader StreamOutGS = ConstructGSWithSO(CompileShader(gs_5_0,GS_Extrude()),
	"POSITION.xyzw; NORMAL.xyz;TEXCOORD0.xy;");

technique11 Extrude
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(CompileShader( gs_5_0, GS_Extrude() ) );
		SetGeometryShader( StreamOutGS );
		SetPixelShader(NULL);
	}
}

Result looks like this (with instancing shader as well)


#2

sorry, can´t help you. picture above shows correct result? very promising.