void gkRendPipe_ShadowMapGen::Prepare( gkRenderSequence* renderSeq )
{
    gkRendererD3D9::RS_SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE);
    gkRendererD3D9::RS_SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE);
    gkRendererD3D9::RS_SetRenderState( D3DRS_ALPHATESTENABLE, FALSE);
    gkRendererD3D9::RS_SetRenderState( D3DRS_ZENABLE, TRUE );
    gkRendererD3D9::RS_SetRenderState( D3DRS_ZWRITEENABLE, TRUE);
    gkRendererD3D9::RS_SetRenderState( D3DRS_COLORWRITEENABLE, 0x0 );
    float slopebia = g_pRendererCVars->r_shadowSlopeBias;
    gkRendererD3D9::RS_SetRenderState( D3DRS_SLOPESCALEDEPTHBIAS, F2DW( slopebia ));
    gkRendererD3D9::RS_SetRenderState( D3DRS_DEPTHBIAS, F2DW( 0 ));
}
Пример #2
0
HRESULT KModelWater::Render()
{

	SetMaterial(0);     //设置水面材质
	
	//	DrawMeshSubset(m_pWaterDn,0);   //绘制水底

	g_pd3dDevice->SetTexture(0, m_pBumpMapTexture);		//设置水面bump
	g_pd3dDevice->SetTexture(1, m_pWaterTex);			//水面纹理
	g_pd3dDevice->SetTexture(2, m_pSkyCubeTex);         //天空盒的折射纹理

//	float K = sinf( timeGetTime() * -0.002f) * (1+1);   //使bump纹理波动,产生水波细纹的效果(此部分功能暂未完成)
//	float H = cosf( timeGetTime() * -0.002f) * (1+1);
	float K = 1.0f;
	float H = 0.0f;

	g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_BUMPENVMAP );
	g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
	g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_CURRENT );
	g_pd3dDevice->SetTextureStageState( 0, D3DTSS_BUMPENVMAT00,   F2DW(K) );
	g_pd3dDevice->SetTextureStageState( 0, D3DTSS_BUMPENVMAT01,   F2DW(H) );
	g_pd3dDevice->SetTextureStageState( 0, D3DTSS_BUMPENVMAT10,   F2DW(H) );
	g_pd3dDevice->SetTextureStageState( 0, D3DTSS_BUMPENVMAT11,   F2DW(K) );
	g_pd3dDevice->SetTextureStageState( 0, D3DTSS_BUMPENVLSCALE,  F2DW(4.0f) );
	g_pd3dDevice->SetTextureStageState( 0, D3DTSS_BUMPENVLOFFSET, F2DW(4.0f) );  

	g_pd3dDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 0 );
	g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
	g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
	g_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG2 );
	g_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG2,  D3DTA_CURRENT );

	g_pd3dDevice->SetTextureStageState( 2, D3DTSS_TEXTURETRANSFORMFLAGS,D3DTTFF_COUNT2);
	g_pd3dDevice->SetTextureStageState( 2, D3DTSS_COLOROP,  D3DTOP_BLENDCURRENTALPHA );
	g_pd3dDevice->SetTextureStageState( 2, D3DTSS_COLORARG1, D3DTA_TEXTURE );
	g_pd3dDevice->SetTextureStageState( 2, D3DTSS_COLORARG2, D3DTA_CURRENT );
	g_pd3dDevice->SetTextureStageState( 2, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG2 );
	g_pd3dDevice->SetTextureStageState( 2, D3DTSS_ALPHAARG2,  D3DTA_CURRENT );
	g_pd3dDevice->SetTextureStageState( 2, D3DTSS_TEXCOORDINDEX,D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
	g_pd3dDevice->SetTextureStageState( 2, D3DTSS_TEXTURETRANSFORMFLAGS,D3DTTFF_COUNT3);
	g_pd3dDevice->SetSamplerState( 2, D3DSAMP_ADDRESSU,   D3DTADDRESS_CLAMP );
	g_pd3dDevice->SetSamplerState( 2, D3DSAMP_ADDRESSV,   D3DTADDRESS_CLAMP );
	g_pd3dDevice->SetSamplerState( 2, D3DSAMP_ADDRESSW,   D3DTADDRESS_CLAMP );  

	g_pd3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE); 
	/*	UINT uPasses;
	m_pEffect->Begin(&uPasses, 0);

	for(UINT uPass = 0; uPass < uPasses; uPass++)
	{
	m_pEffect->Pass(uPass);  */
	m_pWaterUp->DrawSubset(0);
	/*	}

	m_pEffect->End();*/

	//每计数400次产生一个涟漪纹,(功能测试)
	static int count		  = 0;			
	if(count%400==0){
		Ripple.Drop();  
		count = 0;
	}
	count++;	

	return S_OK;
}
Пример #3
0
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Called once per frame, the call is the entry point for 3d
//       rendering. This function sets up render states, clears the
//       viewport, and renders the scene.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::Render()
{
    // Begin the scene
    if( FAILED( m_pd3dDevice->BeginScene() ) )
        return S_OK;

    // Render the background
    m_pd3dDevice->SetTexture( 0, m_pBackgroundTexture );
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
    m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_DISABLE );

    m_pd3dDevice->SetVertexShader( D3DFVF_BACKGROUNDVERTEX );
    m_pd3dDevice->SetStreamSource( 0, m_pBackgroundVB, sizeof(BACKGROUNDVERTEX) );
    m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

    // Render the lens
    m_pd3dDevice->SetTexture( 0, m_pBumpMapTexture );
    m_pd3dDevice->SetTexture( 1, m_pBackgroundTexture );

    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_BUMPENVMAP );
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_CURRENT );
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );

    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_BUMPENVMAT00,   F2DW(0.2f) );
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_BUMPENVMAT01,   F2DW(0.0f) );
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_BUMPENVMAT10,   F2DW(0.0f) );
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_BUMPENVMAT11,   F2DW(0.2f) );
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_BUMPENVLSCALE,  F2DW(1.0f) );
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_BUMPENVLOFFSET, F2DW(0.0f) );

    m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
    m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
    m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
    m_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );

    // Generate texture coords depending on objects camera space position
    D3DXMATRIX mat;
    mat._11 = 0.5f; mat._12 = 0.0f;
    mat._21 = 0.0f; mat._22 =-0.5f;
    mat._31 = 0.0f; mat._32 = 0.0f;
    mat._41 = 0.5f; mat._42 = 0.5f;

    // Scale-by-z here
    D3DXMATRIX matView, matProj;
    m_pd3dDevice->GetTransform( D3DTS_VIEW,       &matView );
    m_pd3dDevice->GetTransform( D3DTS_PROJECTION, &matProj );
    D3DXVECTOR3 vEyePt( matView._41, matView._42, matView._43 );
    FLOAT       z = D3DXVec3Length( &vEyePt );
    mat._11 *= ( matProj._11 / ( matProj._33 * z + matProj._34 ) );
    mat._22 *= ( matProj._22 / ( matProj._33 * z + matProj._34 ) );

    m_pd3dDevice->SetTransform( D3DTS_TEXTURE1, &mat );
    m_pd3dDevice->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
    m_pd3dDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION | 1);

    // Position the lens
    D3DXMATRIX matWorld;
    D3DXMatrixTranslation( &matWorld, 0.7f * (1000.0f-256.0f)*m_fLensX,
                                      0.7f * (1000.0f-256.0f)*m_fLensY,
                                      0.0f );
    m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

    m_pd3dDevice->SetVertexShader( D3DFVF_BUMPVERTEX );
    m_pd3dDevice->SetStreamSource( 0, m_pLensVB, sizeof(BUMPVERTEX) );

    // Verify that the texture operations are possible on the device
    DWORD dwNumPasses;
    if( FAILED( m_pd3dDevice->ValidateDevice( &dwNumPasses ) ) )
    {
        // The right thing to do when device validation fails is to try
        // a different rendering technique.  This sample just warns the user.
        m_bDeviceValidationFailed = TRUE;
    }

    // Render the lens
    m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

    // Output statistics
    m_pFont->DrawText( 2,  0, D3DCOLOR_ARGB(255,255,255,0), m_strFrameStats );
    m_pFont->DrawText( 2, 20, D3DCOLOR_ARGB(255,255,255,0), m_strDeviceStats );

    if( m_bDeviceValidationFailed )
    {
        m_pFont->DrawText( 2, 40, D3DCOLOR_ARGB(255,255,0,0), 
            _T("Warning: Device validation failed.  Rendering may not look right.") );
    }

    // End the scene.
    m_pd3dDevice->EndScene();

    return S_OK;
}
Пример #4
0
void HeightMap::Render( )
{
	if(bQuadTree) QuadTreeDraw( );

	if (wireMode) GameManager::GetDevice( )->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);

	GameManager::GetDevice( )->SetTexture(0, pTexNormal);
	GameManager::GetDevice( )->SetTexture(1, pTexDiffuse);
	GameManager::GetDevice( )->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC);
	GameManager::GetDevice( )->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC);
	GameManager::GetDevice( )->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
	GameManager::GetDevice( )->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);

	// Set luminance controls.This is only needed when using
	// a bump map that contains luminance, and when the 
	// D3DTOP_BUMPENVMAPLUMINANCE texture blending operation is
	// being used.
	//
	// Note These calls rely on the following inline shortcut function:
	// inline DWORD F2DW( FLOAT f ) { return *((DWORD*) &f); }
	GameManager::GetDevice( )->SetTextureStageState(0, D3DTSS_BUMPENVLSCALE, F2DW(0.5f));
	GameManager::GetDevice( )->SetTextureStageState(0, D3DTSS_BUMPENVLOFFSET, F2DW(0.0f));
	//
	//GameManager::GetDevice( )->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_BUMPENVMAPLUMINANCE);
	GameManager::GetDevice( )->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DOTPRODUCT3);
	//GameManager::GetDevice( )->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BUMPENVMAP);
	GameManager::GetDevice( )->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
	GameManager::GetDevice( )->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TEXTURE);
	//GameManager::GetDevice( )->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT);


	GameManager::GetDevice( )->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
	GameManager::GetDevice( )->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
	GameManager::GetDevice( )->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);

	GameManager::GetDevice( )->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
	GameManager::GetDevice( )->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
	GameManager::GetDevice( )->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);


	GameManager::GetDevice( )->SetTransform(D3DTS_WORLD, &world);
	GameManager::GetDevice( )->SetRenderState(D3DRS_LIGHTING, true);
	GameManager::GetDevice( )->SetMaterial(&material);
	//
	GameManager::GetDevice( )->SetStreamSource(0, vertexBuffer, 0, sizeof(FVF_PositionNormalTexture));
	GameManager::GetDevice( )->SetFVF(FVF_PositionNormalTexture::FVF);
	GameManager::GetDevice( )->SetIndices(indexBuffer);
	GameManager::GetDevice( )->DrawIndexedPrimitive(
		D3DPT_TRIANGLELIST,
		0,
		0,
		vertexCount,
		0,
		triangleCount);

	GameManager::GetDevice( )->SetTexture(0, nullptr);
	GameManager::GetDevice( )->SetTexture(1, nullptr);
	GameManager::GetDevice( )->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);	//원상 복귀(이게 디폴트)
	GameManager::GetDevice( )->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);	//원상 복귀(이게 디폴트)
	GameManager::GetDevice( )->SetRenderState(D3DRS_ALPHABLENDENABLE, false);

	if (wireMode) GameManager::GetDevice( )->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);


	Debuging( );
}
Пример #5
0
void CParticleSystem::m_Paint(void *arg1, void *arg2, void *arg3)
{
  CRenderLib *RL;
  HRESULT hr;
  ParticleVBVertex *l_Particles;
  AD_Matrix l_identity;
  int32 numLive, i, alpha;
  DWORD zw, ab;

  RL=(CRenderLib *)arg1;
  if (!RL) return;

  hr=RL->p_Device->GetRenderState(D3DRS_ALPHABLENDENABLE, &ab);
  hr=RL->p_Device->GetRenderState(D3DRS_ZWRITEENABLE, &zw);

  // matrice identita', i particle vivono gia' nello spazio mondo!!!
  mat_identity(&l_identity);
  RL->m_SetWorldMatrix(&l_identity);

  hr=RL->p_Device->SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE);
  hr=RL->p_Device->SetRenderState(D3DRS_POINTSCALEENABLE,  TRUE);
  hr=RL->p_Device->SetRenderState(D3DRS_POINTSIZE,     F2DW(p_Attenuation0));
  hr=RL->p_Device->SetRenderState(D3DRS_POINTSIZE_MIN, F2DW(0.0f));
  //RL->p_Device->SetRenderState(D3DRS_POINTSIZE_MAX, F2DW(50.0f));
  hr=RL->p_Device->SetRenderState(D3DRS_POINTSCALE_A,  F2DW(p_Attenuation1));
  hr=RL->p_Device->SetRenderState(D3DRS_POINTSCALE_B,  F2DW(p_Attenuation2));
  hr=RL->p_Device->SetRenderState(D3DRS_POINTSCALE_C,  F2DW(p_Attenuation3));
  hr=RL->p_Device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
  hr=RL->p_Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
  hr=RL->p_Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
  hr=RL->p_Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
  // SERVE SENNO' SONO CAZZI
  hr=RL->p_Device->SetRenderState(D3DRS_LIGHTING, FALSE);
  hr=RL->p_Device->SetRenderState(D3DRS_FOGENABLE, FALSE);

  hr=RL->p_Device->SetTexture(0, p_Texture->p_HWSurfaces[0]);
  hr=RL->p_Device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
  hr=RL->p_Device->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
  hr=RL->p_Device->SetTextureStageState(0, D3DTSS_COLOROP,   D3DTOP_MODULATE);
  hr=RL->p_Device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
  hr=RL->p_Device->SetTextureStageState(0, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG1);
  hr=RL->p_Device->SetTexture(1, NULL);
  hr=RL->p_Device->SetTextureStageState(1, D3DTSS_COLOROP,   D3DTOP_DISABLE);
  hr=RL->p_Device->SetTextureStageState(1, D3DTSS_ALPHAOP,   D3DTOP_DISABLE);
  hr=RL->p_Device->SetTexture(2, NULL);
  hr=RL->p_Device->SetTextureStageState(2, D3DTSS_COLOROP,   D3DTOP_DISABLE);
  hr=RL->p_Device->SetTextureStageState(2, D3DTSS_ALPHAOP,   D3DTOP_DISABLE);

  // Set up the vertex buffer to be rendered
  RL->p_Device->SetStreamSource(0, p_VertexBuffer, sizeof(ParticleVBVertex));
  RL->p_Device->SetVertexShader(FVF_PARTICLE);

