[headshake]failed using a vertex shader to render my scene..

Started by
8 comments, last by kauna 13 years, 4 months ago
[headshake][headshake][headshake][headshake]
Hey guys,
I'm trying to render my scene using a vertex shader,to generate DIFFUSE lighting..
//vertex shadermatrix mat;vector lightPos;struct VS_INPUT{	vector position:POSITION;	vector normal:NORMAL;	float2 tex:TEXCOORD;};struct VS_OUTPUT{    vector position:POSITION;	vector color:COLOR;	float2 tex:TEXCOORD;};VS_OUTPUT VS(VS_INPUT input){    VS_OUTPUT output=(VS_OUTPUT)0;	output.position=mul(input.position,mat);    output.color = saturate(dot(lightPos, input.normal));    output.tex=input.tex;		return output;}

and here is my main program,which renders a house and a role.
#include <windows.h>#include <windowsx.h>#include <d3d9.h>#include "SkinMesh.h"#include "Mesh.h"#include "Camera.h"// include the Direct3D Library file#pragma comment (lib, "d3d9.lib")// global declarationsLPDIRECT3D9 d3d;    // the pointer to our Direct3D interfaceLPDIRECT3DDEVICE9 d3ddev;    // the pointer to the device classCSkinMesh *Role;Mesh *House;CFPCamera *camera;IDirect3DVertexShader9 *shader=NULL;ID3DXConstantTable *constTable=NULL;D3DXHANDLE matHandle;D3DXHANDLE lightPosHANDLE;float m_x=0.0f;float m_y1=-3.0f;float m_y2=2.0f;float m_z1=4.5;float m_z2=0.0f;bool moveable=TRUE;bool Eattack=FALSE;// function prototypesvoid initD3D(HWND hWnd);    // sets up and initializes Direct3Dvoid render_frame(void);    // renders a single framevoid cleanD3D(void);    // closes Direct3D and releases memoryvoid initLight(void);void initRole(void);void initHouse(void);void initCamera(void);BOOL hitTest(ID3DXMesh* pMesh,			 float XStart,float YStart,float ZStart,			 float XEnd,float YEnd,float ZEnd,float *Distance);float GetClosestHeight(ID3DXMesh* pMesh,float XPos,float YPos,float ZPos);float GetHeightAbove(ID3DXMesh* pMesh,float XPos,float YPos,float ZPos);float GetHeightBelow(ID3DXMesh* pMesh,float XPos,float YPos,float ZPos);// the WindowProc function prototypeLRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);// the entry point for any Windows programint WINAPI WinMain(HINSTANCE hInstance,                   HINSTANCE hPrevInstance,                   LPSTR lpCmdLine,                   int nCmdShow){    HWND hWnd;    WNDCLASSEX wc;    ZeroMemory(&wc, sizeof(WNDCLASSEX));    wc.cbSize = sizeof(WNDCLASSEX);    wc.style = CS_HREDRAW | CS_VREDRAW;    wc.lpfnWndProc = WindowProc;    wc.hInstance = hInstance;	wc.hCursor = LoadCursor(NULL, IDC_ARROW);    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;    wc.lpszClassName = "WindowClass";    RegisterClassEx(&wc);    hWnd = CreateWindowEx(NULL,                          "WindowClass",                          "&#30896;&#26816;&#23454;&#20363;-D3DXIntersect()",                          WS_OVERLAPPEDWINDOW,                          0, 0,                          1366, 768,                          NULL,                          NULL,                          hInstance,                          NULL);    ShowWindow(hWnd, nCmdShow);    // set up and initialize Direct3D    initD3D(hWnd);	initLight();    initRole();	initHouse();	    // enter the main loop:    MSG msg;    while(TRUE)    {        while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))        {            TranslateMessage(&msg);            DispatchMessage(&msg);        }        if(msg.message == WM_QUIT)            break;        render_frame();    }    // clean up DirectX and COM    cleanD3D();    return msg.wParam;}// this is the main message handler for the programLRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){    switch(message)    {        case WM_DESTROY:            {                PostQuitMessage(0);                return 0;            } break;    }    return DefWindowProc (hWnd, message, wParam, lParam);}// this function initializes and prepares Direct3D for usevoid initD3D(HWND hWnd){    d3d = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface    D3DPRESENT_PARAMETERS d3dpp;    // create a struct to hold various device information    ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use    d3dpp.Windowed = TRUE;    // program windowed, not fullscreen    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames    d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D    d3dpp.EnableAutoDepthStencil=TRUE;	d3dpp.AutoDepthStencilFormat=D3DFMT_D16;    // create a device class using this information and the info from the d3dpp stuct    d3d->CreateDevice(D3DADAPTER_DEFAULT,                      D3DDEVTYPE_HAL,                      hWnd,                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,                      &d3dpp,                      &d3ddev);	    ID3DXBuffer* shaderBuf=NULL;	ID3DXBuffer* errorBuf=NULL;        D3DXCompileShaderFromFile("HLSL.txt",		NULL,		NULL,		"VS",		"vs_1_1",		D3DXSHADER_DEBUG,		&shaderBuf,		&errorBuf,		&constTable);	if(errorBuf){		MessageBox(NULL,			(char*)errorBuf->GetBufferPointer(),			(char*)errorBuf->GetBufferSize(),			MB_OK);	}	d3ddev->CreateVertexShader((DWORD*)shaderBuf->GetBufferPointer(),		&shader);	matHandle=constTable->GetConstantByName(0,"mat");	lightPosHANDLE=constTable->GetConstantByName(0,"lightPos");	constTable->SetDefaults(d3ddev);	d3ddev->SetRenderState(D3DRS_LIGHTING,FALSE);	d3ddev->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE );	d3ddev->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );    d3ddev->SetRenderState(D3DRS_ANTIALIASEDLINEENABLE,TRUE);	d3ddev->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS,TRUE);	d3ddev->SetSamplerState(0,D3DSAMP_MAGFILTER,D3DTEXF_LINEAR);				//&#32447;&#24615;&#36807;&#28388;&#26041;&#24335;	d3ddev->SetSamplerState(0,D3DSAMP_MINFILTER,D3DTEXF_LINEAR);				//&#32447;&#24615;&#36807;&#28388;&#26041;&#24335;	d3ddev->SetSamplerState(0,D3DSAMP_MIPFILTER,D3DTEXF_LINEAR);				//&#32447;&#24615;&#36807;&#28388;&#26041;&#24335;	}        // this is the function used to render a single framevoid render_frame(void){    // clear the window to a deep blue    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 255, 255), 1.0f, NULL);    d3ddev->BeginScene();    // begins the 3D scene    // Set up our view matrix. A view matrix can be defined given an eye point,    // a point to lookat, and a direction for which way is up. Here, we set the    // eye five units back along the z-axis and up three units, look at the     // origin, and define "up" to be in the y-direction.    D3DXVECTOR3 vEyePt( m_x, m_z1,m_y1 );    D3DXVECTOR3 vLookatPt( m_x, m_z2, m_y2 );    D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );    D3DXMATRIXA16 matView;    D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );    d3ddev->SetTransform( D3DTS_VIEW, &matView );    // For the projection matrix, we set up a perspective transform (which    // transforms geometry from 3D view space to 2D viewport space, with    // a perspective divide making objects smaller in the distance). To build    // a perpsective transform, we need the field of view (1/4 pi is common),    // the aspect ratio, and the near and far clipping planes (which define at    // what distances geometry should be no longer be rendered).    D3DXMATRIXA16 matProj;    D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );    d3ddev->SetTransform( D3DTS_PROJECTION, &matProj );	D3DXMATRIX matVS;	D3DXMATRIX matVieww,matWorldd,matProjj;	d3ddev->GetTransform(D3DTS_VIEW,&matVieww);	d3ddev->GetTransform(D3DTS_WORLD,&matWorldd);	d3ddev->GetTransform(D3DTS_PROJECTION,&matProjj);	matVS=matVieww*matWorldd*matProjj;    constTable->SetMatrix(d3ddev,matHandle,&matVS);    D3DXVECTOR4 lightPos;	lightPos=D3DXVECTOR4(1.0f,1.0f,1.0f,0.0f);    constTable->SetVector(d3ddev,lightPosHANDLE,&lightPos);	d3ddev->SetVertexShader(shader);    Role->Render(0.025f);     House->render();	    // do 3D rendering on the back buffer here	if(::GetAsyncKeyState(VK_UP)&0x8000f){		if(moveable){				float YPos=GetClosestHeight(House->GetMesh(),			0.0f,			-1.0f,			0.0f);        Role->SetAltitude(YPos);    if(hitTest(House->pMesh,Role->GetPosition()->x,1.0f, Role->GetPosition()->z,                      (float)cos(Role->m_fAngle), 1.0f, (float)sin(Role->m_fAngle),                      NULL) == TRUE) {	     //&#21457;&#29983;&#20102;&#30896;&#25758;&#65292;&#35282;&#33394;&#20498;&#36864;		  Role->Back();              }		  			else {		Role->m_fElapsedTime=0;			Role->SetAnimationIndex(3);	    Role->WalkFoward(0.05f);        m_y1=-4.0f+Role->GetPosition()->z;    	m_y2=1.0f+Role->GetPosition()->z;		m_x=Role->GetPosition()->x;			}		}	}	else{		moveable=TRUE;		Role->SetAnimationIndex(4);	}		if(::GetAsyncKeyState(VK_UP)&::GetAsyncKeyState(VK_SHIFT)&0x8000f){		if(moveable){		Role->m_fElapsedTime=0;			Role->SetAnimationIndex(2);	    Role->WalkFoward(0.08f);        m_y1=-4.0f+Role->GetPosition()->z;    	m_y2=1.0f+Role->GetPosition()->z;  		m_x=Role->GetPosition()->x;			}	}	if(::GetAsyncKeyState(VK_LEFT)&0x8000f){		if(moveable){	    Role->Turn(-0.1f);		Role->SetAnimationIndex(3);	    m_x=Role->GetPosition()->x;		}	}	if(::GetAsyncKeyState(VK_RIGHT)&0x8000f){		if(moveable){	    Role->Turn(0.1f);		Role->SetAnimationIndex(3);		m_x=Role->GetPosition()->x;				}	}    d3ddev->EndScene();    // ends the 3D scene    d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen}void initLight(){	D3DLIGHT9 d3dLight;	ZeroMemory(&d3dLight,sizeof(D3DLIGHT9));	d3dLight.Type = D3DLIGHT_POINT;//D3DLIGHT_POINT,D3DLIGHT_SPOT	d3dLight.Range = 1000;	D3DCOLORVALUE color;	color.a = 1;	color.r = 255;	color.g = 255;	color.b = 255;	d3dLight.Position = D3DXVECTOR3(0.0f,10.0f,-20.0f);	d3dLight.Diffuse = color;	d3dLight.Falloff = 0;	d3dLight.Attenuation0 = 0;	d3dLight.Attenuation1 = 0.5;	d3dLight.Attenuation2 = 0;	d3ddev->SetLight(0,&d3dLight);	d3ddev->LightEnable(0,TRUE);}void initRole(){	Role=new CSkinMesh(d3ddev);	Role->LoadFromXFile("hero.X");	Role->SetScale(0.03f);	Role->Turn(0.0f);    Role->SetAnimationIndex(4);	Role->SetPosition(0.0f,0.0f,0.0);	    m_y1=-4.0f+Role->GetPosition()->z;	m_y2=1.0f+Role->GetPosition()->z;	m_x=Role->GetPosition()->x;}void initHouse(){    House=new Mesh("level.x",d3ddev);}void initCamera(){//&#36824;&#26410;&#23436;&#21892;}BOOL hitTest(ID3DXMesh* pMesh,			 float XStart,float YStart,float ZStart,			 float XEnd,float YEnd,float ZEnd,float *Distance)//&#30896;&#26816;{	BOOL hit;	float u,v,dist;	float XDiff,YDiff,ZDiff,Size;    DWORD FaceIndex;	D3DXVECTOR3 vecPos;	D3DXVECTOR3 vecDir;	    vecPos=D3DXVECTOR3(XStart,YStart,ZStart);	XDiff=XEnd-XStart;	YDiff=YEnd-YStart;	ZDiff=ZEnd-ZStart;	D3DXVec3Normalize(&vecDir,&D3DXVECTOR3(XDiff,YDiff,ZDiff));	    D3DXMATRIX m,m_i;	d3ddev->GetTransform(D3DTS_WORLD,&m);		D3DXMatrixInverse(&m_i,NULL,&m);	D3DXVec3TransformCoord(&vecPos,&vecPos,&m_i);	D3DXVec3TransformNormal(&vecDir,&vecDir,&m_i);	D3DXIntersect(pMesh,		&vecPos,&vecDir,		&hit,&FaceIndex,&u,&v,&dist,		NULL,NULL);	 	if(hit==TRUE){		if(dist<1.3f){			hit=TRUE;		}		else{			hit=FALSE;		}	}	return hit;}//&#30896;&#26816;&#20989;&#25968;float GetClosestHeight(ID3DXMesh* pMesh,float XPos,float YPos,float ZPos){	    D3DXVECTOR3 vecPos=D3DXVECTOR3(XPos,YPos,ZPos);	D3DXMATRIX m,m_i;	d3ddev->GetTransform(D3DTS_WORLD,&m);		D3DXMatrixInverse(&m_i,NULL,&m);	D3DXVec3TransformCoord(&vecPos,&vecPos,&m_i);	float YBelow,float YAbove;	YBelow=GetHeightBelow(pMesh,		vecPos.x,vecPos.y,vecPos.z);	YAbove=GetHeightAbove(pMesh,		vecPos.x,vecPos.y,vecPos.z);		if(fabs(YBelow-vecPos.y)<fabs(YAbove-vecPos.y))		return YBelow;	return YAbove;}float GetHeightBelow(ID3DXMesh* pMesh,float XPos,float YPos,float ZPos){	BOOL hit;	float u,v,dist;	DWORD faceIndex;		D3DXIntersect(pMesh,		&D3DXVECTOR3(XPos,YPos,ZPos),		&D3DXVECTOR3(XPos,-1.0f,ZPos),		&hit,&faceIndex,&u,&v,&dist,NULL,NULL);		if(hit==TRUE)		return YPos-dist;	return YPos;}float GetHeightAbove(ID3DXMesh* pMesh,float XPos,float YPos,float ZPos){	BOOL hit;	float u,v,dist;	DWORD faceIndex;		D3DXIntersect(pMesh,		&D3DXVECTOR3(XPos,YPos,ZPos),		&D3DXVECTOR3(XPos,1.0f,ZPos),		&hit,&faceIndex,&u,&v,&dist,NULL,NULL);		if(hit==TRUE)		return YPos+dist;	return YPos;}// this is the function that cleans up Direct3D and COMvoid cleanD3D(void){	House->free();    d3ddev->Release();    // close and release the 3D device    d3d->Release();    // close and release Direct3D}

