• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Problem with compile shader from file

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

38 replies to this topic

### #21Arkanoid  Members

Posted 20 March 2012 - 09:42 AM

I find only one problem:

before VS all vertexes have different position

and after VS all 0...so how to fix it?

### #22Asesh  Members

Posted 20 March 2012 - 06:05 PM

see that column VTX in PostVS tab? 0 1 2 3...click one of those and debug your vertex shader. IDX are indices, looking that picture, they are not correct either. Am guessing, the homogeneous matrix is not being update in the shader. Debug and find it out

### #23Arkanoid  Members

Posted 21 March 2012 - 09:13 AM

//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
// Parameters:
//
// float4x4 worldViewProj;
//
//
// Registers:
//
// Name Reg Size
// ------------- ----- ----
// worldViewProj c0 4
//

vs_2_0
def c4, 1, 0, 0, 0
dcl_position v0
dcl_color v1
dcl_texcoord v2
dp4 oPos.x, r0, c0
dp4 oPos.y, r0, c1
dp4 oPos.z, r0, c2
dp4 oPos.w, r0, c3
mov oD0, v1
mov oT0.xy, v2

// approximately 7 instruction slots used

if i understand correctly this is 0 vertex debug.
and Registry:
c4  (1.000,0.000,0.000,0.000) float4
v0 (909.163,59.139,-1585.124,1.000) float4
and what is wrong? I can post my VS too.

### #24Asesh  Members

Posted 21 March 2012 - 09:42 AM

As far as I remember c# are constant registers and v# are output registers but don't remember much though. Debug your shader in via HLSL rather than going through the disassembled code...anyways, when debugging your shader monitor the value of variables from the variables tab. Look at the value of homogeneous matrix from that tab.

### #25Asesh  Members

Posted 21 March 2012 - 09:49 AM

Rather than waiting for someone to reply goto gamedev chat room: http://www.gamedev.net/community/chat

### #26Arkanoid  Members

Posted 21 March 2012 - 10:40 AM

well i asked there and sb tell me that i can multiply anything by a zero matrix and tend to get null vectors.
...

float4x4 worldViewProj;

struct VS_INPUT
{
float3 position : POSITION;
float4 color0 : COLOR0;
float2 texcoord0 : TEXCOORD0;
};

struct VS_OUTPUT
{
float4 hposition : POSITION;
float4 color0 : COLOR0;
float2 texcoord0 : TEXCOORD0;
};

VS_OUTPUT main( VS_INPUT IN )
{
VS_OUTPUT OUT;

float4 v = float4( IN.position.x,
IN.position.y,
IN.position.z,
1.0f );

OUT.hposition = mul( v, worldViewProj );
OUT.color0 = IN.color0;
OUT.texcoord0 = IN.texcoord0;

return OUT;
}

its my shader code...where can i multiply by a zero here?

### #27Asesh  Members

Posted 21 March 2012 - 10:44 AM

well, use PIX to check the value of

worldViewProj

in your shader. Am sure that matrix is not being updated in the shader from external source

### #28Asesh  Members

Posted 21 March 2012 - 10:47 AM

BTW, there's nothing wrong in that shader...

### #29Arkanoid  Members

Posted 21 March 2012 - 01:24 PM

well, use PIX to check the value of

i tried maybe all...rad SDK and i don't know how to chek it , can you plz tell me where i can see it?

P.S. If you sure where is the problem - can you simply say how to fix it?

### #30Dancin_Fool  Members

Posted 21 March 2012 - 01:28 PM

i tried maybe all...rad SDK and i don't know how to chek it , can you plz tell me where i can see it?

P.S. If you sure where is the problem - can you simply say how to fix it?

### #31Arkanoid  Members

Posted 22 March 2012 - 07:50 AM

Yes i found a mistake! Thanks very much for help!

### #32Arkanoid  Members

Posted 22 March 2012 - 09:14 AM

but how i can give my shader other variables? like this:
float4x4 matWorld;
float4 vec_light;

for worldViewProj i have special function: g_pConstantTableVS->SetMatrix
but have can i set other vectors or matrixes? Or they just need to have same name?

### #33Asesh  Members

Posted 22 March 2012 - 10:04 AM

you are free to declare more variables and update those variables from external source

### #34Arkanoid  Members

Posted 23 March 2012 - 01:39 PM

well for example:
float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecLightDir;

struct VS_OUTPUT
{
float4 Pos : POSITION;
float3 Light : TEXCOORD0;
float3 Norm : TEXCOORD1;
};

VS_OUTPUT VS(float4 Pos : POSITION, float3 Normal : NORMAL)
{
VS_OUTPUT Out = (VS_OUTPUT)0;
Out.Pos = mul(Pos, matWorldViewProj); // transform Position
Out.Light = vecLightDir; // output light vector
Out.Norm = normalize(mul(Normal, matWorld)); // transform Normal and normalize it
return Out;
}
this shader code need texture coordinates, but when i use PIX - i see that all textures positions are 0. I update all variables in render:

for(int b =1;b<MeshCount+1;b++)
{
for( DWORD i = 0; i < g_dwNumMaterials[b]; i++ )
{

{
//
// Use vertex and pixel shaders...
//
g_pd3dDevice->SetMaterial( &entity[b].g_pMeshMaterials[i] );
g_pd3dDevice->SetTexture( 0,entity[b].g_pMeshTextures[1] );
g_pd3dDevice->SetTexture( 1,entity[b].g_pMeshTextures[2] );

D3DXVECTOR3 vecLightDir(10,10,10);
D3DXMATRIX matWorldViewProj = matWorld * matView *matProj;
g_pConstantTableVS->SetMatrix( g_pd3dDevice, " matWorldViewProj", &matWorldViewProj );

g_pd3dDevice->SetVertexDeclaration( g_pVertexDeclaration );

g_pMesh[b]->DrawSubset( i );
}

i update all, why shader cannot see coordinates?

### #35Dancin_Fool  Members

Posted 23 March 2012 - 01:50 PM

Secondly, does the geometry have UV coordinates?

I think you need to take a step back and review what you have so far, and understand what everything is doing.

### #36Arkanoid  Members

Posted 24 March 2012 - 01:32 PM

I find all information that i need to, now shaders are working good. But there is the last thing that i cannot understand, i don't want start new topic, so : how to add to my mesh more then 1 textures?Mesh have 1 diffuse map, but in shader i need second texture for bump mapping, where can i add it to my mesh? For example in 3dsMax? Or where? Can i load it in code?

### #37Asesh  Members

Posted 25 March 2012 - 06:48 AM

### #38Arkanoid  Members

Posted 26 March 2012 - 04:38 AM

I still cannot find working sample of HLSL bump. I found only diffuse lighting...sb know where to find working HLSL effects?

### #39Asesh  Members

Posted 26 March 2012 - 10:01 AM