为什么小弟我渲染出来的是黑色的呢
为什么我渲染出来的是黑色的呢?
渲染出来的都是黑色的
请高手指教
------解决方案--------------------
D3D中的光照,默认情况下处于打开状态。那么渲染计算就要结合光源颜色和材质光颜色才能得到可见的结果。
如果关掉关照,渲染计算就直接使用顶点或贴图的颜色。
------解决方案--------------------
LS正解。
D3D固定流水线光照其实是在内部自动封装了一些颜色计算公式,建议用Shader自己动手实现一遍,你便会掌握D3D中光照的本质。
- C/C++ code
#include "head.h" #include "define.h" #include "DXUTsettingsdlg.h" #include "SDKmisc.h" #include "SDKmesh.h" #pragma warning(disable: 4995) #define WM_MOUSEWHEEL 0x020A //***************** Camera ********************************* CModelViewerCamera MyCamera; //***************** Camera ********************************* //Model_info *model; CDXUTXFileMesh model; using namespace std; int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { //*********************************************** DXUTSetCallbackD3D9DeviceCreated( OnCreateDevice ); DXUTSetCallbackD3D9FrameRender( OnFrameRender ); DXUTSetCallbackMsgProc( MsgProc ); DXUTSetCallbackFrameMove( OnFrameMove ); DXUTInit( true, true ); // Parse the command line and show msgboxes DXUTCreateWindow( L"G" ); DXUTCreateDevice( true, 1024, 768 ); DXUTMainLoop(); //***************** Wait Message ********************* return DXUTGetExitCode(); } LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing, void* pUserContext ) { MyCamera.HandleMessages( hWnd, uMsg, wParam, lParam ); return 0; } HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { //pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255,255,255), 1.0f, 0); //model = LoadModel_Texture(L"I:\\I disk\\可移动磁盘 (L)\\3DS文件转换为X文件\\conv3ds\\test.x", L"I:\\I disk\\可移动磁盘 (L)\\3DS文件转换为X文件\\conv3ds\\Serah.jpg", pd3dDevice); model.Create(pd3dDevice, L"I:\\I disk\\可移动磁盘 (L)\\3DS文件转换为X文件\\conv3ds\\test.x"); D3DXVECTOR3 eyePt(0.0f, 0.0f, 50.0f); D3DXVECTOR3 lookAt(0.0f, 0.0f, 0.0f); MyCamera.SetViewParams(&eyePt, &lookAt); float fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT )pBackBufferSurfaceDesc->Height; MyCamera.SetProjParams( D3DX_PI / 4, fAspectRatio, 0.1f, 10000.0f ); MyCamera.SetWindow( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height ); return S_OK; } void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ) { HRESULT hr; V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 255,255,255 ), 1.0f, 0 ) ); if (SUCCEEDED(pd3dDevice->BeginScene())) { D3DXMATRIX world = *MyCamera.GetWorldMatrix() ; V(pd3dDevice->SetTransform(D3DTS_WORLD, &world)) ; D3DXMATRIX view = *MyCamera.GetViewMatrix() ; V(pd3dDevice->SetTransform(D3DTS_VIEW, &view)) ; D3DXMATRIX proj = *MyCamera.GetProjMatrix() ; V(pd3dDevice->SetTransform(D3DTS_PROJECTION, &proj)) ; //**********************Rendering**************************** model.Render(pd3dDevice); pd3dDevice->EndScene(); } } void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void* pUserContext ) { MyCamera.FrameMove( fElapsedTime ); }
渲染出来的都是黑色的
请高手指教
------解决方案--------------------
D3D中的光照,默认情况下处于打开状态。那么渲染计算就要结合光源颜色和材质光颜色才能得到可见的结果。
如果关掉关照,渲染计算就直接使用顶点或贴图的颜色。
------解决方案--------------------
LS正解。
D3D固定流水线光照其实是在内部自动封装了一些颜色计算公式,建议用Shader自己动手实现一遍,你便会掌握D3D中光照的本质。