void InitLight() { D3DMATERIAL9 material; // create the material struct D3DLIGHT9 light; // create the light struct ZeroMemory(&light, sizeof(light)); // clear out the light struct for use light.Type = D3DLIGHT_DIRECTIONAL; // make the light type 'directional light' light.Diffuse = D3DXCOLOR(0.7f, 0.7f, 0.7f, 1.0f); // set the light's color light.Position = D3DXVECTOR3(0.0f, 1.0f, 0.0f); light.Direction = D3DXVECTOR3(0.5f, -1.0f, -1.0f); d3ddev->SetLight(0, &light); // send the light struct properties to light #0 d3ddev->LightEnable(0, TRUE); // turn on light #0 D3DLIGHT9 pointLight; // create the light struct ZeroMemory(&pointLight, sizeof(pointLight)); // clear out the light struct for use pointLight.Type = D3DLIGHT_POINT; // make the light type 'point light' pointLight.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); // set the light's color pointLight.Position = D3DXVECTOR3(0.0f, 7.0f, 5.0f); //pointLight.Direction = D3DXVECTOR3(0.5f, -1.0f, -1.0f); pointLight.Range = 100.0f; pointLight.Attenuation0 = 0.0f; // no constant inverse attenuation pointLight.Attenuation1 = 0.125f; // only .125 inverse attenuation pointLight.Attenuation2 = 0.0f; // no square inverse attenuation d3ddev->SetLight(1, &pointLight); // send the light struct properties to light #0 d3ddev->LightEnable(1, TRUE); // turn on light #1 ZeroMemory(&material, sizeof(D3DMATERIAL9)); // clear out the struct for use material.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); // set diffuse color to white material.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); // set ambient color to white d3ddev->SetMaterial(&material); // set the globably-used material to &material }
VOID SetupLights() { D3DMATERIAL9 mtrl; ZeroMemory(&mtrl, sizeof(D3DMATERIAL9)); mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f; mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f; mtrl.Diffuse.b = mtrl.Ambient.b = 1.0f; mtrl.Diffuse.a = mtrl.Ambient.a = 1.0f; g_pD3DDevice->SetMaterial(&mtrl); D3DXVECTOR3 vecDir0; D3DLIGHT9 light0; ZeroMemory(&light0, sizeof(D3DLIGHT9)); light0.Type = D3DLIGHT_DIRECTIONAL; light0.Diffuse.r = 1.f; light0.Diffuse.g = 1.f; light0.Diffuse.b = 1.f; vecDir0 = D3DXVECTOR3(-1.f, 1.f, 0.f ); D3DXVec3Normalize((D3DXVECTOR3*) &light0.Direction, &vecDir0); light0.Range = 1000.f; D3DXVECTOR3 vecDir1; D3DLIGHT9 light1; ZeroMemory(&light1, sizeof(D3DLIGHT9)); light1.Type = D3DLIGHT_DIRECTIONAL; light1.Diffuse.r = 1.f; light1.Diffuse.g = 1.f; light1.Diffuse.b = 1.f; vecDir1 = D3DXVECTOR3(1.f, 1.f, 0.f); D3DXVec3Normalize((D3DXVECTOR3*) &light1.Direction, &vecDir1); light1.Range = 1000.f; g_pD3DDevice->SetLight(0, &light0); g_pD3DDevice->SetLight(1, &light1); g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, TRUE); g_pD3DDevice->SetRenderState(D3DRS_AMBIENT, 0x00808080); if (5<(g_tick%31)) { g_pD3DDevice->LightEnable(0, TRUE); g_pD3DDevice->LightEnable(1, FALSE); } else { g_pD3DDevice->LightEnable(0, FALSE); g_pD3DDevice->LightEnable(1, TRUE); } }
// // 윈도우 프로시져 함수 ( 메시지 큐에서 받아온 메시지를 처리한다 ) // LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch (msg) { case WM_KEYDOWN: if (wParam == VK_ESCAPE) ::DestroyWindow(hWnd); else if (wParam == VK_TAB) { static bool flag = false; g_pDevice->SetRenderState(D3DRS_CULLMODE, flag? D3DCULL_CCW : D3DCULL_NONE); g_pDevice->SetRenderState(D3DRS_FILLMODE, flag? D3DFILL_SOLID : D3DFILL_WIREFRAME); flag = !flag; } else if (VK_SPACE == wParam) { static bool flag = false; g_pDevice->SetLight(0, &global->light); // 광원 설정. g_pDevice->LightEnable(0, flag); flag = !flag; } break; case WM_DESTROY: //윈도우가 파괴된다면.. PostQuitMessage(0); //프로그램 종료 요청 ( 메시지 루프를 빠져나가게 된다 ) break; } return DefWindowProc( hWnd, msg, wParam, lParam ); }
void SetupLightingDX9(void) { // 取得Direct3D 9裝置 LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9(); device->SetRenderState(D3DRS_LIGHTING, TRUE); // 設定環境光 device->SetRenderState(D3DRS_AMBIENT, ConvertToD3DCOLOR(g_vAmbientLight)); // 設定光源 device->LightEnable(0, TRUE); D3DLIGHT9 light; ZeroMemory( &light, sizeof(light) ); light.Type = D3DLIGHT_POINT; light.Position = *(D3DVECTOR *) &g_Light.m_Position; light.Diffuse = *(D3DCOLORVALUE*) &g_Light.m_Diffuse; light.Specular = *(D3DCOLORVALUE*) &g_Light.m_Specular; light.Range = 100.0f; light.Attenuation0 = 1.0f; light.Attenuation1 = 0.0f; light.Attenuation2 = 0.0f; device->SetLight(0, &light); }
// @brief : 描画が有効のときの挙動 //-------------------------------------------------------------------- void DirectionalLightDx9::OnEnable( void ) { LPDIRECT3DDEVICE9 device = DirectX9::Instance().Device; device->SetRenderState(D3DRS_LIGHTING,TRUE); device->SetRenderState(D3DRS_AMBIENT,TRUE); device->LightEnable(m_Index,TRUE); }
//----------------------------------------------------------------------------- // Name: SetupLights() // Desc: Sets up the lights and materials for the scene. //----------------------------------------------------------------------------- VOID SetupLights() { // Set up a material. The material here just has the diffuse and ambient // colors set to yellow. Note that only one material can be used at a time. D3DMATERIAL9 mtrl; ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) ); mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f; mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f; mtrl.Diffuse.b = mtrl.Ambient.b = 0.0f; mtrl.Diffuse.a = mtrl.Ambient.a = 1.0f; g_pd3dDevice->SetMaterial( &mtrl ); // Set up a white, directional light, with an oscillating direction. // Note that many lights may be active at a time (but each one slows down // the rendering of our scene). However, here we are just using one. Also, // we need to set the D3DRS_LIGHTING renderstate to enable lighting D3DXVECTOR3 vecDir; D3DLIGHT9 light; ZeroMemory( &light, sizeof(D3DLIGHT9) ); light.Type = D3DLIGHT_DIRECTIONAL; light.Diffuse.r = 1.0f; light.Diffuse.g = 1.0f; light.Diffuse.b = 1.0f; vecDir = D3DXVECTOR3(cosf(timeGetTime()/350.0f), 1.0f, sinf(timeGetTime()/350.0f) ); D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir ); light.Range = 1000.0f; g_pd3dDevice->SetLight( 0, &light ); g_pd3dDevice->LightEnable( 0, TRUE ); g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE ); // Finally, turn on some ambient light. g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00202020 ); }
// デフォルトコンストラクタ Light::Light() { // ライトの設定 ZeroMemory(&light, sizeof(D3DLIGHT9)); light.Type = D3DLIGHT_DIRECTIONAL; light.Diffuse.r = 1.0f; light.Diffuse.g = 1.0f; light.Diffuse.b = 1.0f; light.Ambient.r = 1.0f; light.Ambient.g = 1.0f; light.Ambient.b = 1.0f; light.Specular.r = 1.0f; light.Specular.g = 1.0f; light.Specular.b = 1.0f; D3DXVECTOR3 lightAngle; lightAngle = D3DXVECTOR3(1.0f, -1.0f, 1.0f); D3DXVec3Normalize((D3DXVECTOR3*)&light.Direction, &lightAngle); d3dDevice->SetLight(0, &light); d3dDevice->LightEnable(0, true); d3dDevice->SetRenderState(D3DRS_LIGHTING, true); d3dDevice->SetRenderState(D3DRS_AMBIENT, 0x00111111); d3dDevice->SetRenderState(D3DRS_SPECULARENABLE, true); // 霧の発生 d3dDevice->SetRenderState(D3DRS_FOGENABLE, true); d3dDevice->SetRenderState(D3DRS_FOGCOLOR, 0xff000033); d3dDevice->SetRenderState(D3DRS_FOGSTART, FtoDW(100.0f)); d3dDevice->SetRenderState(D3DRS_FOGEND, FtoDW(315.0f)); d3dDevice->SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR); }
void RageDisplay_D3D::SetLightDirectional( int index, const RageColor &ambient, const RageColor &diffuse, const RageColor &specular, const RageVector3 &dir ) { g_pd3dDevice->LightEnable( index, true ); D3DLIGHT9 light; ZERO( light ); light.Type = D3DLIGHT_DIRECTIONAL; /* Z for lighting is flipped for D3D compared to OpenGL. * XXX: figure out exactly why this is needed. Our transforms * are probably goofed up, but the Z test is the same for both * API's, so I'm not sure why we don't see other weirdness. -Chris */ float position[] = { dir.x, dir.y, -dir.z }; memcpy( &light.Direction, position, sizeof(position) ); memcpy( &light.Diffuse, diffuse, sizeof(diffuse) ); memcpy( &light.Ambient, ambient, sizeof(ambient) ); memcpy( &light.Specular, specular, sizeof(specular) ); // Same as OpenGL defaults. Not used in directional lights. // light.Attenuation0 = 1; // light.Attenuation1 = 0; // light.Attenuation2 = 0; g_pd3dDevice->SetLight( index, &light ); }
VOID SetupLights() { // 初始化一个材料 D3DMATERIAL9 mtrl; ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) ); mtrl.Diffuse = mtrl.Ambient = D3DXCOLOR(1.0f,1.0f,0.0f,1.0f); //材质有漫射和环境光的设置,都为黄色 g_pd3dDevice->SetMaterial( &mtrl ); // 初始化一个白色的方向光 ///* D3DXVECTOR3 vecDir; D3DLIGHT9 light; ZeroMemory( &light, sizeof(D3DLIGHT9) ); light.Type = D3DLIGHT_DIRECTIONAL;//方向光 light.Diffuse = D3DXCOLOR(1.0f,1.0f,1.0f,1.0f);//设置光源的漫射光颜色为白色 light.Direction = D3DXVECTOR3(0.0f,0.0f,1.0f);//光的传播方向平行z轴 light.Range = 1000.0f; g_pd3dDevice->SetLight( 0, &light ); g_pd3dDevice->LightEnable( 0, TRUE ); g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE ); // Finally, turn on some ambient light. g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00202020 ); }
HRESULT Game::InitLight() { D3DLIGHT9 light; ZeroMemory(&light, sizeof(D3DLIGHT9)); light.Type = D3DLIGHT_DIRECTIONAL; //ライトの向きの調整 light.Direction = D3DXVECTOR3(1.0f, -1.0f, 1.0f); //ディフューズを設定する light.Diffuse.r = 1.0f; light.Diffuse.g = 1.0f; light.Diffuse.b = 1.0f; //アンビエント(間接光)を追加する light.Ambient.r = 0.4f; light.Ambient.g = 0.4f; light.Ambient.b = 0.4f; if (FAILED(g_pDevice->SetLight(0, &light))) { MessageBox(0, "ライトをセットできませんでした", "Game", MB_OK); return E_FAIL; } if (FAILED(g_pDevice->LightEnable(0, TRUE))) { MessageBox(0, "ライトを有効にできませんでした", "Game", MB_OK); return E_FAIL; } return S_OK; }
//デフォルトコンストラクタ Light::Light() { //ライトの設定 ZeroMemory(&light, sizeof(D3DLIGHT9)); light.Type = D3DLIGHT_DIRECTIONAL; light.Diffuse.r = 1.0f; light.Diffuse.g = 1.0f; light.Diffuse.b = 1.0f; light.Ambient.r = 1.0f; light.Ambient.g = 1.0f; light.Ambient.b = 1.0f; light.Specular.r = 1.0f; light.Specular.g = 1.0f; light.Specular.b = 1.0f; D3DXVECTOR3 lightAngle; lightAngle = D3DXVECTOR3(0.0f, -1.0f, 1.0f); D3DXVec3Normalize((D3DXVECTOR3 *)&light.Direction, &lightAngle); d3dDevice->SetLight(0, &light); d3dDevice->LightEnable(0, true); d3dDevice->SetRenderState(D3DRS_LIGHTING, true); d3dDevice->SetRenderState(D3DRS_AMBIENT, 0x00111111); d3dDevice->SetRenderState(D3DRS_SPECULARENABLE, true); }
//----------------------------------------------------------------------------- // Desc: 设置材质和灯光 //----------------------------------------------------------------------------- VOID SetLight() { //设置材质 D3DMATERIAL9 mtrl; ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) ); mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f; mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f; mtrl.Diffuse.b = mtrl.Ambient.b = 0.0f; mtrl.Diffuse.a = mtrl.Ambient.a = 1.0f; g_pd3dDevice->SetMaterial( &mtrl ); //设置灯光 D3DXVECTOR3 vecDir; D3DLIGHT9 light; ZeroMemory( &light, sizeof(D3DLIGHT9) ); light.Type = D3DLIGHT_DIRECTIONAL; light.Diffuse.r = 1.0f; light.Diffuse.g = 1.0f; light.Diffuse.b = 1.0f; vecDir = D3DXVECTOR3( cosf(timeGetTime()/350.0f), 1.0f, sinf(timeGetTime()/350.0f) ); vecDir = D3DXVECTOR3(1.0f, 1.0f, 0.0f); D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir ); light.Range = 1000.0f; g_pd3dDevice->SetLight( 0, &light ); g_pd3dDevice->LightEnable( 0, TRUE ); g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE ); //设置环境光 g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00505050); }
HRESULT HookIDirect3DDevice9::LightEnable(LPVOID _this, DWORD Index, BOOL Enable) { LOG_API(); return pD3Dev->LightEnable(Index, Enable); }
/**----------------------------------------------------------------------------- * 광원 설정 *------------------------------------------------------------------------------ */ VOID SetupLights() { /// 재질(material)설정 /// 재질은 디바이스에 단 하나만 설정될 수 있다. D3DMATERIAL9 mtrl; ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) ); mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f; mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f; mtrl.Diffuse.b = mtrl.Ambient.b = 1.0f; mtrl.Diffuse.a = mtrl.Ambient.a = 1.0f; g_pd3dDevice->SetMaterial( &mtrl ); /// 광원 설정 D3DXVECTOR3 vecDir; /// 방향성 광원(directional light)이 향할 빛의 방향 D3DLIGHT9 light; /// 광원 구조체 ZeroMemory( &light, sizeof(D3DLIGHT9) ); /// 구조체를 0으로 지운다. light.Type = D3DLIGHT_DIRECTIONAL; /// 광원의 종류(점 광원,방향성 광원,스포트라이트) light.Diffuse.r = 1.0f; /// 광원의 색깔과 밝기 light.Diffuse.g = 1.0f; light.Diffuse.b = 0.0f; vecDir = D3DXVECTOR3( 1, 1, 1 ); /// 광원 고정 vecDir = D3DXVECTOR3(cosf(GetTickCount()/350.0f), /// 광원 회전 1.0f, sinf(GetTickCount()/350.0f) ); D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir ); /// 광원의 방향을 단위벡터로 만든다. light.Range = 1000.0f; /// 광원이 다다를수 있는 최대거리 g_pd3dDevice->SetLight( 0, &light ); /// 디바이스에 0번 광원 설치 g_pd3dDevice->LightEnable( 0, TRUE ); /// 0번 광원을 켠다 g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE ); /// 광원설정을 켠다 g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00909090 ); /// 환경광원(ambient light)의 값 설정 }
VOID SetupLights() { D3DMATERIAL9 mtrl; ZeroMemory( &mtrl, sizeof( D3DMATERIAL9 ) ); mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f; mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f; mtrl.Diffuse.b = mtrl.Ambient.b = 1.0f; mtrl.Diffuse.a = mtrl.Ambient.a = 1.0f; g_pd3dDevice->SetMaterial( &mtrl ); D3DXVECTOR3 vecDir; D3DLIGHT9 light; ZeroMemory( &light, sizeof( D3DLIGHT9 ) ); light.Type = D3DLIGHT_DIRECTIONAL; light.Diffuse.r = 1.0f; light.Diffuse.g = 1.0f; light.Diffuse.b = 1.0f; vecDir = D3DXVECTOR3( 0.0f, 0.0f, 1.0f ); D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir ); light.Range = 1000.0f; g_pd3dDevice->SetLight( 0, &light ); g_pd3dDevice->LightEnable( 0, true ); g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE ); g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0xFFA0A0A0 ); }
HRESULT SetupPointLight(D3DXVECTOR3& position, D3DXCOLOR color) { D3DLIGHT9 pointLight; ZeroMemory(&pointLight, sizeof(pointLight)); pointLight.Type = D3DLIGHT_POINT ; pointLight.Ambient = color * 0.6f; pointLight.Diffuse = color; pointLight.Specular = color * 0.6f; pointLight.Position = position; pointLight.Range = 1000.0f; pointLight.Falloff = 1.0f; pointLight.Attenuation0 = 1.0f; pointLight.Attenuation1 = 0.0f; pointLight.Attenuation2 = 0.0f; g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE); // Set light g_pd3dDevice->SetLight(0, &pointLight); // Enable light g_pd3dDevice->LightEnable(0, TRUE); return D3D_OK; }
bool initScene() { const double kFovY = 40; // Lighting pd3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE); // Ambient pd3dDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(77, 77, 77)); // Directional D3DLIGHT9 light; light.Type = D3DLIGHT_DIRECTIONAL; D3DXVECTOR3 dir(0.0f, -0.4f, 1.0f); D3DXVec3Normalize((D3DXVECTOR3*)&light.Direction, &dir); light.Diffuse.r = 0.9f; light.Diffuse.g = 0.9f; light.Diffuse.b = 0.9f; light.Ambient.r = 0.5f; light.Ambient.g = 0.5f; light.Ambient.b = 0.5f; light.Range = sqrtf(FLT_MAX); pd3dDevice->SetLight(0, &light); pd3dDevice->LightEnable(0, TRUE); // Create the cube HRESULT hr = D3DXCreateBox( pd3dDevice, gCubeEdgeLength, gCubeEdgeLength, gCubeEdgeLength, &gCube, NULL); gCubeMaterial.MatD3D.Diffuse.r = 0.5f; gCubeMaterial.MatD3D.Diffuse.g = 0.5f; gCubeMaterial.MatD3D.Diffuse.b = 0.5f; gCubeMaterial.MatD3D.Ambient.r = 0.5f; gCubeMaterial.MatD3D.Ambient.g = 0.5f; gCubeMaterial.MatD3D.Ambient.b = 0.5f; // Create the cursor hr = D3DXCreateSphere( pd3dDevice, gCursorRadius, 15, 15, &gCursor, NULL); gCursorMaterial.MatD3D.Diffuse.r = 0.0f; gCursorMaterial.MatD3D.Diffuse.g = 0.5f; gCursorMaterial.MatD3D.Diffuse.b = 0.5f; gCursorMaterial.MatD3D.Ambient.r = 0.0f; gCursorMaterial.MatD3D.Ambient.g = 0.5f; gCursorMaterial.MatD3D.Ambient.b = 0.5f; return true; }
/* =============== */ virtual void enter () { m_devcs->SetRenderState(D3DRS_LIGHTING, TRUE); m_devcs->SetRenderState(D3DRS_AMBIENT, m_color[0]); m_devcs->SetRenderState(D3DRS_NORMALIZENORMALS, TRUE); for (DWORD idx = 0; idx < m_count; idx++) { m_devcs->SetLight(idx, &m_light[idx]); m_devcs->LightEnable(idx, m_onoff[idx]); } }
bool si3::SealData::draw( LPDIRECT3DDEVICE9 device, const D3DXMATRIX & world_mat, LPDIRECT3DTEXTURE9 texture, IDirect3DVertexBuffer9 * vertbuff, IDirect3DIndexBuffer9 * indexbuff, int index_num, int triangle_num, const D3DMATERIAL9 & material) const { // 頂点フォーマット設定 device->SetFVF(LAND_FVF); //マテリアル設定 device->SetMaterial(&material); //テクスチャ設定 device->SetTexture(0, texture); device->SetStreamSource(0, vertbuff, 0, sizeof(DxTop2D)); device->SetIndices(indexbuff); // ライティング無し device->LightEnable(0, FALSE); device->SetRenderState(D3DRS_LIGHTING, FALSE); device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); // プリミティブ描画 device->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP, 0, 0, index_num, 0, triangle_num); // ライティング有り device->LightEnable(0, TRUE); device->SetRenderState(D3DRS_LIGHTING, TRUE); return true; }
void TSRLightingManager::RenderAllLightsPassesForward( TSRSceneWorldInterface* _pWorld ) { #ifdef D3D9_RENDERER if ( g_bD3D9FixedFunction ) { g_pD3DDevice->LightEnable( 0, TRUE ); g_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); g_pD3DDevice->SetRenderState( D3DRS_LIGHTING, TRUE ); g_pD3DDevice->SetRenderState( D3DRS_AMBIENT, *( ( DWORD* ) ( &m_AmbientColor ) ) ); } #endif { GenerateLightingContexts(); unsigned int uiOriginalDisableMask = m_EffectsDisabledMask; Graphics()->SetBlendState( Graphics()->m_BlendDisabled ); if ( m_aFwdLightingContexts.size() == 0 ) { return; } // first render using the ambient light and the directional lights.. TSRForwardRenderingLightingContext& firstContext = m_aFwdLightingContexts[ 0 ]; SetShaderConstants( firstContext ); _pWorld->RenderObjects( _pWorld->GetMainCamera() ); // cascaded shadow maps are disabled with the subsequent passes m_EffectsDisabledMask = uiOriginalDisableMask | TWISTER_SHADER_FLAG_SHADOWMAP; // the rest is additive Graphics()->SetBlendState( Graphics()->m_BlendAdditiveColor ); m_AmbientLightColor.Set( TSRColor4::Black ); for ( unsigned int i = 1; i < m_aFwdLightingContexts.size(); i++ ) { TSRForwardRenderingLightingContext& currContext = m_aFwdLightingContexts[ i ]; SetShaderConstants( currContext ); _pWorld->RenderObjects( _pWorld->GetMainCamera() ); } Graphics()->SetBlendState( Graphics()->m_BlendDisabled ); m_AmbientLightColor.Set( m_AmbientColor ); m_EffectsDisabledMask = uiOriginalDisableMask; } #ifdef D3D9_RENDERER if ( g_bD3D9FixedFunction ) { g_pD3DDevice->SetRenderState( D3DRS_LIGHTING, FALSE ); g_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); } #endif }
VOID RenderTeapot() { g_pd3dDevice->SetMaterial(&g_Material) ; g_pd3dDevice->SetRenderState( D3DRS_LIGHTING , TRUE ); g_pd3dDevice->SetLight(0, &g_Light) ; g_pd3dDevice->LightEnable(0, TRUE) ; g_pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME) ; g_pTeapotMesh->DrawSubset(0) ; // Draw teapot }
VOID SetupLightEnvironment() { D3DMATERIAL9 mtrl; ZeroMemory( &mtrl, sizeof( D3DMATERIAL9 ) ); mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f; mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f; mtrl.Diffuse.b = mtrl.Ambient.b = 0.0f; mtrl.Diffuse.a = mtrl.Ambient.a = 1.0f; g_pd3dDevice->SetMaterial( &mtrl ); g_pd3dDevice->LightEnable( 1, TRUE ); g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE ); g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00202020 ); }
VOID Light_Set(LPDIRECT3DDEVICE9 &pd3dDevice, UINT uType){ D3DLIGHT9 light; ZeroMemory(&light, sizeof(light)); switch (uType){ case 0: light.Type = D3DLIGHT_POINT; light.Ambient = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f); light.Diffuse = D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f); light.Specular = D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f); light.Position = D3DXVECTOR3(0.0f, 100.0f, 0.0f); light.Direction = D3DXVECTOR3(0.0f, -1.0f, 0.0f); light.Range = 300.0f; light.Attenuation0 = 1.0f; light.Attenuation1 = 0.0f; light.Attenuation2 = 0.0f; break; case 1: light.Type = D3DLIGHT_DIRECTIONAL; light.Ambient = D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f); light.Diffuse = D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f); light.Specular = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f); light.Direction = D3DXVECTOR3(-1.0f, 0.0f, 0.0f); break; case 2: light.Type = D3DLIGHT_SPOT; light.Ambient = D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f); light.Diffuse = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f); light.Specular = D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f); light.Position = D3DXVECTOR3(0.0f, -100.0f, 0.0f); light.Direction = D3DXVECTOR3(0.0f, 1.0f, 0.0f); light.Range = 300.0f; light.Falloff = 0.1f; light.Phi = D3DX_PI / 3.0f; light.Theta = D3DX_PI / 6.0f; light.Attenuation0 = 1.0f; light.Attenuation1 = 0.0f; light.Attenuation2 = 0.0f; break; default: break; } pd3dDevice->SetLight(0, &light); pd3dDevice->LightEnable(0, true); pd3dDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(36, 36, 36)); }
void CLight::Appear( LPDIRECT3DDEVICE9 pd3dDevice, BOOL bEnable ) { if( bEnable ) { if( D3D_OK != pd3dDevice->SetLight( m_dwIndex, this ) ) { ASSERT( 0 ); } } if( D3D_OK != pd3dDevice->LightEnable( m_dwIndex, bEnable ) ) { ASSERT( 0 ); } }
void enableLightHackDirectional(LPDIRECT3DDEVICE9 pDevice) { D3DLIGHT9 light; ZeroMemory(&light, sizeof(light)); light.Type = D3DLIGHT_DIRECTIONAL; light.Diffuse = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); light.Direction = D3DXVECTOR3(-1.0f, -0.5f, -1.0f); pDevice->SetLight(0, &light); pDevice->LightEnable(0, TRUE); lightHack = true; }
VOID SetupLights(int lightNum) { D3DMATERIAL9 mtrl; ZeroMemory(&mtrl, sizeof(D3DMATERIAL9)); mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f; mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f; mtrl.Diffuse.b = mtrl.Ambient.b = 0.0f; mtrl.Diffuse.a = mtrl.Ambient.a = 0.0f; g_pd3dDevice->SetMaterial(&mtrl); D3DXVECTOR3 vecDir; D3DLIGHT9 light0, light1; ZeroMemory(&light0, sizeof(D3DLIGHT9)); ZeroMemory(&light1, sizeof(D3DLIGHT9)); D3DLIGHT9 *light; if (lightNum == 0) light = &light0; else if (lightNum == 1) light = &light1; light->Type = D3DLIGHT_DIRECTIONAL; light->Diffuse.r = 1.0f; light->Diffuse.g = 1.0f; light->Diffuse.b = 1.0f; vecDir = D3DXVECTOR3(10.f * pow(-1.f,lightNum), 1.0f, 0); D3DXVec3Normalize((D3DXVECTOR3*)&light->Direction, &vecDir); light->Range = 1000.f; g_pd3dDevice->SetLight(lightNum, light); g_pd3dDevice->LightEnable(lightNum, TRUE); g_pd3dDevice->LightEnable(1-lightNum, FALSE); g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE); // Finally, turn on some ambient light. g_pd3dDevice->SetRenderState(D3DRS_AMBIENT, 0x00202020); }
void SetLight(LPDIRECT3DDEVICE9 device, int type) { static D3DLIGHT9 light; ZeroMemory(&light, sizeof(D3DLIGHT9)); switch (type) { case 1: //点光源 light.Type = D3DLIGHT_POINT; light.Ambient = D3DXCOLOR(0.6f, 0.6f, 0.6f, 1.0f); light.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); light.Specular = D3DXCOLOR(0.3f, 0.3f, 0.3f, 1.0f); light.Position = D3DXVECTOR3(0.0f, 200.0f, 0.0f); light.Attenuation0 = 1.0f; light.Attenuation1 = 0.0f; light.Attenuation2 = 0.0f; light.Range = 300.0f; break; case 2: //平行光 light.Type = D3DLIGHT_DIRECTIONAL; light.Ambient = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); light.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); light.Specular = D3DXCOLOR(0.3f, 0.3f, 0.3f, 1.0f); light.Direction = D3DXVECTOR3(1.0f, 0.0f, 0.0f); break; case 3: //聚光灯 light.Type = D3DLIGHT_SPOT; light.Position = D3DXVECTOR3(100.0f, 100.0f, 100.0f); light.Direction = D3DXVECTOR3(-1.0f, -1.0f, -1.0f); light.Ambient = D3DXCOLOR(0.3f, 0.3f, 0.3f, 1.0f); light.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); light.Specular = D3DXCOLOR(0.3f, 0.3f, 0.3f, 0.3f); light.Attenuation0 = 1.0f; light.Attenuation1 = 0.0f; light.Attenuation2 = 0.0f; light.Range = 300.0f; light.Falloff = 0.1f; light.Phi = PI / 3.0f; light.Theta = PI / 6.0f; break; default: break; } device->SetLight(0, &light); device->LightEnable(0, TRUE); device->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(36, 36, 36)); }
//========================================================== // Name : // Desc : //========================================================== void CLight::Directional(LPDIRECT3DDEVICE9 device, D3DXVECTOR3 direction) { ZeroMemory(&light,sizeof(D3DLIGHT9)); light.Type = D3DLIGHT_DIRECTIONAL; // light.Type = D3DLIGHT_POINT; light.Ambient.r = 0.3f; light.Ambient.g = 0.3f; light.Ambient.b = 0.3f; light.Diffuse.r = 0.6f; light.Diffuse.g = 0.6f; light.Diffuse.b = 0.6f; light.Specular.r = 1.0f; light.Specular.g = 1.0f; light.Specular.b = 1.0f; // light.Position = D3DXVECTOR3(3.0f,3.0f,3.0f); light.Direction.x= direction.x; light.Direction.y= direction.y; light.Direction.z= direction.z; // light.Range = 30.0f; // ライト有効化 device->LightEnable(D3DLIGHT_DIRECTIONAL,TRUE); device->SetLight(D3DLIGHT_DIRECTIONAL,&light); }
void SetupLight() { // Enable lighting g_pd3dDevice->SetRenderState( D3DRS_LIGHTING , TRUE ); D3DLIGHT9 light; ZeroMemory( &light, sizeof(light) ); light.Type = D3DLIGHT_DIRECTIONAL; light.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); light.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); light.Specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); light.Direction = D3DXVECTOR3(10.0f, 10.0f, -10.0f); g_pd3dDevice->SetLight(0, &light); g_pd3dDevice->LightEnable(0, true); g_pd3dDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true); g_pd3dDevice->SetRenderState(D3DRS_SPECULARENABLE, true); };
void SetupLights() { LPDIRECT3DDEVICE9 d = g_pd3dDevice; { /// material D3DMATERIAL9 material; _E_INIT_STRUCT( material ); material.Diffuse.r = material.Ambient.r = 1.0f; material.Diffuse.g = material.Ambient.g = 1.0f; material.Diffuse.b = material.Ambient.b = 0.0f; material.Diffuse.a = material.Ambient.a = 1.0f; // set d->SetMaterial( &material ); } { /// light D3DLIGHT9 light; _E_INIT_STRUCT( light ); // fill value light.Range = 1000.0f; light.Type = D3DLIGHT_DIRECTIONAL; light.Diffuse.r = 1.0f; light.Diffuse.g = 1.0f; light.Diffuse.b = 1.0f; // dir D3DXVECTOR3 light_dir; float time_angle = timeGetTime() / 350.0f; light_dir = D3DXVECTOR3( cosf(time_angle), 1.0f, sinf(time_angle) ); D3DXVec3Normalize( (D3DXVECTOR3 *)&light.Direction, &light_dir ); // set d->SetLight( 0, &light ); d->LightEnable( 0, true ); d->SetRenderState( D3DRS_LIGHTING, true ); d->SetRenderState( D3DRS_AMBIENT, 0x00202020 ); } }