Jump to content
  • Advertisement
Sign in to follow this  
Nathan Drake

DX11 Vertex Shader Output

This topic is 1004 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello guys wub.png

it's me again mellow.png

I've facing on a wired issue here.

This is my Vertex Shader code:

 

[SPOILER]

struct Light
{
    float3 dir;
    float cone;
    float3 pos;
    float  range;
    float3 att;
    float4 ambient;
    float4 diffuse;
    float pixelSampleArray[64];
};
 
cbuffer cbPerFrame
{
    Light light;
};
 
cbuffer cbPerObject
{
    float4x4 WVP;
    float4x4 World;
    float NegORPos;
    float4x4 lightWVP;
    float4x4 lightView;
};
 
Texture2D ObjTexture;
Texture2D depthMapTexture;
Texture2D positionMapTexture;
Texture2D normalMapTexture;
Texture2D fluxMapTexture;
SamplerState ObjSamplerState;
SamplerState ObjSamplerStateClamp;
 
 
struct VS_OUTPUT
{
    float4 Pos : SV_POSITION;
    float3 lightPos : TEXCOORD1;
    float4 lightVP : TEXCOORD2;
    float4 worldPos : POSITION0;
    float2 TexCoord : TEXCOORD0;
    float3 normal : NORMAL;
};
 
 
VS_OUTPUT VS(float4 inPos : POSITION, float2 inTexCoord : TEXCOORD, float3 normal : NORMAL)
{
    VS_OUTPUT output = (VS_OUTPUT)0;
 
    inPos.w = 1.0f;
    output.Pos = mul(inPos, WVP);
    //output.lightVP = mul(inPos, lightWVP);
 
    output.worldPos = mul(inPos, World);
 
    output.lightPos = float4(normalize(light.pos - output.worldPos.xyz),1.0f);
 
    output.normal = (mul(normal, World));
    output.normal = normalize(output.normal);
    output.TexCoord = inTexCoord;
 
    return output;
}

[/SPOILER]

 

when i comment line 40, my usual output works without any issue:

 

[SPOILER]

sdW6NV3.png

[/SPOILER]

 

but when i uncomment line 40, my scene will repeat 22*22 times. this is the output:

 

[SPOILER]

AMmz3NN.png

[/SPOILER]

 

and this is the disassembly of my Vertex Shader that i've got from Render Doc:

Shader hash dad50848-c305871f-aea7256f-1c81645b

vs_5_0
      dcl_globalFlags refactoringAllowed
      dcl_constantbuffer cb0[2], immediateIndexed
      dcl_constantbuffer cb1[8], immediateIndexed
      dcl_input v0.xyz
      dcl_input v1.xy
      dcl_input v2.xyz
      dcl_output_siv o0.xyzw, position
      dcl_output o1.xyz
      dcl_output o3.xyzw
      dcl_output o4.xy
      dcl_output o5.xyz
      dcl_temps 5

      c:\users\mahdi\documents\visual studio 2013\projects\dx11revision_project4\dx11revision_project2\vertexshader.hlsl:51
      inPos.w = 1.0f;
   0: mov r0.w, l(1.000000)

      output.Pos = mul(inPos, WVP);
   1: mov r0.xyz, v0.xyzx
   2: dp4 r1.x, r0.xyzw, WVP[0].xyzw
   3: dp4 r1.y, r0.xyzw, WVP[1].xyzw
   4: dp4 r1.z, r0.xyzw, WVP[2].xyzw
   5: dp4 r1.w, r0.xyzw, WVP[3].xyzw

      output.worldPos = mul(inPos, World);
   6: dp4 r2.x, r0.xyzw, World[0].xyzw
   7: dp4 r2.y, r0.xyzw, World[1].xyzw
   8: dp4 r2.z, r0.xyzw, World[2].xyzw
   9: dp4 r2.w, r0.xyzw, World[3].xyzw

      output.lightPos = float4(normalize(light.pos - output.worldPos.xyz),1.0f);
  10: mov r0.xyz, -r2.xyzx
  11: add r0.xyz, r0.xyzx, pos.xyzx
  12: dp3 r0.w, r0.xyzx, r0.xyzx
  13: rsq r0.w, r0.w
  14: mul r0.xyz, r0.wwww, r0.xyzx

      output.normal = (mul(normal, World));
  15: dp3 r3.x, v2.xyzx, World[0].xyzx
  16: dp3 r3.y, v2.xyzx, World[1].xyzx
  17: dp3 r3.z, v2.xyzx, World[2].xyzx

      output.normal = normalize(output.normal);
  18: dp3 r0.w, r3.xyzx, r3.xyzx
  19: rsq r0.w, r0.w
  20: mul r3.xyz, r0.wwww, r3.xyzx

      output.TexCoord = inTexCoord;
  21: mov r4.xy, v1.xyxx

      return output;
  22: mov o0.xyzw, r1.xyzw
  23: mov o3.xyzw, r2.xyzw
  24: mov o1.xyz, r0.xyzx
  25: mov o5.xyz, r3.xyzx
  26: mov o4.xy, r4.xyxx
  27: ret

i want to ask does Vertex Shader has some capacity on their output or not ?

even when i change lightVP datatype from float4 to float, i can see the usual scene.  huh.png

 

if there is a capacity, what is you suggestion to pass that variable from vertex shader to pixel shader ?

 

Regards

Edited by Nathan Drake

Share this post


Link to post
Share on other sites
Advertisement

If I was a betting man... your use of both SV_POSITION and POSITION0 semantics is confusing things.  POSITION0 was the old SM2/3 output position which was replaced by SV_POSITION in newer shader models.  Change POSITION0 to something else and see what happens.

Share this post


Link to post
Share on other sites