begin:
  //hr=p_VertexBuffer->Lock(0, 0, (BYTE **)&l_Particles, D3DLOCK_NOOVERWRITE);
  hr=p_VertexBuffer->Lock(0, 0, (BYTE **)&l_Particles, 0);
  if (hr!=0) goto begin;

  numLive=0;

  if (p_FadedParticles<=0)
    for (i=0; i<p_MaxParticles; i++)
	{
	  // lock e paint con drawprimitve
	  if (p_Particles[i].age > 0)
	  {
        vect_copy(&p_Particles[i].pos, &l_Particles[numLive].pos);
        l_Particles[numLive].color=0xffffffff;
        numLive++;
	  }
	}
  else
  {
	float4 h=p_FadedParticles*p_Life;
	float4 invLife=255.0f/(p_Life-h);
	float4 fStart=0.08f*p_Life;

    for (i=0; i<p_MaxParticles; i++)
	{
	  // lock e paint con drawprimitve
	  if (p_Particles[i].age > 0)
	  {
        vect_copy(&p_Particles[i].pos, &l_Particles[numLive].pos);
		if (p_Particles[i].age<=fStart)
		{
		   alpha=(int32)(255.0f*p_Particles[i].age/fStart);
		}
		else
		if (p_Particles[i].age<=h) alpha=255;
		else
		{
          alpha=((int32)((p_Particles[i].age-h)*invLife)) & 0xFF;
	      alpha=255-alpha;
		}
        //l_Particles[numLive].color=0x00ffffff | (alpha <<24);
        //l_Particles[numLive].color=(bb) | (gg<<8) | (rr<<16) | (alpha <<24);
        l_Particles[numLive].color=p_Particles[numLive].color | (alpha <<24);
        numLive++;
	  }
	}
  }
