• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Arkanoid

Problem with compile shader from file

38 posts in this topic

Hi,

i wanna to add to my project shaders, but always have a problem here:[CODE]

hr =D3DXCompileShaderFromFile( L"vertex.vsh", NULL, NULL,
"main", D3DXGetVertexShaderProfile(g_pd3dDevice),dwFlags, &Code, &BufferErrors,
&ConstantTable )

[/CODE]
i cannot understand why? here is the part of my shader code:
[CODE]
LPDIRECT3DVERTEXDECLARATION9 VertexDeclaration = NULL;
g_pd3dDevice->CreateVertexDeclaration( declaration, &VertexDeclaration );

g_pd3dDevice->SetVertexDeclaration( VertexDeclaration );
HRESULT hr;
DWORD dwFlags = 0;
dwFlags |= D3DXSHADER_SKIPOPTIMIZATION;
hr =D3DXCompileShaderFromFile( L"vertex.vsh", NULL, NULL,
"main", D3DXGetVertexShaderProfile(g_pd3dDevice),dwFlags, &Code, &BufferErrors,
&ConstantTable );
if(FAILED(hr))
{
MessageBox( NULL, LPCWSTR(BufferErrors), L"Meshes.exe", MB_OK );
}

g_pd3dDevice->CreateVertexShader( (DWORD*)Code->GetBufferPointer(),&VertexShader );[/CODE]
0

Share this post


Link to post
Share on other sites
[left]did you mean [color=#000000][size=2]D3DXCompileShaderFromFile[/size][/color] fails? you can see what went wrong by calling: ::OutputDebugString(reinterpret_cast<WCHAR *>([color=#660066][size=2]BufferErrors->GetBufferPointer()));[/size][/color][/left]
0

Share this post


Link to post
Share on other sites
[CODE]if(FAILED(hr))
{
::OutputDebugString(reinterpret_cast<WCHAR *>(BufferErrors->GetBufferPointer()));
}[/CODE]like that?...no it didn't show anything...

or like this:
[CODE]if(FAILED(hr))
{
//::OutputDebugString(reinterpret_cast<WCHAR *>(BufferErrors->GetBufferPointer()));
MessageBox( NULL,reinterpret_cast<WCHAR *>(BufferErrors->GetBufferPointer()), L"Meshes.exe", MB_OK );
}[/CODE]then it shows me many ?hinese characters...i cannot understand ?hinese....
0

Share this post


Link to post
Share on other sites
oops, replace WCHAR with char. BTW OutputDebugString will output that data to the Visual Studio output window not in your app
0

Share this post


Link to post
Share on other sites
you better use shader shader compiler (fxc) to compile that shader/to find errors in your shader
0

Share this post


Link to post
Share on other sites
oh...sorry can you please say more correctly what function i need to use? And how can i using it understand what error i have?
0

Share this post


Link to post
Share on other sites
[img]http://s15.radikal.ru/i188/1203/51/964b3f33308d.jpg[/img]
i cannot read it)...i don't know how to see message in English.
0

Share this post


Link to post
Share on other sites
[img]http://s019.radikal.ru/i627/1203/b7/9fca6430a47c.jpg[/img]


I changed, here is all errors maybe...
0

Share this post


Link to post
Share on other sites
Well, now fix those errors...looking at those errors, seems like it's very easy to fix them
0

Share this post


Link to post
Share on other sites
[quote name='Asesh' timestamp='1331829981' post='4922313']
Well, now fix those errors...looking at those errors, seems like it's very easy to fix them
[/quote]
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.
0

Share this post


Link to post
Share on other sites
Use PIX to find out what's wrong. It's part of the SDK. Here are some D3D 9 samples: [url="http://www.codesampler.com/dx9src.htm"]http://www.codesampler.com/dx9src.htm[/url] try using effect framework instead, since it will be very easy to use both vertex and pixel shaders
0

Share this post


Link to post
Share on other sites
I understand where can be the problem...in all samples vertexes have special format:
[CODE]struct Vertex
{
float x, y, z;
DWORD color;
float tu, tv;

enum FVF
{
FVF_Flags = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1
};
};[/CODE]
but i use .X model and i what vertexes i need to use? For example:
[CODE]g_pd3dDevice->SetFVF( Vertex::FVF_Flags );
g_pd3dDevice->SetStreamSource( 0, g_pVertexBuffer, 0,sizeof(Vertex) );[/CODE]
i don't know where i can find Vertex of my mesh...and how can i change it.
0

Share this post


Link to post
Share on other sites
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: [url="http://d3dcoder.net/d3d9c.htm"]http://d3dcoder.net/d3d9c.htm[/url] you can download source code from that page and scroll down to see the output
0

Share this post


Link to post
Share on other sites
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:
[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();
}[/CODE]

than to render:
[CODE]for(int b =1;b<MeshCount+1;b++)
{
for( DWORD i = 0; i < g_dwNumMaterials[b]; 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[b]);
// Draw the mesh subset

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

g_pd3dDevice->SetMaterial( &entity[b].g_pMeshMaterials[i] );
g_pd3dDevice->SetTexture( 0,entity[b].g_pMeshTextures[i] );

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

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?
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
...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?[img]http://public.gamedev.net//public/style_emoticons/default/wacko.png[/img]
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
I find only one problem:
[img]http://s019.radikal.ru/i605/1203/2a/cfae492ce2e9.jpg[/img]
before VS all vertexes have different position
[img]http://s019.radikal.ru/i607/1203/39/2500eb7f542f.jpg[/img]
and after VS all 0...so how to fix it?
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
[CODE]
//
// 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
[/CODE]
if i understand correctly this is 0 vertex debug.
and Registry:
[CODE]c4 (1.000,0.000,0.000,0.000) float4
v0 (909.163,59.139,-1585.124,1.000) float4[/CODE]
and what is wrong? I can post my VS too.
0

Share this post


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

Share this post


Link to post
Share on other sites
Rather than waiting for someone to reply goto gamedev chat room: [url="http://www.gamedev.net/community/chat"][color=#009933][font=arial, sans-serif][size=1]www.[/size][/font][/color][b]gamedev[/b][color=#009933][font=arial, sans-serif][size=1].net/community/[/size][/font][/color][b]chat[/b][/url]
0

Share this post


Link to post

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  
Followers 0