rouncer
01-26-2009, 02: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()));
}
}
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()));
}
}