again:
  hr=p_VertexBuffer->Unlock();
  if (hr!=0) goto again;

  if (numLive>0)
	 hr=RL->p_Device->DrawPrimitive(D3DPT_POINTLIST, 0, numLive);
  hr=RL->p_Device->SetRenderState(D3DRS_POINTSPRITEENABLE, FALSE);
  hr=RL->p_Device->SetRenderState(D3DRS_POINTSCALEENABLE,  FALSE);
  hr=RL->p_Device->SetRenderState(D3DRS_ZWRITEENABLE, zw);
  hr=RL->p_Device->SetRenderState(D3DRS_ALPHABLENDENABLE, ab);
}
Пример #6
0
	void render(const ProceduralEffect &e, float width, float height, bool offsetTarget)
	{
        GFX_TRACE_SCOPE("Storm3D_ProceduralManager::render");
		GfxDevice& device = storm.GetD3DDevice();
		
		if(e.texture1)
			e.texture1->Apply(1);
		if(e.texture2)
			e.texture2->Apply(3);

		if(offsetTarget)
		{
			if(e.distortion1)
				e.distortion1->Apply(0);
			if(e.distortion2)
				e.distortion2->Apply(2);

			if(!e.distortion1 || !e.distortion2 || !e.effect.enableDistortion)
				return;
		}
		else
		{
			if(e.offset1)
				e.offset1->Apply(0);
			if(e.offset2)
				e.offset2->Apply(2);
		}

		assert(vshader && pshader);
		vshader->apply();

		float constants[8 * 4];
		const TexCoord &c1 = (offsetTarget) ? e.displaceCoord1 : e.coord1;
		const TexCoord &c2 = (offsetTarget) ? e.displaceCoord2 : e.coord2;

		constants[0 + 0] = c1.offsetFactor.x;
		constants[0 + 1] = c1.offsetFactor.y;
		constants[4 + 0] = c1.offsetOffset.x;
		constants[4 + 1] = c1.offsetOffset.y;
		constants[8 + 0] = c1.baseFactor.x;
		constants[8 + 1] = c1.baseFactor.y;
		constants[12 + 0] = c1.baseOffset.x;
		constants[12 + 1] = c1.baseOffset.y;
		constants[16 + 0] = c2.offsetFactor.x;
		constants[16 + 1] = c2.offsetFactor.y;
		constants[20 + 0] = c2.offsetOffset.x;
		constants[20 + 1] = c2.offsetOffset.y;
		constants[24 + 0] = c2.baseFactor.x;
		constants[24 + 1] = c2.baseFactor.y;
		constants[28 + 0] = c2.baseOffset.x;
		constants[28 + 1] = c2.baseOffset.y;

		device.SetVertexShaderConstantF(0, constants, 8);

		float scale1 = (offsetTarget) ? e.effect.distortion1.offset.scale.x : e.effect.source1.offset.scale.x;
		float scale2 = (offsetTarget) ? e.effect.distortion2.offset.scale.x : e.effect.source2.offset.scale.x;
		device.SetTextureStageState(1, D3DTSS_BUMPENVMAT00, F2DW(scale1));
		device.SetTextureStageState(1, D3DTSS_BUMPENVMAT01, F2DW(0.f));
		device.SetTextureStageState(1, D3DTSS_BUMPENVMAT10, F2DW(0.f));
		device.SetTextureStageState(1, D3DTSS_BUMPENVMAT11, F2DW(scale1));
		device.SetTextureStageState(3, D3DTSS_BUMPENVMAT00, F2DW(scale2));
		device.SetTextureStageState(3, D3DTSS_BUMPENVMAT01, F2DW(0.f));
		device.SetTextureStageState(3, D3DTSS_BUMPENVMAT10, F2DW(0.f));
		device.SetTextureStageState(3, D3DTSS_BUMPENVMAT11, F2DW(scale2));

		if(offsetTarget)
		{
			float scale = (scale1 + scale2) * .25f;
			float c2[4] = { scale, scale, scale, scale };
			device.SetPixelShaderConstantF(2, c2, 1);

			poffsetShader->apply();
		}
		else
		{
			pshader->apply();
		}
	
		vbuffer->apply(device, 0);
		ibuffer->render(device, 2, 4, 0);

		device.SetPixelShader(0);
	}
