Sign in to follow this  
Arkanoid

Problem with compile shader from file

Recommended Posts

Asesh    276
Rather than waiting for someone to reply goto gamedev chat room: [url="http://www.gamedev.net/community/chat"]http://www.gamedev.net/community/chat[/url]

Share this post


Link to post
Share on other sites
Arkanoid    109
well i asked there and sb tell me that i can multiply anything by a zero matrix and tend to get null vectors.
...[CODE]

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;
}
[/CODE]
its my shader code...where can i multiply by a zero here?

Share this post


Link to post
Share on other sites
Asesh    276
well, use PIX to check the value of [color=#000000][size=2][left]worldViewProj [/left][/size][/color]in your shader. Am sure that matrix is not being updated in the shader from external source

Share this post


Link to post
Share on other sites
Arkanoid    109
[quote name='Asesh' timestamp='1332348275' post='4923989']
well, use PIX to check the value of
[/quote]
i tried maybe all...rad SDK and i don't know how to chek it [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img] , 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?

Share this post


Link to post
Share on other sites
Dancin_Fool    785
[quote name='Arkanoid' timestamp='1332357898' post='4924060']
i tried maybe all...rad SDK and i don't know how to chek it [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img] , 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?
[/quote]

You need to double check that you're uploading a proper world/view/projection matrix in your c++ code to your [color="#000000"]worldViewProj that is in your shader.[/color]

Share this post


Link to post
Share on other sites
Arkanoid    109
but how i can give my shader other variables? like this:
[CODE]float4x4 matWorld;
float4 vec_light;[/CODE]

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?

Share this post


Link to post
Share on other sites
Arkanoid    109
well for example:
[CODE]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;
}[/CODE]
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:
[CODE]

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 );
}
[/CODE]i update all, why shader cannot see coordinates?

Share this post


Link to post
Share on other sites
Dancin_Fool    785
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.

Share this post


Link to post
Share on other sites
Arkanoid    109
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?

Share this post


Link to post
Share on other sites
Asesh    276
Use NVIDIA texture tools: [url="http://developer.nvidia.com/nvidia-texture-tools-adobe-photoshop"]http://developer.nvidia.com/nvidia-texture-tools-adobe-photoshop[/url] to generate a normal map of your mesh's texture and modify your shader to add support for normal mapping

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this