Jump to content


dx10 disaster


11 replies to this topic

#1 rouncer

    Senior Member

  • Members
  • PipPipPipPip
  • 2722 posts

Posted 26 January 2009 - 10:56 AM

Im in dx10, and im performing a triangle id render by sticking the ids of the triangles in the second texture coordinate.
But the texture coordinate isnt getting through to the shader.
Ive been having problems like this ever since i moved to dx10, its been a total disaster for me!!!
Id give anything to go back to dx9 but I cant have displacement mapping so its not an option.
Dx10 is total asshole, so many wierd things happened and I cant even do the simplest thing with it.

vdmvertex is the structure, theres the layoutdesc and the shader, but nothings wrong as I see it, im blaming
the api.

struct vdmvertex

{

 VEC pos;

 VEC nor;

 float u;

 float v;

 float w;

 float t;

};


LAYOUTDESC lay[] =

 {

  {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0},  

  {"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT,   0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0}, 

  {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT,    0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0}, 

  {"TEXCOORD", 1, DXGI_FORMAT_R32G32_FLOAT,    0, 32, D3D10_INPUT_PER_VERTEX_DATA, 0}, 

 };


shader code:



struct vs_input8

{

 float4 pos : POSITION; 

 float3 nor : NORMAL;

 float2 uv  : TEXCOORD;

 float2 id  : TEXCOORD1;

};


struct gs_input8

{

 float4 pos : POSITION;

 float3 nor : TEXCOORD1;

 float2 uv  : TEXCOORD0;

 float2 id  : TEXCOORD2;

};


struct ps_input8

{

 float4 pos : SV_POSITION;

 float2 id : TEXCOORD0;

};



gs_input8 vs8(vs_input8 input)

{

 gs_input8 output = (gs_input8)0;

 output.pos = input.pos;

 output.nor=input.nor;

 output.uv = input.uv;

 output.id = input.id;

 

 return output;

}




[maxvertexcount(100)]

void gs8(triangle gs_input8 input[3], inout TriangleStream<ps_input8> TriStream)

{

 ps_input8 output;


 int segs=8;


 float4 posvec[2];

 float2 uvvec[2];

 float3 norvec[2];

 

 posvec[0]=input[1].pos-input[0].pos;

 posvec[1]=input[2].pos-input[1].pos;

 uvvec[0]=input[1].uv-input[0].uv;

 uvvec[1]=input[2].uv-input[1].uv;

 norvec[0]=input[1].nor-input[0].nor;

 norvec[1]=input[2].nor-input[1].nor;


 posvec[0]/=(float)segs;

 posvec[1]/=(float)segs;

 uvvec[0]/=(float)segs;

 uvvec[1]/=(float)segs;

 norvec[0]/=(float)segs;

 norvec[1]/=(float)segs;

 

 float4 p[2];

 float2 uv[2];

 float3 n[2];

 float3 nor;

 

 p[0]=input[0].pos;

 uv[0]=input[0].uv;

 n[0]=input[0].nor;

 float height;


 height=0;

 

 float2 uv2;

 output.id=input[0].id;

 

 int i,j;

 for(i=0;i<segs;i++)

 {

  nor=normalize(n[0]+norvec[0]*(i));

  output.pos=p[0]+posvec[0]*(i);

  uv2=uv[0]+uvvec[0]*(i);

  height=dift.SampleLevel(sstate,uv2,0)*2-1;

  output.pos.xyz+=height*nor*0.5f;

  output.pos=mul(output.pos,wvp);

  TriStream.Append(output);


  nor=normalize(n[0]+norvec[0]*(i+1));

  output.pos=p[0]+posvec[0]*(i+1);

  uv2=uv[0]+uvvec[0]*(i+1);

  height=dift.SampleLevel(sstate,uv2,0)*2-1;

  output.pos.xyz+=height*nor*0.5f;

  output.pos=mul(output.pos,wvp);

  TriStream.Append(output);

 

  for(j=0;j<i+1;j++)

  {

   if(j==i)

   {

    nor=normalize(n[0]+norvec[0]*(i+1)+norvec[1]*(j+1));

    output.pos=p[0]+posvec[0]*(i+1)+posvec[1]*(j+1);

    uv2=uv[0]+uvvec[0]*(i+1)+uvvec[1]*(j+1);

    height=dift.SampleLevel(sstate,uv2,0)*2-1;

    output.pos.xyz+=height*nor*0.5f;

    output.pos=mul(output.pos,wvp);

    TriStream.Append(output);

   }

   else

   {

    nor=normalize(n[0]+norvec[0]*(i)+norvec[1]*(j+1));

    output.pos=p[0]+posvec[0]*(i)+posvec[1]*(j+1);

    uv2=uv[0]+uvvec[0]*(i)+uvvec[1]*(j+1);

    height=dift.SampleLevel(sstate,uv2,0)*2-1;

    output.pos.xyz+=height*nor*0.5f;

    output.pos=mul(output.pos,wvp);

    TriStream.Append(output);

    nor=normalize(n[0]+norvec[0]*(i+1)+norvec[1]*(j+1));

    output.pos=p[0]+posvec[0]*(i+1)+posvec[1]*(j+1);

    uv2=uv[0]+uvvec[0]*(i+1)+uvvec[1]*(j+1);

    height=dift.SampleLevel(sstate,uv2,0)*2-1;

    output.pos.xyz+=height*nor*0.5f;

    output.pos=mul(output.pos,wvp);

    TriStream.Append(output);

   }

   

  }

  TriStream.RestartStrip();  

 }

}




float4 ps8(ps_input8 input) : SV_Target

{

 float4 col=float4(input.id.x,input.id.y,0,1);

 

 return col;

}



technique10 id

{

 pass P0

 {

  SetVertexShader(CompileShader(vs_4_0,vs8()));

  SetGeometryShader(CompileShader(gs_4_0,gs8()));

  SetPixelShader(CompileShader(ps_4_0,ps8()));

 }

}




#2 kusma

    Valued Member

  • Members
  • PipPipPip
  • 163 posts

Posted 26 January 2009 - 11:30 AM

Is there a reason why you aren't simply using SV_PrimitiveID? Also, I don't think you're using the semantic index in the right way - yes it was like that in DX9, but in DX10 the semantic index seems to be intended specificly for matrices, and not multiple (otherwise unrelated) streams. Try using "TEXCOORD0" and "TEXCOORD1", like this:

{"TEXCOORD0", 0, DXGI_FORMAT_R32G32_FLOAT,    0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0}, 
{"TEXCOORD1", 0, DXGI_FORMAT_R32G32_FLOAT,    0, 32, D3D10_INPUT_PER_VERTEX_DATA, 0}, 


#3 rouncer

    Senior Member

  • Members
  • PipPipPipPip
  • 2722 posts

Posted 26 January 2009 - 01:42 PM

That makes my screen go all garbled, what else could i have gotten wrong?

Also, what is SV_PrimitiveID?

#4 kusma

    Valued Member

  • Members
  • PipPipPip
  • 163 posts

Posted 26 January 2009 - 02:05 PM

Uhm, dunno. Screenshot, perhaps?

http://letmegoogleth...=SV_PrimitiveID
Basically, it's a special semantic meant to get the primitive index of a draw-call. The value can be read from both the geometry shader and the pixel shader.

#5 kusma

    Valued Member

  • Members
  • PipPipPip
  • 163 posts

Posted 26 January 2009 - 07:39 PM

No, that was my bad about the vertex declaration. The usage-index should not have the semantic-index inlined into the semantic name. Doing so makes the creating of the vertex declatation fail.

#6 rouncer

    Senior Member

  • Members
  • PipPipPipPip
  • 2722 posts

Posted 27 January 2009 - 04:44 AM

Thanks alot, but im still screwed and dont know what to do.

Can you PLEAASE help me with a bit of example code to get 2 texture coordinates going at once?

#7 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 939 posts

Posted 27 January 2009 - 03:45 PM

Isn't there examples in the DXSDK that can show you that?
"Stupid bug! You go squish now!!" - Homer Simpson

#8 kusma

    Valued Member

  • Members
  • PipPipPip
  • 163 posts

Posted 27 January 2009 - 06:08 PM

roucer: my first attempt worked out just fine... I'll see if I can smack together some source code.

#9 kusma

    Valued Member

  • Members
  • PipPipPip
  • 163 posts

Posted 27 January 2009 - 06:19 PM

Alright, here's basically the code. DXERR is a macro that basically outputs an error and exits when passed an error-code.

fx-file:
float4x4 mvp;

struct PS_INPUT

{

	float4 pos : SV_POSITION;

	float2 tex1 : TEXCOORD1;

	float2 tex2 : TEXCOORD2;

};


PS_INPUT VS( float4 pos : POSITION, float2 tex1 : TEXCOORD0, float2 tex2 : TEXCOORD1 )

{

	PS_INPUT o;

	o.pos = mul(pos, mvp);

	o.tex1 = tex1;

	o.tex2 = tex2;

	return o;

}


float4 PS( PS_INPUT i ) : SV_Target

{

	return float4( i.tex1.xy * i.tex2.xy, 1, 1 );

}


technique10 Render

{

	pass P0

	{

		SetVertexShader( CompileShader( vs_4_0, VS() ) );

		SetGeometryShader( NULL );

		SetPixelShader( CompileShader( ps_4_0, PS() ) );

	}

}

init code:
CONST D3D10_INPUT_ELEMENT_DESC decl[] = 

{

	{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0 },

	{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT,    0, sizeof(float) * 3, D3D10_INPUT_PER_VERTEX_DATA, 0 },

	{"TEXCOORD", 1, DXGI_FORMAT_R32G32_FLOAT,    0, sizeof(float) * (3 + 2), D3D10_INPUT_PER_VERTEX_DATA, 0 },

};

ID3DX10Mesh *mesh = NULL;

D3DERR(D3DX10CreateMesh(

	pd3dDevice,

	decl,

	sizeof(decl) / sizeof(decl[0]),

	"POSITION",

	8,

	4,

	0,

	&mesh

	)

);

		

		

const float verts[] =

{

	-1, -1, -1, 0, 0, 0, 0,

	-1,  1, -1, 0, 1, 1, 0,

	 1, -1, -1, 1, 0, 0, 1,

	 1,  1, -1, 1, 1, 1, 1,

	

	 -1, -1, 1, 0, 0, 0, 0,

	  1, -1, 1, 1, 0, 0, 1,

	 -1,  1, 1, 0, 1, 1, 0,

	  1,  1, 1, 1, 1, 1, 1,

};

D3DERR(mesh->SetVertexData(0, verts));

		

const unsigned short indices[] = {

	0, 1, 2,

	2, 1, 3,

	4, 5, 6,

	6, 5, 7

};

		

D3DERR(mesh->SetIndexData(indices, 6 * 2));

D3DERR(mesh->CommitToDevice());

		

ID3D10Effect *pEffect = NULL;

D3DERR(D3DX10CreateEffectFromFile(

	_T("test.fx"), NULL, NULL, "fx_4_0", D3D10_SHADER_OPTIMIZATION_LEVEL3 | D3D10_SHADER_ENABLE_STRICTNESS, D3D10_EFFECT_SINGLE_THREADED,

	pd3dDevice, NULL, NULL, &pEffect, NULL, NULL));

		

ID3D10EffectTechnique *pTechnique = pEffect->GetTechniqueByName( "Render" );

		

// Create the input layout

D3D10_PASS_DESC PassDesc;

pTechnique->GetPassByIndex( 0 )->GetDesc( &PassDesc );

		

ID3D10InputLayout *pVertexLayout = NULL;

D3DERR(pd3dDevice->CreateInputLayout(

	decl,

	sizeof(decl) / sizeof(decl[0]),

	PassDesc.pIAInputSignature,

	PassDesc.IAInputSignatureSize,

	&pVertexLayout

	)

);


ID3D10EffectMatrixVariable *mvpVar = pEffect->GetVariableByName("mvp" )->AsMatrix();


rendering code:

D3D10_VIEWPORT vp;

vp.Width = width;

vp.Height = height;

vp.MinDepth = 0.0f;

vp.MaxDepth = 1.0f;

vp.TopLeftX = 0;

vp.TopLeftY = 0;		

pd3dDevice->RSSetViewports( 1, &vp );

			

float ClearColor[4] = { 0.0f, 0.125f, 0.6f, 1.0f };

pd3dDevice->ClearRenderTargetView(pRenderTargetView, ClearColor);

			

D3DXMATRIX proj = Matrix4x4::projection(90.0f, 16.0 / 9, 1.0, 1000.0f);

D3DXMATRIX mv = Matrix4x4::rotation(Vector3(time, time * 0.25, time * 0.1)) * Matrix4x4::translation(Vector3(0, 0, 3));

D3DXMATRIX mvp = mv * proj;

D3DERR(mvpVar->SetMatrix( (float*)&mvp ));


pd3dDevice->IASetInputLayout(pVertexLayout);


// Render a triangle

D3D10_TECHNIQUE_DESC techDesc;

D3DERR(pTechnique->GetDesc( &techDesc ));

for( UINT p = 0; p < techDesc.Passes; ++p )

{

	D3DERR(pTechnique->GetPassByIndex(p)->Apply(0));

	D3DERR(mesh->DrawSubset(0));

}

			

D3DERR(demosys::pSwapChain->Present(int(config::vsync != 0), 0));




#10 kusma

    Valued Member

  • Members
  • PipPipPip
  • 163 posts

Posted 27 January 2009 - 06:21 PM

Uhm, and yeah, Matrix4x4 :: projection() and Matrix4x4 :: rotation() are wrappers for D3DXMatrixPerspectiveFovLH() and D3DXMatrixRotationYawPitchRoll().

#11 rouncer

    Senior Member

  • Members
  • PipPipPipPip
  • 2722 posts

Posted 28 January 2009 - 05:09 AM

Thankyou kusma for taking the time to help my dumb ass, ill examine the code thoroughly.
Guess what im trying to code, compressed zbrush.

#12 rouncer

    Senior Member

  • Members
  • PipPipPipPip
  • 2722 posts

Posted 28 January 2009 - 06:54 AM

Thats exactly what I DID!!!!! my computers just fucking me around.


I dont have any dxerrs around but i think im gonna quit programming, its just given me hell.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users