Problem with compile shader from file

Started by
37 comments, last by Asesh 12 years, 1 month ago
9fca6430a47c.jpg


I changed, here is all errors maybe...
Advertisement
Well, now fix those errors...looking at those errors, seems like it's very easy to fix them

Well, now fix those errors...looking at those errors, seems like it's very easy to fix them

haha...but...i understand that the error was in shader code - this mas the main that i wanted to understand...

Now situation is better but - models don't render...i tried many shader examples code - and with all them model don't render...where can be the problem?
Have sb 100% working vertex-shader code? I'll try it in my program to understand where is the problem - in shader or in code.
Use PIX to find out what's wrong. It's part of the SDK. Here are some D3D 9 samples: http://www.codesampler.com/dx9src.htm try using effect framework instead, since it will be very easy to use both vertex and pixel shaders
I understand where can be the problem...in all samples vertexes have special format:
struct Vertex
{
float x, y, z;
DWORD color;
float tu, tv;

enum FVF
{
FVF_Flags = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1
};
};

but i use .X model and i what vertexes i need to use? For example:
g_pd3dDevice->SetFVF( Vertex::FVF_Flags );
g_pd3dDevice->SetStreamSource( 0, g_pVertexBuffer, 0,sizeof(Vertex) );

i don't know where i can find Vertex of my mesh...and how can i change it.
You are mixing shaders and fixed function pipeline. Those FVFs should be replaced with vertex declarations. But since you are using x file you don't have to do that. Just went through my old D3D 9 code and seems like simply setting x file's corresponding texture and then calling DrawSubset would suffice. Like I said, try using effect frame instead. For reference:
Frank Luna's Dx 9.0c a shader approach: http://d3dcoder.net/d3d9c.htm you can download source code from that page and scroll down to see the output
hm...i downloaded this sample:
Simple Vertex & Pixel Shader (HLSL)
from here: http://www.codesampler.com/dx9src/dx9src_8.htm#dx9_hlsl_fx_simple
cause it works....i tryed to add it to my code:
void initShader( void )
{
//
// Create a test texture for our effect to use...
//

//D3DXCreateTextureFromFile( g_pd3dDevice, "test.bmp", &g_pTexture );

//
// Create a HLSL based vertex shader.
//

//
// If your program uses explicit binding semantics (like this one),
// you can create a vertex declaration using those semantics.
//

D3DVERTEXELEMENT9 declaration[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
{ 0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
D3DDECL_END()
};

g_pd3dDevice->CreateVertexDeclaration( declaration, &g_pVertexDeclaration );

HRESULT hr;
LPD3DXBUFFER pCode;
DWORD dwShaderFlags = 0;
LPD3DXBUFFER pBufferErrors = NULL;

// Assemble the vertex shader from the file
hr = D3DXCompileShaderFromFile( "vertex_shader.vsh", NULL, NULL, "main",
"vs_2_0", dwShaderFlags, &pCode,
&pBufferErrors, &g_pConstantTableVS );

if( FAILED(hr) )
{
LPVOID pCompilErrors = pBufferErrors->GetBufferPointer();
MessageBox(NULL, (const char*)pCompilErrors, "Vertex Shader Compile Error",
MB_OK|MB_ICONEXCLAMATION);
}

// Create the vertex shader
g_pd3dDevice->CreateVertexShader( (DWORD*)pCode->GetBufferPointer(),
&g_pVertexShader );
pCode->Release();

//
// Create a HLSL based pixel shader.
//

// Assemble the vertex shader from the file
hr = D3DXCompileShaderFromFile( "pixel_shader.psh", NULL, NULL, "main",
"ps_2_0", dwShaderFlags, &pCode,
&pBufferErrors, &g_pConstantTablePS );

if( FAILED(hr) )
{
LPVOID pCompilErrors = pBufferErrors->GetBufferPointer();
MessageBox(NULL, (const char*)pCompilErrors, "Pixel Shader Compile Error",
MB_OK|MB_ICONEXCLAMATION);
}

// Create the vertex shader
g_pd3dDevice->CreatePixelShader( (DWORD*)pCode->GetBufferPointer(),
&g_pPixelShader );
pCode->Release();
}


than to render:
for(int b =1;b<MeshCount+1;b++)
{
for( DWORD i = 0; i < g_dwNumMaterials; i++ )
{
if( g_bUseShaders == true )
{
//
// Use vertex and pixel shaders...
//

D3DXMATRIX worldViewProjection = matWorld * matView * g_matProj;
g_pConstantTableVS->SetMatrix( g_pd3dDevice, "worldViewProj", &worldViewProjection );

g_pd3dDevice->SetVertexDeclaration( g_pVertexDeclaration );
g_pd3dDevice->SetVertexShader( g_pVertexShader );

// Set the material and texture for this subset

// shiftTextureCoordinates(g_pMesh);
// Draw the mesh subset

//g_pd3dDevice->SetTexture(0, g_baseTexture);
g_pd3dDevice->SetPixelShader( g_pPixelShader );

g_pd3dDevice->SetMaterial( &entity.g_pMeshMaterials );
g_pd3dDevice->SetTexture( 0,entity.g_pMeshTextures );

g_pMesh->DrawSubset( i );
}
}


in sample everything works, in my program mesh doesn't draw. I don't think that i'll find better code than this one...what i missed?
Use PIX to find out what's going on, like I said it's part of the SDK. You can use PIX to see what happened before vertex shader and after vertex shader and debug your vertex/pixel shader too
...how? PIX show me all frames but i Draw my mesh after i set up shader....and what shoud i see? I can see only all commands. I know witch command
is problem here:
g_pd3dDevice->SetPixelShader( g_pPixelShader );
or
g_pd3dDevice->SetVertexShader( g_pVertexShader );
I know this without PIX...everything that i see is clean screen in all frames in PIX. How can i see what i need?wacko.png
Run your app via PIX by choosing single frame capture option, then capture a frame by hitting F12 button. Now in the events panel choose a frame. Now to debug vertex shader you have to locate draw call, so locate that Draw* call then goto Mesh tab, there you can see what's happening to your primitive in pre VS and post VS stages and can debug your vertex shader too

This topic is closed to new replies.

Advertisement