void gkRendPipe_ShadowMapGen::End( gkRenderSequence* renderSeq )
{
    gkRendererD3D9::RS_SetRenderState( D3DRS_COLORWRITEENABLE, 15 );
    gkRendererD3D9::RS_SetRenderState( D3DRS_SLOPESCALEDEPTHBIAS, F2DW( 0 ));
}
Пример #8
0
void COperator::Render()
{
	rd::CRenderDevice * pRender = rd::CRenderDevice::GetInstance();
	LPDIRECT3DDEVICE9 pDevice = pRender->GetRawDevice();
	rd::CRenderDevice::Layer3D * pLayer3D = pRender->GetLayer3D();
	

	//if ( m_eEditState != EES_SET_BLOCK_LOGIC_HEIGHT )
	//{
	// self specific transform
	pRender->GetRawDevice()->SetTransform(D3DTS_WORLD,&this->GetAbsolute());
	
	pLayer3D->SetShader(m_dwShaderHandle);
	
	static D3DXVECTOR3 vertex[4];
	static D3DXVECTOR2 uv0[4];
	static DWORD color[4];

	// Use depth bias
	pDevice->SetRenderState( D3DRS_SLOPESCALEDEPTHBIAS, F2DW(0.0f) );
	pDevice->SetRenderState( D3DRS_DEPTHBIAS, F2DW(-.012f) );
	
	// draw brush
	if ( this->GetDrawBrush() )
	{
		if ( this->GetGridIndexHot() != INVALID  )
		{
			DWORD brushSize = this->GetBrushSize();

			//DWORD dwCnt = 4*this->GetBrushSize()*this->GetBrushSize();
			DWORD dwCnt = 4 * brushSize * brushSize;

			if ( dwCnt == 0 ) 
				dwCnt = 1;
			
			DWORD terrianWidth = CTileEditApp::GetInstance()->GetTerrainMesh()->GetWidth();
			//DWORD dwGridIndex = this->GetGridIndexHot() - this->GetBrushSize() - this->GetBrushSize() * CTileEditApp::GetInstance()->GetTerrainMesh()->GetWidth();
			DWORD dwGridIndex = this->GetGridIndexHot() - brushSize - brushSize * terrianWidth;

			for ( DWORD j = 0; j < dwCnt; j++)
			{
				if ( j )
				{
					if ( !(j % (2 * this->GetBrushSize())) ) 
						dwGridIndex += CTileEditApp::GetInstance()->GetTerrainMesh()->GetWidth() - 2*this->GetBrushSize() + 1;
					else
						++dwGridIndex;
				}
				
				if ( dwGridIndex < 0 || dwGridIndex > CTileEditApp::GetInstance()->GetTerrainMesh()->GetWidth() * CTileEditApp::GetInstance()->GetTerrainMesh()->GetDepth() )
				{
					continue;
				}
				


				CTerrainMesh::SGrid & s = CTileEditApp::GetInstance()->GetTerrainMesh()->GetGrid(dwGridIndex);
				
				vertex[0] = CTileEditApp::GetInstance()->GetTerrainMesh()->GetVertex(s.dwVertexIndex[0]).vPosition;
				
				vertex[1] = CTileEditApp::GetInstance()->GetTerrainMesh()->GetVertex(s.dwVertexIndex[3]).vPosition;
				
				vertex[2] = CTileEditApp::GetInstance()->GetTerrainMesh()->GetVertex(s.dwVertexIndex[1]).vPosition;
				
				vertex[3] = CTileEditApp::GetInstance()->GetTerrainMesh()->GetVertex(s.dwVertexIndex[2]).vPosition;

				//////////////////////////////////////////////////////////////////////////
				

				color[0] = 0xff0000ff;
				color[1] = 0xff0000ff;
				color[2] = 0xff0000ff;
				color[3] = 0xff0000ff;
				
				uv0[0] = D3DXVECTOR2(0.0f,0.0f);
				uv0[1] = D3DXVECTOR2(0.0f,0.0f);
				uv0[2] = D3DXVECTOR2(0.0f,0.0f);
				uv0[3] = D3DXVECTOR2(0.0f,0.0f);
				
				pLayer3D->DrawTriangleStrip(2, vertex, NULL, color, uv0,NULL);
			}
		}
		
	//}

	// turn off depth bias
	pDevice->SetRenderState( D3DRS_SLOPESCALEDEPTHBIAS, F2DW(0.0f) );
	pDevice->SetRenderState( D3DRS_DEPTHBIAS, F2DW(0.0f) );
	}
	
	// warning  object must be drawn after tools ( tools needs identity matrix !)
	
	// pass to tools
	//switch ( m_eEditState ) 
	//{
	/*case EES_SET_BLOCK_TYPE:
		{
			m_toolSetBlockType.Render();
		}
	break;*/
	
	/*case EES_SET_BLOCK_MASK:
		{
			m_toolSetModel.Render();
		}
	break;*/

	//case EES_SET_BLOCK_LOGIC_HEIGHT:
	//	{
	//		m_toolSetBlockLogicHeight.Render();
	//	}
	//break;
	//}
	
	// render the model
	if ( m_pObject )
		m_pObject->GetFace()->Render();
	
	ISceneNode::Render();
}
Пример #9
0
		DEBUGSTRING("Your computer has no high resolution performance counter available.\n"
			"Some MGE features or plugins will not function correctly.\n");
	}
	MWSEpipe=pipe;
}

