void RMeshNodeMtrl::SetMtrl(D3DXCOLOR* c,float vis_alpha) { if(!c) return; D3DMATERIAL9 mtrl; ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) ); mtrl.Diffuse.r = c->r; mtrl.Diffuse.g = c->g; mtrl.Diffuse.b = c->b; mtrl.Diffuse.a = c->a; mtrl.Ambient.r = c->r*0.5f; mtrl.Ambient.g = c->g*0.5f; mtrl.Ambient.b = c->b*0.5f; mtrl.Ambient.a = 1.0f; mtrl.Specular.r = 1.0f; mtrl.Specular.g = 1.0f; mtrl.Specular.b = 1.0f; mtrl.Specular.a = 1.0f; if(vis_alpha != 1.f) { mtrl.Diffuse.a = vis_alpha; mtrl.Ambient.a = vis_alpha; mtrl.Specular.a = vis_alpha; } RGetDevice()->SetMaterial( &mtrl ); if(RGetShaderMgr()->mbUsingShader ) { RGetShaderMgr()->setMtrl( *c, vis_alpha ); } }
void ZApplication::OnRestore() { if(m_pGameInterface) m_pGameInterface->OnRestore(); if( ZGetConfiguration()->GetVideo()->bShader ) { RMesh::mHardwareAccellated = true; if( !RGetShaderMgr()->SetEnable() ) { RGetShaderMgr()->SetDisable(); } } }
void RMeshNodeMtrl::SetMtrlDiffuse(RMtrl* pMtrl,float vis_alpha) { if(!pMtrl) return; D3DMATERIAL9 mtrl; ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) ); D3DXCOLOR* c = &pMtrl->m_diffuse; mtrl.Diffuse.r = c->r*0.5f; mtrl.Diffuse.g = c->g*0.5f; mtrl.Diffuse.b = c->b*0.5f; mtrl.Diffuse.a = 1.0f; mtrl.Ambient.r = c->r*0.1f; mtrl.Ambient.g = c->g*0.1f; mtrl.Ambient.b = c->b*0.1f; mtrl.Ambient.a = 1.0f; mtrl.Specular.r = 0.5f; mtrl.Specular.g = 0.5f; mtrl.Specular.b = 0.5f; mtrl.Specular.a = 1.f; mtrl.Power = pMtrl->m_power; if( pMtrl->m_power ) { RGetDevice()->SetRenderState( D3DRS_SPECULARENABLE, TRUE ); } else { RGetDevice()->SetRenderState( D3DRS_SPECULARENABLE, FALSE ); } if(vis_alpha != 1.f) { mtrl.Diffuse.a = vis_alpha; mtrl.Ambient.a = vis_alpha; mtrl.Specular.a = vis_alpha; } RGetDevice()->SetMaterial( &mtrl ); if(RGetShaderMgr()->mbUsingShader ) { RGetShaderMgr()->setMtrl( pMtrl, vis_alpha ); } }
void RMeshNodeMtrl::SetMtrl(RMtrl* pMtrl,float vis_alpha,bool bNpc,D3DCOLORVALUE color) { if(!pMtrl) return; D3DMATERIAL9 mtrl; ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) ); if(bNpc) { mtrl.Diffuse.r = color.r; mtrl.Diffuse.g = color.g; mtrl.Diffuse.b = color.b; mtrl.Diffuse.a = 1.0f; mtrl.Ambient.r = color.r/2.f; mtrl.Ambient.g = color.g/2.f; mtrl.Ambient.b = color.b/2.f; mtrl.Ambient.a = 1.0f; } else { mtrl.Diffuse.r = color.r; mtrl.Diffuse.g = color.g; mtrl.Diffuse.b = color.b; mtrl.Diffuse.a = 1.0f; mtrl.Ambient.r = color.r/2.f; mtrl.Ambient.g = color.g/2.f; mtrl.Ambient.b = color.b/2.f; mtrl.Ambient.a = 1.0f; /* mtrl.Diffuse.r = 0.5f; mtrl.Diffuse.g = 0.5f; mtrl.Diffuse.b = 0.5f; mtrl.Diffuse.a = 1.0f; mtrl.Ambient.r = 0.35f; mtrl.Ambient.g = 0.35f; mtrl.Ambient.b = 0.35f; mtrl.Ambient.a = 1.0f; */ } mtrl.Specular.r = 0.5f; mtrl.Specular.g = 0.5f; mtrl.Specular.b = 0.5f; mtrl.Specular.a = 1.f; mtrl.Power = pMtrl->m_power; if( pMtrl->m_power ) { RGetDevice()->SetRenderState( D3DRS_SPECULARENABLE, TRUE ); } else { RGetDevice()->SetRenderState( D3DRS_SPECULARENABLE, FALSE ); } if(vis_alpha != 1.f) { mtrl.Diffuse.a = vis_alpha; mtrl.Ambient.a = vis_alpha; mtrl.Specular.a = vis_alpha; } RGetDevice()->SetMaterial( &mtrl ); if(RGetShaderMgr()->mbUsingShader ) { RGetShaderMgr()->setMtrl( pMtrl, vis_alpha ); } }
////////////////////////////////////////////////////////////////////////// // Render ////////////////////////////////////////////////////////////////////////// void ZClothEmblem::render() { // if( !isInViewFrustum( &mAABB, RGetViewFrustum() ) ) //{ // return; //} // if(g_pGame==NULL || !ZGetGame()->GetWorld()->GetBsp()->IsVisible(mAABB)) return; if( !mbIsInFrustrum ) return; int i, index; UpdateNormal(); //memset(g_Cloth_Buffer,0, sizeof(RVertex)*MAX_NUM_CLOTH_PARTICLE*3 ); //for( i = 0 ; i < mpMeshNode->m_point_num; ++i ) //{ // g_Cloth_Buffer[i].p = m_pX[i]; // g_Cloth_Buffer[i].n = m_pNormal[i]; //} // for( i = 0 ; i < mpMeshNode->m_face_num; ++i ) //{ // for( int j = 0 ; j < 3; ++j ) // { // index = mpMeshNode->m_face_list[i].m_point_index[j]; // g_Cloth_Buffer[index].tu = mpMeshNode->m_face_list[i].m_point_tex[j].x; // g_Cloth_Buffer[index].tv = mpMeshNode->m_face_list[i].m_point_tex[j].y; // g_index_buffer[i*3+j] = index; // } //} for( i = 0 ; i < mpMeshNode->m_face_num; ++i ) { for( int j = 0 ; j < 3; ++j ) { index = mpMeshNode->m_face_list[i].m_point_index[j]; g_Cloth_Buffer[3*i+j].p = m_pX[index]; g_Cloth_Buffer[3*i+j].n = m_pNormal[index]; g_Cloth_Buffer[3*i+j].tu = mpMeshNode->m_face_list[i].m_point_tex[j].x; g_Cloth_Buffer[3*i+j].tv = mpMeshNode->m_face_list[i].m_point_tex[j].y; // g_index_buffer[i*3+j] = index; } } D3DMATERIAL9 mtrl; mtrl.Ambient.r = 1.f; mtrl.Ambient.g = 1.f; mtrl.Ambient.b = 1.f; mtrl.Ambient.a = 0.f; mtrl.Diffuse.r = 1.0f; mtrl.Diffuse.g = 1.0f; mtrl.Diffuse.b = 1.0f; mtrl.Diffuse.a = 1.f; mtrl.Specular.r = 0.f; mtrl.Specular.g = 0.f; mtrl.Specular.b = 0.f; mtrl.Specular.a = 0.f; mtrl.Emissive.r = 0.f; mtrl.Emissive.g = 0.f; mtrl.Emissive.b = 0.f; mtrl.Emissive.a = 0.f; mtrl.Power = 0.0f; RGetDevice()->SetMaterial( &mtrl ); RMtrlMgr* pMtrlMgr = &mpMeshNode->m_pParentMesh->m_mtrl_list_ex; RMtrl* pMtrl = pMtrlMgr->Get_s(mpMeshNode->m_mtrl_id,-1); RGetDevice()->SetTexture( 0, pMtrl->GetTexture() ); RGetDevice()->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); RGetDevice()->SetRenderState( D3DRS_SPECULARENABLE, FALSE ); RGetDevice()->SetRenderState( D3DRS_AMBIENT, 0x00555555 ); RGetShaderMgr()->setAmbient( 0x00555555 ); RGetDevice()->SetRenderState( D3DRS_LIGHTING, TRUE ); RGetDevice()->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE ); RGetDevice()->SetRenderState( D3DRS_ALPHATESTENABLE, FALSE ); RGetDevice()->SetLight( 0, mpLight ); RGetDynamicLightManager()->SetLight( m_pX[0], 1, LIGHT_DISTANCE ); rmatrix Identity; D3DXMatrixIdentity( &Identity ); RGetDevice()->SetTransform( D3DTS_WORLD, &Identity ); RGetDevice()->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE ); RGetDevice()->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); RGetDevice()->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); RGetDevice()->SetRenderState( D3DRS_ZWRITEENABLE, TRUE ); RGetDevice()->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); RGetDevice()->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE ); RGetDevice()->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TEXTURE ); RGetDevice()->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); RGetDevice()->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); RGetDevice()->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID ); RGetDevice()->LightEnable( 0, TRUE ); RGetDevice()->LightEnable( 1, FALSE ); RGetDevice()->SetFVF( RVertexType ); //RGetDevice()->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME ); if( bHardwareBuffer ) { // TODO: 무조건 DISCARD 로 lock할것이 아니라, nooverwrite 로 적절히 낭비되지않도록해주자. VOID* pVertex; if( FAILED( g_hw_Buffer->Lock( 0, mpMeshNode->m_point_num * 3 * sizeof(RVertex), (VOID**)&pVertex, D3DLOCK_DISCARD ))) { mlog(" Fail to Lock Emblem hw buffer.. Check Buffer Size.. \n" ); bHardwareBuffer = false; return; } memcpy( pVertex, g_Cloth_Buffer, mpMeshNode->m_face_num*3 * sizeof(RVertex) ); if( FAILED( g_hw_Buffer->Unlock() )) { mlog(" Fail to unLock Emblem hw buffer.. Check Buffer Size.. \n" ); bHardwareBuffer = false; return; } RGetDevice()->SetStreamSource( 0, g_hw_Buffer, 0, sizeof(RVertex) ); //RGetDevice()->SetIndices( mIndexBuffer); //RGetDevice()->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, mpMeshNode->m_point_num, 0, mpMeshNode->m_face_num ); RGetDevice()->DrawPrimitive(D3DPT_TRIANGLELIST,0,mpMeshNode->m_face_num); } else { //RGetDevice()->DrawIndexedPrimitiveUP( D3DPT_TRIANGLELIST, 0, mpMeshNode->m_point_num, mpMeshNode->m_face_num, g_index_buffer, D3DFMT_INDEX16, g_Cloth_Buffer, sizeof(RVertex) ); RGetDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, mpMeshNode->m_face_num, g_Cloth_Buffer, sizeof(RVertex) ); } RGetDevice()->LightEnable( 0, FALSE ); RGetDevice()->LightEnable( 1, FALSE ); //{ // static testv v[1000]; // for( int i = 0; i < m_nCntP; ++i ) // { // v[2*i].n = m_pX[i]; // v[2*i].c = 0xffffffff; // v[2*i + 1].n = m_pX[i] + mpNormal[i] * 50.f; // v[2*i + 1].c = 0xffffffff; // } // RGetDevice()->SetFVF( testvFVF ); // RGetDevice()->DrawPrimitiveUP( D3DPT_LINELIST, m_nCntP, v, sizeof(testv) ); //} }
void ZCharacterObject::Draw_SetLight(const rvector& vPosition) { // ±¤¿øÁ¤ÀÇ // 0¹ø - ambient : ij¸¯ÅÍÀÇ ±âº» ¹à±â // - diffuse : ¼ø°£ÀûÀÎ ±¤¿ø( ÃÑ·ù¸¦ ¹ß»çÇÒ¶§ Àû¿ë) // 1¹ø - ambient : »ç¿ë¾ÈÇÔ // - diffuse : ¸ÊÀÇ µðÇ»Áî ¶óÀÌÆ® // specular, emit ¼Ó¼ºÀº »ç¿ë¾ÈÇÔ #define CHARACTER_AMBIENT 0.0 D3DLIGHT9 Light; rvector pos; rvector char_pos = vPosition; char_pos.z += 180.f; memset( &Light, 0, sizeof( D3DLIGHT9 )); // ÃʱâÈ // 0¹ø ¶óÀÌÆ® begine Light.Type = D3DLIGHT_POINT; Light.Ambient.r = CHARACTER_AMBIENT; Light.Ambient.g = CHARACTER_AMBIENT; Light.Ambient.b = CHARACTER_AMBIENT; Light.Specular.r = 1.f; Light.Specular.g = 1.f; Light.Specular.b = 1.f; Light.Specular.a = 1.f; if( ZGetConfiguration()->GetVideo()->bDynamicLight && m_bDynamicLight ) { m_vLightColor.x -= 0.03f; m_vLightColor.y -= 0.03f; m_vLightColor.z -= 0.03f; max( m_vLightColor.x, 0.0f ); max( m_vLightColor.y, 0.0f ); max( m_vLightColor.z, 0.0f ); Light.Diffuse.r = m_vLightColor.x; Light.Diffuse.g = m_vLightColor.y; Light.Diffuse.b = m_vLightColor.z; Light.Range = g_CharLightList[m_iDLightType].fRange; float lastTime = m_fTime; m_fTime = timeGetTime(); float lap = m_fTime - lastTime; m_fLightLife -= lap; if( m_fLightLife <= 0.0f ) { m_bDynamicLight = false; m_fLightLife = 0; } } else { m_bDynamicLight = false; m_vLightColor.x = 0.0f; m_vLightColor.y = 0.0f; m_vLightColor.z = 0.0f; } if( IsDoubleGun() ) { if( m_bLeftShot ) GetWeaponTypePos( weapon_dummy_muzzle_flash, &pos ,true); else GetWeaponTypePos( weapon_dummy_muzzle_flash, &pos ); m_bLeftShot = !m_bLeftShot; } else { GetWeaponTypePos( weapon_dummy_muzzle_flash, &pos ); } Light.Position.x = pos.x ; Light.Position.y = pos.y ; Light.Position.z = pos.z ; Light.Attenuation1 = 0.05f; Light.Attenuation2 = 0.001f; if (IsNPC()) { Light.Ambient.r = 0.4f; Light.Ambient.g = 0.4f; Light.Ambient.b = 0.4f; Light.Range = 2000.0f; Light.Attenuation0 = 1.0f; Light.Attenuation1 = 0.0f; Light.Attenuation2 = 0.0f; } // RGetDevice()->SetLight( 0, &Light ); // RGetDevice()->LightEnable( 0, TRUE ); // if( RShaderMgr::mbUsingShader ) // { // RGetShaderMgr()->setLight( 0, &Light ); // RGetShaderMgr()->LightEnable( 0, TRUE ); // } m_pVMesh->SetLight(0,&Light,false); // 0¹ø ¶óÀÌÆ® end // 1¹ø ¶óÀÌÆ® begine ZeroMemory( &Light, sizeof(D3DLIGHT9) ); RLightList* pLightList = 0; RLIGHT* pLight = 0; RLIGHT* pSelectedLight = 0; rvector sunDir; float distance; float SelectedLightDistance = FLT_MAX; pLightList = ZGetGame()->GetWorld()->GetBsp()->GetSunLightList(); int nLight = (int)pLightList->size(); Light.Specular.r = 1.f; Light.Specular.g = 1.f; Light.Specular.b = 1.f; Light.Specular.a = 1.f; if( nLight > 0 ) { // Áß°£¿¡ ¸Ê ÇÈÅ·ÀÌ ¾ÈµÇ¸é.. // ÇØ°¡ ¿©·¯°³À̸é? °Å¸®·Î ¼±ÅÃ.. for( RLightList::iterator iter = pLightList->begin(); iter != pLightList->end(); ++iter ) { pLight = *iter; sunDir = pLight->sPosition - char_pos; distance = D3DXVec3LengthSq( &sunDir ); D3DXVec3Normalize( &sunDir, &sunDir ); RBSPPICKINFO info; if( ZGetGame()->GetWorld()->GetBsp()->Pick( char_pos, sunDir, &info,RM_FLAG_ADDITIVE ) ) { if( distance > D3DXVec3LengthSq(&( char_pos - info.PickPos )) ) { continue; } } if( distance < SelectedLightDistance ) { SelectedLightDistance = distance; pSelectedLight = pLight; } } Light.Type = D3DLIGHT_POINT; Light.Attenuation1 = 0.00001f; if( pSelectedLight != 0 ) { Light.Diffuse.r = pSelectedLight->Color.x * pSelectedLight->fIntensity * 0.15f; Light.Diffuse.g = pSelectedLight->Color.y * pSelectedLight->fIntensity * 0.15f; Light.Diffuse.b = pSelectedLight->Color.z * pSelectedLight->fIntensity * 0.15f; } } SelectedLightDistance = FLT_MAX ; if( pSelectedLight == 0 ) { pLightList = ZGetGame()->GetWorld()->GetBsp()->GetObjectLightList(); // ¿©±â ÃÖÀûÈ°¡ ÂÀ ÇÊ¿äÇÏ´Ù for( RLightList::iterator itor = pLightList->begin(); itor != pLightList->end(); itor++ ) { RLIGHT *pl = *itor; float fDist = Magnitude( pl->sPosition-char_pos ); if( SelectedLightDistance > fDist ) { SelectedLightDistance = fDist; pSelectedLight = pl; } } Light.Type = D3DLIGHT_POINT; Light.Attenuation1 = 0.0025f; if( pSelectedLight != 0 ) { Light.Diffuse.r = pSelectedLight->Color.x * pSelectedLight->fIntensity; Light.Diffuse.g = pSelectedLight->Color.y * pSelectedLight->fIntensity; Light.Diffuse.b = pSelectedLight->Color.z * pSelectedLight->fIntensity; } } if( pSelectedLight != NULL ) { Light.Position = pSelectedLight->sPosition; // Light.Diffuse.r = pSelectedLight->Color.x; // Light.Diffuse.g = pSelectedLight->Color.y; // Light.Diffuse.b = pSelectedLight->Color.z; Light.Range = pSelectedLight->fAttnEnd; m_pVMesh->SetLight(1,&Light,false); // RGetDevice()->SetLight( 1, &Light ); // RGetDevice()->LightEnable( 1, TRUE ); // if( RShaderMgr::mbUsingShader ) // { // RGetShaderMgr()->setLight( 1, &Light ); // RGetShaderMgr()->LightEnable( 1, TRUE ); // RGetShaderMgr()->setLight( 0x00cccccc ); // } } else { m_pVMesh->SetLight(1,NULL,false); // RGetDevice()->LightEnable( 1, FALSE ); // if( RShaderMgr::mbUsingShader ) // { // RGetShaderMgr()->LightEnable( 1, FALSE ); // } } // 1¹ø ¶óÀÌÆ® end RGetShaderMgr()->setAmbient( 0x00cccccc ); RGetDevice()->SetRenderState( D3DRS_LIGHTING, TRUE ); RGetDevice()->SetRenderState( D3DRS_AMBIENT, 0x00cccccc ); }
void ZApplication::OnInvalidate() { RGetShaderMgr()->Release(); if(m_pGameInterface) m_pGameInterface->OnInvalidate(); }