|
dev.gamez.lv Latvian Game Developers Community
|
View previous topic :: View next topic |
Author |
Message |
dawchiks
Joined: 03 Jan 2007 Posts: 37 Location: Rīga
|
Posted: Mon Feb 12, 2007 7:37 pm Post subject: |
|
nu tas ir pof vai ir pixel shaderis man, tapat viss melns, draiveris man ir jaunaakais,
fx composeraa jau visi sampli iet, bet neiet ar manu exe |
|
Back to top |
|
|
anggelus
Joined: 23 Feb 2005 Posts: 383 Location: Rīga (LV)
|
Posted: Mon Feb 12, 2007 7:42 pm Post subject: |
|
atsuti to savu fignu man uz emailu _________________ No comprendo lo que dice. |
|
Back to top |
|
|
dawchiks
Joined: 03 Jan 2007 Posts: 37 Location: Rīga
|
Posted: Mon Feb 12, 2007 9:26 pm Post subject: |
|
es te pat ielikshu
pats kods -
Code: |
#include <windows.h>
#include <mmsystem.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <strsafe.h>
#define HEIGHT 768
#define WIDTH 1024
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")
LPDIRECT3D9 g_pd3d;
LPDIRECT3DDEVICE9 g_pd3dDevice;
LPDIRECT3DSURFACE9 z_buffer = NULL;
LPD3DXEFFECT g_pEffect = NULL;
LPD3DXMESH g_pMesh;
LPDIRECT3DTEXTURE9* g_pTex = NULL;
D3DMATERIAL9* g_pMat = NULL;
DWORD g_pNumMat = 0L;
D3DXMATRIX matView;
D3DXMATRIX matWorld;
D3DXMATRIXA16 matProj;
UINT uPasses;
void Objekti()
{
LPD3DXBUFFER g_pBuffer;
if(FAILED(D3DXLoadMeshFromX("model.x",D3DXMESH_SYSTEMMEM,g_pd3dDevice,NULL,&g_pBuffer,NULL,&g_pNumMat,&g_pMesh)))
{
MessageBox(NULL,"Cant find model.x!","Error",MB_OK);
}
D3DXMATERIAL* D3DXMaterials = (D3DXMATERIAL*)g_pBuffer->GetBufferPointer();
g_pMat = new D3DMATERIAL9[g_pNumMat];
g_pTex = new LPDIRECT3DTEXTURE9[g_pNumMat];
for(DWORD i=0;i<g_pNumMat;i++)
{
g_pMat[i] = D3DXMaterials[i].MatD3D;
g_pMat[i].Ambient = g_pMat[i].Diffuse;
g_pTex = NULL;
if(D3DXMaterials[i].pTextureFilename != NULL && lstrlen(D3DXMaterials[i].pTextureFilename) > 0)
{
if(FAILED(D3DXCreateTextureFromFile(g_pd3dDevice,D3DXMaterials[i].pTextureFilename,&g_pTex[i])))
MessageBox(NULL,"Cannot find texture!","Error!",MB_OK);
}
}
g_pBuffer->Release();
}
void gaisma() //sito es nelietoju, pagaidaam
{
D3DMATERIAL9 mat;
ZeroMemory(&mat,sizeof(mat));
mat.Diffuse.r = mat.Ambient.r = 1.0f;
mat.Diffuse.g = mat.Ambient.g = 1.0f;
mat.Diffuse.b = mat.Ambient.b = 1.0f;
mat.Diffuse.a = mat.Ambient.a = 1.0f;
g_pd3dDevice->SetMaterial(&mat);
D3DLIGHT9 light;
D3DXVECTOR3 vLightDir(2.0f,-4.0f,-2.0f);
ZeroMemory(&light,sizeof(light));
light.Type = D3DLIGHT_DIRECTIONAL;
light.Diffuse.r = 0.5f;
light.Diffuse.g = 0.5f;
light.Diffuse.b = 0.5f;
light.Diffuse.a = 0.5f;
light.Direction = vLightDir;
light.Range = 200.0f;
g_pd3dDevice->SetLight(0,&light);
g_pd3dDevice->LightEnable(0,TRUE);
}
HRESULT InitD3D(HWND hWnd)
{
g_pd3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp,sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.BackBufferWidth = WIDTH;
d3dpp.BackBufferHeight = HEIGHT;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
g_pd3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&g_pd3dDevice);
//g_pd3dDevice->SetRenderState(D3DRS_LIGHTING,TRUE);
//g_pd3dDevice->SetRenderState(D3DRS_AMBIENT,D3DCOLOR_XRGB(50,50,50));
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE,TRUE);
return S_OK;
}
void effekts(void)
{
HRESULT error;
LPD3DXBUFFER pBufferErrors = NULL;
error = D3DXCreateEffectFromFile(g_pd3dDevice,"shader.fx",NULL,NULL,NULL,0,&g_pEffect,&pBufferErrors);
if(FAILED(error))
{
LPVOID pCompileErrors = pBufferErrors->GetBufferPointer();
MessageBox(NULL,(const char*)pBufferErrors,"Errors ieladejot shaderi",MB_OK);
}
g_pEffect->SetMatrix("matWVP",&matView);
}
void kamera()
{
D3DXVECTOR3 vEyePt(0.0f,3.0f,-6.0f);
D3DXVECTOR3 vLookAt(0.0f,0.0f,0.0f);
D3DXVECTOR3 vUpVec(0.0f,1.0f,0.0f);
D3DXMatrixLookAtLH(&matView,&vEyePt,&vLookAt,&vUpVec);
g_pd3dDevice->SetTransform(D3DTS_VIEW,&matView); D3DXMatrixPerspectiveFovLH(&matProj,D3DX_PI/4,1.33333333f,1.0f,144.0f);
g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);
}
void Cleanup()
{
if(g_pMat !=NULL)
delete[] g_pMat;
g_pMesh->Release();
g_pd3d->Release();
g_pd3dDevice->Release();
}
void Render()
{
g_pd3dDevice->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,10),1.0f,0);
if(SUCCEEDED(g_pd3dDevice->BeginScene()))
{
g_pEffect->SetTechnique("textured");
g_pEffect->Begin(&uPasses,0);
for(UINT uPass = 0;uPass<uPasses;++uPass)
{
g_pEffect->BeginPass(uPass);
g_pMesh->DrawSubset(0);
g_pEffect->EndPass();
}
g_pEffect->End();
g_pd3dDevice->EndScene();
}
g_pd3dDevice->Present(NULL,NULL,NULL,NULL);
}
LRESULT WINAPI MsgProc(HWND hWnd,UINT msg, WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_KEYDOWN:
{
switch(wParam)
{
case VK_ESCAPE:
Cleanup();
PostQuitMessage(0);
return 0;
}
}
}
return DefWindowProc(hWnd,msg,wParam,lParam);
}
INT WINAPI WinMain(HINSTANCE hInst,HINSTANCE,LPSTR,INT)
{
WNDCLASSEX wc = {sizeof(WNDCLASSEX),CS_CLASSDC,MsgProc,0L,0L,GetModuleHandle(NULL),NULL,NULL,NULL,NULL,"D3D",NULL};
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
RegisterClassEx (&wc);
HWND hWnd = CreateWindow("D3D","Project Research",WS_EX_TOPMOST|WS_POPUP,0,0,WIDTH,HEIGHT,NULL,NULL,wc.hInstance,NULL);
if(SUCCEEDED(InitD3D(hWnd)))
{
kamera();
//gaisma(); // atsleedzu jo lietoju shaaderi
Objekti();
effekts();
ShowWindow(hWnd,SW_SHOWDEFAULT);
UpdateWindow(hWnd);
MSG msg;
ZeroMemory(&msg,sizeof(msg));
while(msg.message!=WM_QUIT)
{
if(PeekMessage(&msg,NULL,0U,0U,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
Render();
}
}
UnregisterClass("D3D",wc.hInstance);
return 0;
} |
un shaaderis-
oj shaaderis nestraadaa pat samplee..... šas samekleeshu kaadu citu |
|
Back to top |
|
|
anggelus
Joined: 23 Feb 2005 Posts: 383 Location: Rīga (LV)
|
Posted: Mon Feb 12, 2007 10:28 pm Post subject: |
|
nu blin caliit tu vispar izlasiiji to pamaaciibu no indago??
tur tac rakstiits arii par matricaam un kaadas kur ir jaauzstaada
tev piemeeraa vispaar seiderim WorldViewProj matricas vietaa tiekpadota View matrica
logiski ka neko neraadiis
DX dokumentaacijaa arii var palasiit par transformaacijaam telpaa un koordinaasu sistemu.
Tie jau ir pasi pamati, ja nesapratisi kaa tas darbojaas, tad turpmakais iz tuksa laika izskiesana.
Code: |
void Render()
{
g_pd3dDevice->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,255),1.0f,0);
D3DXMATRIX matWorld, matWVP;
D3DXMatrixIdentity(&matWorld);
g_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld);
kamera();
matWVP = matWorld*matView*matProj;
if(SUCCEEDED(g_pd3dDevice->BeginScene()))
{
g_pEffect->SetMatrix("matWVP",&matWVP);
g_pEffect->SetTechnique("textured"); |
_________________ No comprendo lo que dice. |
|
Back to top |
|
|
dawchiks
Joined: 03 Jan 2007 Posts: 37 Location: Rīga
|
Posted: Mon Feb 12, 2007 10:42 pm Post subject: |
|
vispaar es izlasiiju visu(gandriiz) pamaaciibu no indago, arii dx dokumentaaciju esmu paarlasiijis vairaakas reizes, bet tur jau tas prikols, ka neiet.
i to es shaaderi var ielaadeet tikai tad ja nokomenteeju PixelShader = compile ps_1_1 PS(); savaadaak man izmet erroru. |
|
Back to top |
|
|
anggelus
Joined: 23 Feb 2005 Posts: 383 Location: Rīga (LV)
|
Posted: Mon Feb 12, 2007 10:45 pm Post subject: |
|
pievieno taas paaris rindinas kodaa, kaa manaa iepriekseejaa postaatad viss ies. pats parbaudiju viss straadaa. _________________ No comprendo lo que dice. |
|
Back to top |
|
|
dawchiks
Joined: 03 Jan 2007 Posts: 37 Location: Rīga
|
Posted: Mon Feb 12, 2007 10:48 pm Post subject: |
|
ja godiigi es pievienoju, bet man neiet, iedo moska savu shaadera kodu? |
|
Back to top |
|
|
anggelus
Joined: 23 Feb 2005 Posts: 383 Location: Rīga (LV)
|
Posted: Mon Feb 12, 2007 10:55 pm Post subject: |
|
shaders arii ir tas pats taveejais ko tu te biji iepostojis
un veel
g_pMesh->DrawSubset(0);
noziimee ka tu rendereesi tikai pirmo modelja subsetu, ja tas subsets ir viens mazinsh poligons tad iespeejams arii vins nav redzams tev
pamegini kaadu modeli no dxsdk, piemeeram airplane2.x _________________ No comprendo lo que dice. |
|
Back to top |
|
|
dawchiks
Joined: 03 Jan 2007 Posts: 37 Location: Rīga
|
Posted: Mon Feb 12, 2007 11:00 pm Post subject: |
|
da nee ar objektu viss ir ok, tas ir "teapot", no 3ds max exporteeju, prikola peec, tekstuuras gan vinam nav, bet taapat viss ok, vins ir pietiekami liels. un ja kas man nav vairs taa shader koda...
aa nee ir gan...
W00000T iet . bet taapat veel nav atrisinaata probleema par pixelShader, jo taapat kaa es ja vienalga kaadaa shaaderii ir pixelshader = compile ps_1_1 ps(); tad mans .exe man met aaraa erroru, ja es nokomenteeju pixelShader, tad var ielaadeet jebkuru shaderi.
vai shaadam shaaaderim vajadzeetu straadaat?
Code: |
float4x4 matWVP;
//--------------------------------------------------------------------------------------
// Vertex shader output structure
//--------------------------------------------------------------------------------------
struct VS_OUTPUT
{
float4 Position : POSITION; // vertex position
};
struct VS_IN
{
float4 Position : POSITION;
};
//--------------------------------------------------------------------------------------
// Ambient shaders
//--------------------------------------------------------------------------------------
VS_OUTPUT AmbientVS( VS_IN In ) {
VS_OUTPUT Out = (VS_OUTPUT) 0;
Out.Position = mul(In.Position, matWVP); // transformējam Pozīciju
return Out;
}
float4 AmbientPS() : COLOR {
float4 Acolor = {1.0, 0.15, 0.15, 1.0};
float Aintensity = 0.5;
return Aintensity * Acolor;
}
technique textured
{
pass P0
{
VertexShader = compile vs_1_1 AmbientVS();
//PixelShader = compile ps_1_4 AmbientPS(); // JA ES //ATKOMENTEEJU TAD IZMET ERROR
}
}
} |
ja es atkomenteeju tad izmet error, ja palieko nokomenteets tad mans objekts ir prosta balts.
jeee nigas... lol,. kad nomainiiju PixelShader = compile ps_1_1 PS(); uz PixelShader = compile ps_2_0 PS(); tad iet... ir kraasa.... |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|