void UpdateFogRange() {
	DECLARE_MWBRIDGE

	if (UsingDistantLand && DL_HasStatics()) {
		//Set fog end based on water height
		if (mwBridge->IsAboveWater()) {
			if (mwBridge->CellHasWeather()) {
				RealDevice->SetRenderState(D3DRS_FOGSTART, F2DW(DistantFogStart()));
				RealDevice->SetRenderState(D3DRS_FOGEND, F2DW(DistantFogEnd()));
				RealDevice->SetRenderState (D3DRS_FOGDENSITY, F2DW(1/DistantFogEnd ()));
			} else {
				RealDevice->SetRenderState(D3DRS_FOGSTART, F2DW(InteriorFogStart()));
				RealDevice->SetRenderState(D3DRS_FOGEND, F2DW(InteriorFogEnd()));
				RealDevice->SetRenderState (D3DRS_FOGDENSITY, F2DW(1/InteriorFogEnd ()));
			}
		} else {
			RealDevice->SetRenderState(D3DRS_FOGSTART, F2DW(UnderwaterFogStart()));
			RealDevice->SetRenderState(D3DRS_FOGEND, F2DW(UnderwaterFogEnd()));
			RealDevice->SetRenderState (D3DRS_FOGDENSITY, F2DW(1/UnderwaterFogEnd ()));
		}
	} else {
		RealDevice->SetRenderState(D3DRS_FOGSTART, F2DW(StandardFogStart()));
		RealDevice->SetRenderState(D3DRS_FOGEND, F2DW(StandardFogEnd()));
	}
}
Пример #10
0
void CD3D_Device::SetDefaultRenderStates()
{
	// Basic Render State defaults...
	if (m_ExtraDevCaps.m_bUsingTableFog)
	{
		D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_FOGTABLEMODE,  D3DFOG_LINEAR));
		D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_NONE));
	}
	else
	{
		D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR));
		D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_FOGTABLEMODE,  D3DFOG_NONE));
	}