I run the program..it's totally a SHIT[sick],The scene's white,and there's a black figure in the scene...I don't know where's wrong..probably the lightPos?
Thanks for any reply[smile][smile][smile]
Advertisement

Hi,

In my opinion, it is rather complex/impossible to determine the problem related to your program. There is just too much source code and at the end, there is still missing certain parts of the code. It is too much of work for anybody to try to debug an entire program.

If I were you, I'd look into Direct3D samples and see how things are done there.

There are something which I am quite certain that don't work in your code:

- initLight() - d3ddev->SetLight(0,&d3dLight) doesn't have any effect when using shaders

- d3ddev->GetTransform(D3DTS_WORLD,&matWorldd); You use this matrix to produce a worldviewproj matrix which you set to the shader and then you render your house and role. It doesn't make sense. I'd assume that both of them have a separate world matrices.

Cheers!
Where's your Pixelshader? Seems like you're trying to mix up FFP and Shaders and this causes the problems.
Quote:Original post by Auskennfuchs
Where's your Pixelshader? Seems like you're trying to mix up FFP and Shaders and this causes the problems.


Actually, I think it is not an error to use vertex shader and not use a pixel shader (technically, modern hardware doesn't even have a fixed function pipeline).

However, you are right that the code contain several FFP-related parts.
[imwithstupid]
The point is the matrix,i think. I used to use the vertex shader to render one object,and so I can just set up the matrix for this object and send it to the shader.But this time I want to render a skinned mesh and a house,and this take two matrixes. First,I have to set up the matrix for the role,and then render the role,then I have to set up the matrix for the house and render the house.So where should I put my shader ? How can I calculate the matrix and send it to the shader? where should I calculate it?thanks for replies...

So does it work propertly if you render only the house? I mean, do you get the output you are expecting?

To render a skinned mesh, you'll need more than just 1 world matrix and also you can't render a skinned mesh with the same vertex shader (or at least, the output won't be what you are after).

For skinned mesh, you'll need 1 matrix for each bone describing it's location. Usually the source of these matrices is animation track in the file or perhaps a rag doll physics or inverse kinematics controller etc. Also, a vertex shader for skinning is a bit longer than for rigid meshes.

Good luck!
In fact,the shader works quite well when I render only a house:
free image hosting
To render the house,I just need to set up the matrix for the house,send it to the shader and then render it.However,my problem is not the skinmesh,but to set up matrixes and render two objects both.You see,first,I have to set up the matrix for A,and use GetTransform() to get world matrix,then send it to the shader,set up,and render it.After I have to set up the matrix for B and render.So WHERE should I get the projworldview matrix and set up my shader? Also,can I still use device->GetTransform if two objects have their own matrix?
[imwithstupid]Thanks!
Quote:Original post by kauna
To render a skinned mesh, you'll need more than just 1 world matrix and also you can't render a skinned mesh with the same vertex shader (or at least, the output won't be what you are after).

For skinned mesh, you'll need 1 matrix for each bone describing it's location. Usually the source of these matrices is animation track in the file or perhaps a rag doll physics or inverse kinematics controller etc. Also, a vertex shader for skinning is a bit longer than for rigid meshes.


Uh..I still can't understand how to render a skinned mesh..I've looked into the SDK's <BasicHLSL> sample,there's only one shader used,and the code sucks hard..

//init()    V_RETURN( LoadMesh( pd3dDevice, L"tiny\\tiny.x", &g_pMesh ) );    V_RETURN( LoadMesh( pd3dDevice, L"UI\\arrow.x", &g_pArrowMesh ) );    D3DXVECTOR3* pData;     D3DXVECTOR3 vCenter;    FLOAT fObjectRadius;    V( g_pMesh->LockVertexBuffer( 0, (LPVOID*) &pData ) );    V( D3DXComputeBoundingSphere( pData, g_pMesh->GetNumVertices(), D3DXGetFVFVertexSize( g_pMesh->GetFVF() ), &vCenter, &fObjectRadius ) );    V( g_pMesh->UnlockVertexBuffer() );    D3DXMatrixTranslation( &g_mWorldFix, -vCenter.x, -vCenter.y, -vCenter.z );    D3DXMATRIXA16 m;    D3DXMatrixRotationY( &m, D3DX_PI );    g_mWorldFix *= m;    D3DXMatrixRotationX( &m, D3DX_PI / 2.0f );    g_mWorldFix *= m;    V_RETURN( CDXUTDirectionWidget::StaticOnCreateDevice( pd3dDevice ) );    for( int i=0; i<MAX_LIGHTS; i++ )        g_LightControl.SetRadius( fObjectRadius );    // Define DEBUG_VS and/or DEBUG_PS to debug vertex and/or pixel shaders with the     // shader debugger. Debugging vertex shaders requires either REF or software vertex     // processing, and debugging pixel shaders requires REF.  The     // D3DXSHADER_FORCE_*_SOFTWARE_NOOPT flag improves the debug experience in the     // shader debugger.  It enables source level debugging, prevents instruction     // reordering, prevents dead code elimination, and forces the compiler to compile     // against the next higher available software target, which ensures that the     // unoptimized shaders do not exceed the shader model limitations.  Setting these     // flags will cause slower rendering since the shaders will be unoptimized and     // forced into software.  See the DirectX documentation for more information about     // using the shader debugger.    DWORD dwShaderFlags = 0;    #ifdef DEBUG_VS        dwShaderFlags |= D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT;    #endif    #ifdef DEBUG_PS        dwShaderFlags |= D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT;    #endif    // Preshaders are parts of the shader that the effect system pulls out of the     // shader and runs on the host CPU. They should be used if you are GPU limited.     // The D3DXSHADER_NO_PRESHADER flag disables preshaders.    if( !g_bEnablePreshader )        dwShaderFlags |= D3DXSHADER_NO_PRESHADER;    // Read the D3DX effect file    WCHAR str[MAX_PATH];    V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"BasicHLSL.fx" ) );    // If this fails, there should be debug output as to     // why the .fx file failed to compile    V_RETURN( D3DXCreateEffectFromFile( pd3dDevice, str, NULL, NULL, dwShaderFlags, NULL, &g_pEffect, NULL ) );    // Create the mesh texture from a file    V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"tiny\\tiny_skin.bmp" ) );    V_RETURN( D3DXCreateTextureFromFileEx( pd3dDevice, str, D3DX_DEFAULT, D3DX_DEFAULT,                                        D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,                                        D3DX_DEFAULT, D3DX_DEFAULT, 0,                                        NULL, NULL, &g_pMeshTexture ) );    // Set effect variables as needed    D3DXCOLOR colorMtrlDiffuse(1.0f, 1.0f, 1.0f, 1.0f);    D3DXCOLOR colorMtrlAmbient(0.35f, 0.35f, 0.35f, 0);    V_RETURN( g_pEffect->SetValue("g_MaterialAmbientColor", &colorMtrlAmbient, sizeof(D3DXCOLOR) ) );    V_RETURN( g_pEffect->SetValue("g_MaterialDiffuseColor", &colorMtrlDiffuse, sizeof(D3DXCOLOR) ) );        V_RETURN( g_pEffect->SetTexture( "g_MeshTexture", g_pMeshTexture) );    // Setup the camera's view parameters    D3DXVECTOR3 vecEye(0.0f, 0.0f, -15.0f);    D3DXVECTOR3 vecAt (0.0f, 0.0f, -0.0f);    g_Camera.SetViewParams( &vecEye, &vecAt );    g_Camera.SetRadius( fObjectRadius*3.0f, fObjectRadius*0.5f, fObjectRadius*10.0f );    return S_OK;

and :
//render    HRESULT hr;    D3DXMATRIXA16 mWorldViewProjection;    D3DXVECTOR3 vLightDir[MAX_LIGHTS];    D3DXCOLOR   vLightDiffuse[MAX_LIGHTS];    UINT iPass, cPasses;    D3DXMATRIXA16 mWorld;    D3DXMATRIXA16 mView;    D3DXMATRIXA16 mProj;       // Clear the render target and the zbuffer     V( pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DXCOLOR(0.0f,0.25f,0.25f,0.55f), 1.0f, 0) );    // Render the scene    if( SUCCEEDED( pd3dDevice->BeginScene() ) )    {        // Get the projection & view matrix from the camera class        mWorld = g_mWorldFix * *g_Camera.GetWorldMatrix();        mProj = *g_Camera.GetProjMatrix();        mView = *g_Camera.GetViewMatrix();        mWorldViewProjection = mWorld * mView * mProj;        // Render the light spheres so the user can         // visually see the light dir        for( int i=0; i<g_nNumActiveLights; i++ )        {            D3DXCOLOR arrowColor = ( i == g_nActiveLight ) ? D3DXCOLOR(1,1,0,1) : D3DXCOLOR(1,1,1,1);            V( g_LightControl.OnRender( arrowColor, &mView, &mProj, g_Camera.GetEyePt() ) );            vLightDir = g_LightControl.GetLightDirection();            vLightDiffuse = g_fLightScale * D3DXCOLOR(1,1,1,1);        }        V( g_pEffect->SetValue( "g_LightDir", vLightDir, sizeof(D3DXVECTOR3)*MAX_LIGHTS ) );        V( g_pEffect->SetValue( "g_LightDiffuse", vLightDiffuse, sizeof(D3DXVECTOR4)*MAX_LIGHTS ) );        // Update the effect's variables.  Instead of using strings, it would         // be more efficient to cache a handle to the parameter by calling         // ID3DXEffect::GetParameterByName        V( g_pEffect->SetMatrix( "g_mWorldViewProjection", &mWorldViewProjection ) );        V( g_pEffect->SetMatrix( "g_mWorld", &mWorld ) );        V( g_pEffect->SetFloat( "g_fTime", (float)fTime ) );        D3DXCOLOR vWhite = D3DXCOLOR(1,1,1,1);        V( g_pEffect->SetValue("g_MaterialDiffuseColor", &vWhite, sizeof(D3DXCOLOR) ) );        V( g_pEffect->SetFloat( "g_fTime", (float)fTime ) );              V( g_pEffect->SetInt( "g_nNumLights", g_nNumActiveLights ) );              // Render the scene with this technique         // as defined in the .fx file        switch( g_nNumActiveLights )        {            case 1: V( g_pEffect->SetTechnique( "RenderSceneWithTexture1Light" ) ); break;            case 2: V( g_pEffect->SetTechnique( "RenderSceneWithTexture2Light" ) ); break;            case 3: V( g_pEffect->SetTechnique( "RenderSceneWithTexture3Light" ) ); break;        }        // Apply the technique contained in the effect         V( g_pEffect->Begin(&cPasses, 0) );        for (iPass = 0; iPass < cPasses; iPass++)        {            V( g_pEffect->BeginPass(iPass) );            // The effect interface queues up the changes and performs them             // with the CommitChanges call. You do not need to call CommitChanges if             // you are not setting any parameters between the BeginPass and EndPass.            // V( g_pEffect->CommitChanges() );            // Render the mesh with the applied technique            V( g_pMesh->DrawSubset(0) );            V( g_pEffect->EndPass() );        }        V( g_pEffect->End() );        g_HUD.OnRender( fElapsedTime );         g_SampleUI.OnRender( fElapsedTime );        RenderText( fTime );                V( pd3dDevice->EndScene() );    }

thanks for replies..


[Edited by - Washu on December 18, 2010 1:11:26 AM]

Hi,

If you are referring to the basichlsl sample that comes with the DirectX SDK, it doesn't even do skinning.

However, in my honest opinion, you should look in to the SDK samples and try to learn from. The problem you describe here is far too complex for most of the people to solve in reasonable time.

Cheers!

This topic is closed to new replies.

Advertisement