I haven't seen any issue in my pixel shader (maybe there are)

this is my code for my pixel shader:

 

[SPOILER]

struct Light
{
	float3 dir;
	float cone;
	float3 pos;
	float  range;
	float3 att;
	float4 ambient;
	float4 diffuse;
	float pixelSampleArray[512];
};

cbuffer cbPerFrame
{
	Light light;
};

cbuffer cbPerObject
{
	float4x4 WVP;
	float4x4 World;
	float NegORPos;
	float4x4 lightWVP;
	float4x4 lightView;
};

Texture2D ObjTexture;
Texture2D depthMapTexture;
Texture2D positionMapTexture;
Texture2D normalMapTexture;
Texture2D fluxMapTexture;
SamplerState ObjSamplerState;
SamplerState ObjSamplerStateClamp;


struct VS_OUTPUT
{
	float4 Pos : SV_POSITION;
	float3 lightPos : TEXCOORD1;
	float4 LightVP: TEXCOORD2;
	float4 worldPos : TEXCOORD3;
	float2 TexCoord : TEXCOORD0;
	float3 normal : NORMAL;
};

//float myNewSamples[16] : TEXCOORD2;

float4 PS(VS_OUTPUT input) : SV_TARGET
{

	float2 projectTexCoord;
	float2 worldTexCoord;
	float depthValue;
	float lightDepthValue;
	float bias;
	float lightIntensity = 0.0f;

	//fixing the floating point precision issues.
	bias = 0.001f;

	// Calculate the projected texture coordinates.
	projectTexCoord.x = input.lightPos.x / input.lightPos.z / 2.0f + 0.5f;
	projectTexCoord.y = -input.lightPos.y / input.lightPos.z / 2.0f + 0.5f;


	float3 SM = float3(0.0f, 0.0f, 0.0f);
	float3 D = light.ambient;
	float4 TextureColor = ObjTexture.SampleLevel(ObjSamplerState, input.TexCoord, 0);
	float3 finalAmbient = TextureColor * light.ambient;

	depthValue = depthMapTexture.Sample(ObjSamplerStateClamp, projectTexCoord).r;

	lightDepthValue = input.lightPos.z / input.lightPos.z;
	lightDepthValue = lightDepthValue - bias;


	if (lightDepthValue < depthValue)
	{
		lightIntensity = saturate(dot(input.normal, input.lightPos));
		if (lightIntensity > 0.0f)
		{
			// Determine the final diffuse color based on the diffuse color and the amount of light intensity.
			D += (light.diffuse * lightIntensity);

			// Saturate the final light color.
			D = saturate(D);
		}
	}

	SM = D * TextureColor;

	float3 ID = float3(0, 0, 0);


	[unroll(4)]
	for (int i =0; i <2; i++)
	{
		//float2 data = float2(input.myNewSamples[i*2], input.myNewSamples[i*2+1]);
		float2 data = float2(light.pixelSampleArray[i * 2], light.pixelSampleArray[i * 2 + 1]);
		float2 newTexCoord = projectTexCoord + data;

		float3 flux = fluxMapTexture.SampleLevel(ObjSamplerStateClamp, newTexCoord, 0).xyz;
		float3 rsmNormal = (normalMapTexture.SampleLevel(ObjSamplerStateClamp, newTexCoord, 0).xyz - 0.5) * 2.0;
		float3 rsmPosition = (positionMapTexture.SampleLevel(ObjSamplerStateClamp, newTexCoord, 0).xyz - 0.5) * 1000;

		float distance = length(input.worldPos.xyz - rsmPosition);

		float3 omega = (input.worldPos.xyz - rsmPosition).xyz;
		float ndotl1 = max(0, dot(rsmNormal, omega));
		float ndotl2 = max(0, dot(input.normal, -omega));

		ID += flux *((ndotl1 * ndotl2) / (distance * distance));
	}

	//SM += ID;

	return float4 (SM, 1.0f);
}

[/SPOILER]

Share this post


Link to post
Share on other sites

Wow, there are some difference in terms of orders

 

with this order:

 

struct VS_OUTPUT
{
    float4 Pos : SV_POSITION;
    float2 TexCoord : TEXCOORD0;
    float3 lightPos : TEXCOORD1;
    float4 lightVP : TEXCOORD2;
    float4 worldPos : TEXCOORD3;
    float3 normal : NORMAL;
};

 

this is my output:

 

[SPOILER]

RhXr817.png

[/SPOILER]

 

and this order

 

struct VS_OUTPUT
{
    float4 Pos : SV_POSITION;

    float3 normal : NORMAL;
    float2 TexCoord : TEXCOORD0;
    float3 lightPos : TEXCOORD1;
    float4 lightVP : TEXCOORD2;
    float4 worldPos : TEXCOORD3;
};

 

my output:

 

[SPOILER]

XJrqqNi.png

[/SPOILER]

 

it is still buggy, but it's good to know their order is matter ! smile.png

Share this post


Link to post
Share on other sites

finally it works with this order:

struct VS_OUTPUT
{
    float4 Pos : SV_POSITION;
    float4 worldPos : TEXCOORD3;
    float3 normal : NORMAL;
    float2 TexCoord : TEXCOORD0;
    float3 lightPos : TEXCOORD1;
    float4 lightVP : TEXCOORD2;
};

 

YEAS cool.png

 

Thank you so much

Edited by Nathan Drake

Share this post


Link to post
Share on other sites

I'm surprised it drew anything at all. The debug layer should scream at a input-output mismatch (from VS to the next stage, probably pixel shader in your case). Order and type must be identical (there are exceptions: system value semantics, and one can also strip semantics from the end in a follow-up stage). But seriously, look at the debug output.

 

Edit: sort of ninja-ed by mere seconds smile.png

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!