Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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.

  • You cannot reply to this topic
38 replies to this topic

#21 Arkanoid   Members   -  Reputation: 109

Like
0Likes
Like

Posted 20 March 2012 - 09:42 AM

I find only one problem:
Posted Image
before VS all vertexes have different position
Posted Image
and after VS all 0...so how to fix it?

Sponsor:

#22 Asesh   Members   -  Reputation: 268

Like
0Likes
Like

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

#23 Arkanoid   Members   -  Reputation: 109

Like
0Likes
Like

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
mad r0, v0.xyzx, c4.xxxy, c4.yyyx
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.

#24 Asesh   Members   -  Reputation: 268

Like
0Likes
Like

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.

#25 Asesh   Members   -  Reputation: 268

Like
0Likes
Like

Posted 21 March 2012 - 09:49 AM

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

#26 Arkanoid   Members   -  Reputation: 109

Like
0Likes
Like

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?

#27 Asesh   Members   -  Reputation: 268

Like
0Likes
Like

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

#28 Asesh   Members   -  Reputation: 268

Like
0Likes
Like

Posted 21 March 2012 - 10:47 AM

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

#29 Arkanoid   Members   -  Reputation: 109

Like
0Likes
Like

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 Posted Image , 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?

#30 Dancin_Fool   Members   -  Reputation: 611

Like
0Likes
Like

Posted 21 March 2012 - 01:28 PM

i tried maybe all...rad SDK and i don't know how to chek it Posted Image , 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?


You need to double check that you're uploading a proper world/view/projection matrix in your c++ code to your worldViewProj that is in your shader.

#31 Arkanoid   Members   -  Reputation: 109

Like
0Likes
Like

Posted 22 March 2012 - 07:50 AM

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

#32 Arkanoid   Members   -  Reputation: 109

Like
0Likes
Like

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?

#33 Asesh   Members   -  Reputation: 268

Like
0Likes
Like

Posted 22 March 2012 - 10:04 AM

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

#34 Arkanoid   Members   -  Reputation: 109

Like
0Likes
Like

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++ )
{
g_bUseShaders = true;

if( g_bUseShaders == true )
{
//
// 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_pd3dDevice->SetVertexShader( g_pVertexShader );


g_pd3dDevice->SetPixelShader( g_pPixelShader );



g_pMesh[b]->DrawSubset( i );
}
i update all, why shader cannot see coordinates?

#35 Dancin_Fool   Members   -  Reputation: 611

Like
0Likes
Like

Posted 23 March 2012 - 01:50 PM

First off, you aren't uploading your world matrix or your light direction, you're only uploading your matWorldViewProj.

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.

#36 Arkanoid   Members   -  Reputation: 109

Like
0Likes
Like

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?

#37 Asesh   Members   -  Reputation: 268

Like
0Likes
Like

Posted 25 March 2012 - 06:48 AM

Use NVIDIA texture tools: http://developer.nvidia.com/nvidia-texture-tools-adobe-photoshop to generate a normal map of your mesh's texture and modify your shader to add support for normal mapping

#38 Arkanoid   Members   -  Reputation: 109

Like
0Likes
Like

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?

#39 Asesh   Members   -  Reputation: 268

Like
0Likes
Like

Posted 26 March 2012 - 10:01 AM

learn to google :P, google direct3d 9 normal mapping




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.



PARTNERS