//	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_EDGEANTIALIAS, FALSE));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, F2DW(0.0f)));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_DEPTHBIAS, F2DW(0.0f)));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_SPECULARENABLE, FALSE));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_DITHERENABLE, TRUE));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_FILLMODE, g_CV_Wireframe ? D3DFILL_WIREFRAME : D3DFILL_SOLID));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_COLORVERTEX, FALSE));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_VERTEXBLEND, D3DVBF_DISABLE));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_NORMALIZENORMALS,FALSE));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_CLIPPING, TRUE));

	// HW Transform & Light...
	D3D_CALL(m_pD3DDevice->SetSoftwareVertexProcessing(((g_Device.GetDeviceCaps()->DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0) ? 1 : 0));

	// Setup Material (for D3D lighting)...
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_LIGHTING,FALSE));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE,D3DMCS_MATERIAL));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE,D3DMCS_MATERIAL));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_EMISSIVEMATERIALSOURCE,D3DMCS_MATERIAL));
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_SPECULARMATERIALSOURCE,D3DMCS_MATERIAL));

	// Texture Stage States...
	for(uint32 nCurrStage = 0; nCurrStage < 4; nCurrStage++)
	{
		D3D_CALL(m_pD3DDevice->SetTextureStageState(nCurrStage, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU | nCurrStage));
		D3D_CALL(m_pD3DDevice->SetTextureStageState(nCurrStage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE));
		D3D_CALL(m_pD3DDevice->SetSamplerState(nCurrStage, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP));
		D3D_CALL(m_pD3DDevice->SetSamplerState(nCurrStage, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP));

		D3D_CALL(PD3DDEVICE->SetSamplerState(nCurrStage, D3DSAMP_MAXANISOTROPY, g_CV_Anisotropic.m_Val ? g_CV_Anisotropic.m_Val : 1));

		// check for device caps anisotropic filter for min filter
		if ((m_DeviceCaps.VertexTextureFilterCaps & D3DPTFILTERCAPS_MINFANISOTROPIC) && (g_CV_Anisotropic.m_Val))
		{
			D3D_CALL(PD3DDEVICE->SetSamplerState(nCurrStage, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC));
		}
		else
		{
			D3D_CALL(PD3DDEVICE->SetSamplerState(nCurrStage, D3DSAMP_MINFILTER, g_CV_Bilinear.m_Val ? D3DTEXF_LINEAR : D3DTEXF_POINT));
		}

		// check for device cpas anistropic filter for mag filter
		if ((m_DeviceCaps.VertexTextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC) && (g_CV_Anisotropic.m_Val))
		{
			D3D_CALL(PD3DDEVICE->SetSamplerState(nCurrStage, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC));
		}
		else
		{
			D3D_CALL(PD3DDEVICE->SetSamplerState(nCurrStage, D3DSAMP_MAGFILTER, g_CV_Bilinear.m_Val ? D3DTEXF_LINEAR : D3DTEXF_POINT));
		}

		D3D_CALL(PD3DDEVICE->SetSamplerState(nCurrStage, D3DSAMP_MIPFILTER, g_CV_Trilinear.m_Val ? D3DTEXF_LINEAR : D3DTEXF_POINT));

		d3d_DisableTexture(nCurrStage);
	}

	//setup a default blend
	D3D_CALL(m_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE));
	D3D_CALL(m_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE));
	D3D_CALL(m_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE));
	D3D_CALL(m_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE));
	D3D_CALL(m_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE));
	D3D_CALL(m_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE));
	D3D_CALL(m_pD3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE));
	D3D_CALL(m_pD3DDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE));
	D3D_CALL(m_pD3DDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT));
	D3D_CALL(m_pD3DDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE));
	D3D_CALL(m_pD3DDevice->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE));
	D3D_CALL(m_pD3DDevice->SetTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_CURRENT));

	//turn off alpha ref
	D3D_CALL(m_pD3DDevice->SetRenderState(D3DRS_ALPHAREF, 0));

	// Setup the Material...This should be set on the per piece basis, but for the fall release I'm just setting it the once and moving on...
	D3DMATERIAL9 Material;
	D3DCOLORVALUE MatColor1; MatColor1.r = 1.0f; MatColor1.g = 1.0f; MatColor1.b = 1.0f; MatColor1.a = 1.0f;
	D3DCOLORVALUE MatColor2; MatColor2.r = 0.0f; MatColor2.g = 0.0f; MatColor2.b = 0.0f; MatColor2.a = 0.0f;
	Material.Diffuse  = MatColor1; Material.Ambient  = MatColor1;
	Material.Specular = MatColor2; Material.Emissive = MatColor2; Material.Power = 0.0f;
	g_RenderStateMgr.SetMaterial(Material);

	assert(m_pD3DDevice);
}