Ejemplo n.º 1
0
bool Material::bind(RenderContext* context)
{

    if( this == context->getBoundMaterial() )
    {
        return false;
    }

    ID3DX11Effect* effect = m_shader->getEffect();



    context->getImmediateContext()->IASetInputLayout( m_layout );


    for(std::map<string, ResourceID>::iterator iter = m_textureRefs.begin(); iter!=m_textureRefs.end(); ++iter)
    {

        ID3DX11EffectVariable* var = effect->GetVariableByName(iter->first.c_str());
        if(var->IsValid())
        {
            ID3DX11EffectShaderResourceVariable* texResource = var->AsShaderResource();
            Texture* tex = TextureManager::singleton()->getTexture(iter->second);
            if(tex)
            {
                texResource->SetResource(tex->getShaderResourceView());
            }
            else {
                texResource->SetResource(0);
            }
        }
    }

    return true;
}
Ejemplo n.º 2
0
	void TestMaterial::ClearState(ID3D11DeviceContext* context) 
	{
		if (texture != 0) {
			ID3DX11EffectShaderResourceVariable* shaderResource = effect->GetVariableByName("diffuseTexture")->AsShaderResource();
			shaderResource->SetResource(0);
		}
	}
Ejemplo n.º 3
0
    void Effect::SetParam(const string& name, Texture* texture) {
        auto it = resourceVars.find(name);
        _ASSERT(it != resourceVars.end());

        ID3DX11EffectShaderResourceVariable* srVar = it->second;
        DXCall(srVar->SetResource(texture->GetSRView()));
    }
Ejemplo n.º 4
0
void CDX11EffectMaterial::ApplyTextures(
	CDX11Renderer* pkRenderer, CMesh* pkMesh)
{
	for (unsigned short us = 0; us < MAX_TEXTURE_SLOTS; ++us)
	{
		ID3DX11EffectShaderResourceVariable* pkShaderResource = 
			m_spEffectData->GetShaderResourceAt(us);
		if (pkShaderResource)
		{
			const CMesh::STextureSlot* pkTextureSlot = 
				pkMesh->GetTextureSlot(us);
			if (pkTextureSlot && pkTextureSlot->m_pkTexture)
			{
				CDX11TextureData2D* pkTextureData = (CDX11TextureData2D*)
					pkTextureSlot->m_pkTexture->GetTextureData();

				if (pkTextureData)
				{
					pkShaderResource->SetResource(
						pkTextureData->GetShaderResourceView());
				}
			}
		}
	}
}
Ejemplo n.º 5
0
bool CD3DEffect::SetTexture(LPCSTR handle, CD3DTexture &texture)
{
  if (m_effect)
  {
    ID3DX11EffectShaderResourceVariable* var = m_effect->GetVariableByName(handle)->AsShaderResource();
    if (var->IsValid())
      return SUCCEEDED(var->SetResource(texture.GetShaderResource()));
  }
  return false;
}
	void DrawDepthMaterial::SetMeshInstanceState(const MeshInstance* meshInstance) const
	{		
		ID3DX11EffectMatrixVariable* mvp = effect->GetVariableByName("transformMatrix")->AsMatrix();
		mvp->SetMatrix(transform);	
		
		effect->GetVariableByName("texDimensions")->SetRawValue(texDimensions, 0, sizeof(float)*2);
		
		ID3DX11EffectShaderResourceVariable* shaderResource = effect->GetVariableByName("depthTexture")->AsShaderResource();
		shaderResource->SetResource(texture->GetShaderResourceView());
	}
Ejemplo n.º 7
0
	void TestMaterial::SetMeshInstanceState(const MeshInstance* meshInstance) const
	{
		float4x4 mvp;
		if (meshInstance) {
			float4x4 meshTransform = meshInstance->GetTransformMatrix();
			matrix4x4 tr = DirectX::XMLoadFloat4x4(&meshTransform);
			matrix4x4 pr = DirectX::XMLoadFloat4x4(&projection);
			pr = DirectX::XMMatrixMultiply(tr, pr);
			DirectX::XMStoreFloat4x4(&mvp, pr); 
			ID3DX11EffectMatrixVariable* mvpVar = effect->GetVariableByName("gWorldViewProj")->AsMatrix();
			mvpVar->SetMatrix((float*)&mvp);
		}

		if (texture != 0) {
			ID3DX11EffectShaderResourceVariable* shaderResource = effect->GetVariableByName("diffuseTexture")->AsShaderResource();
			shaderResource->SetResource(texture->GetShaderResourceView());
		}
	}
Ejemplo n.º 8
0
void EffectSystemD3D11::UpdateTexture2D(int effectID, const char *name, const char *path)
{
	ASSERT_EFFECT(effectID);
	std::string key(path);
	// 检查是否已创建
	if (mTexture2Ds.find(key) == mTexture2Ds.end())
	{
		CreateTexture2D(key);
	}
	// set resource
	ID3D11ShaderResourceView *resource = mTexture2Ds[key];
	ID3DX11EffectShaderResourceVariable *resourceVariable = mEffects[effectID]->GetVariableByName(name)->AsShaderResource();
	if (resourceVariable->IsValid())
	{
		resourceVariable->SetResource(resource);
	}
	else
	{
		LogSystem::GetInstance().Log("effect shader resource「%s」非法", name);
		return;
	}
}
Ejemplo n.º 9
0
void UIDisplay::drawUI( ID3D11DeviceContext* device )
{
    //Setup temp vars
    uint stride = sizeof(FontVertex);
    uint offset = 0;

    device->IASetInputLayout( mInputLayout );
    device->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

    //Set vertex and index buffers
    device->IASetVertexBuffers( 0, 1, &mVB, &stride, &offset );
    device->IASetIndexBuffer( mIB, DXGI_FORMAT_R16_UINT, offset );

    ID3DX11EffectShaderResourceVariable* mfxTex = mFX->GetVariableByName("uiTexture")->AsShaderResource();
    mfxTex->SetResource(mTexture);

    XMMATRIX world = XMMatrixIdentity();

    ID3DX11EffectMatrixVariable* mfxWorld = mFX->GetVariableByName("gWorld")->AsMatrix();
    mfxWorld->SetMatrix(reinterpret_cast<float*>(&world));

    int indices = ( mVertsGenerated / 4 ) * 6;

    D3DX11_TECHNIQUE_DESC techDesc;
    mTechnique->GetDesc( &techDesc );

    for(ushort p = 0; p < techDesc.Passes; ++p)
    {
        mTechnique->GetPassByIndex(p)->Apply(0, device);

        if( mVertsGenerated > 0 ) {
            //Draw the verts we generated wooo
            device->DrawIndexed( indices, 0, 0 );
        }
    }

    mVertsGenerated = 0;
}
Ejemplo n.º 10
0
void h2GBufferDebugDraw::RenderGBuffer() {
	m_Renderer->m_D3d11ImmediateContext->ClearDepthStencilView( m_Renderer->m_DepthBufferDSV, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0 );
	m_Renderer->m_D3d11ImmediateContext->IASetInputLayout( m_PosTexLayout );
	m_Renderer->m_D3d11ImmediateContext->OMSetRenderTargets( 1, &m_Renderer->m_BackbufferRTV, m_Renderer->m_DepthBufferDSV );

	ID3DX11EffectShaderResourceVariable * fxTexSamplerVar;
	fxTexSamplerVar = m_Fx->GetVariableByName( "texSampler" )->AsShaderResource();
	fxTexSamplerVar->SetResource( m_Renderer->m_GBuffer->GetBufferByType( m_CurrentBuffer )->m_SRV );

	unsigned int stride = sizeof( h2RenderingEngine::vertexPosTex_t );
	unsigned int offset = 0;
	m_Renderer->m_D3d11ImmediateContext->IASetVertexBuffers( 0, 1, &m_Renderer->m_FullScrQuadVB, &stride, &offset );

	const h2SceneObject * cameraObj = h2Engine::GetScene()->GetMainCamera();
	const h2Camera * camera = static_cast<h2Camera *>( cameraObj->GetComponent( "h2Camera" ) );
	h2Matrix44 projMatrix = h2Matrix44::OrthographicD3D( m_Renderer->m_Width, m_Renderer->m_Height, camera->zNear, camera->zFar );

	ID3DX11EffectMatrixVariable * fxPVar = m_Fx->GetVariableByName( "orthoProjection" )->AsMatrix();
	fxPVar->SetMatrix( projMatrix.GetDataPtr() );

	ID3DX11EffectTechnique * tech = nullptr;
	switch ( m_CurrentBuffer ) {
	case DEPTH_BUFFER:
		tech = m_Fx->GetTechniqueByName( "DepthBufferDebugDrawTech" );
		break;
	case NORMAL_BUFFER:
		tech = m_Fx->GetTechniqueByName( "NormalBufferDebugDrawTech" );
		break;
	}

	ID3DX11EffectPass * pass = tech->GetPassByIndex( 0 );
	pass->Apply( 0, m_Renderer->m_D3d11ImmediateContext );

	m_Renderer->m_D3d11ImmediateContext->Draw( 6, 0 );

	ID3D11ShaderResourceView * emptySRV = nullptr;
	m_Renderer->m_D3d11ImmediateContext->PSSetShaderResources(0, 1, &emptySRV);
}
Ejemplo n.º 11
0
void EndOfDirectX11::Render()
{
	if( d3dContext_ == 0 )
	{
		return;
	}

	float clearColor[] = { 0.0f, 0.0f, 0.25f, 1.0f };
	d3dContext_->ClearRenderTargetView( backBufferTarget_, clearColor );
	d3dContext_->ClearDepthStencilView( depthStencilView_, D3D11_CLEAR_DEPTH, 1.0f, 0 );     

	unsigned int stride = sizeof( VertexPos );
	unsigned int offset = 0;

	d3dContext_->IASetInputLayout( inputLayout_ );
	d3dContext_->IASetVertexBuffers( 0, 1, &vertexBuffer_, &stride, &offset );
	d3dContext_->IASetIndexBuffer( indexBuffer_, DXGI_FORMAT_R16_UINT, 0 );
	d3dContext_->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

	ID3DX11EffectShaderResourceVariable * colorMap = 0;
	colorMap = effect_->GetVariableByName( "colorMap" )->AsShaderResource();
	colorMap->SetResource( colorMap_ );

	ID3DX11EffectShaderResourceVariable* colorMap2;
    colorMap2 = effect_->GetVariableByName( "secondMap" )->AsShaderResource( );
    colorMap2->SetResource( secondMap_ );

	ID3DX11EffectSamplerVariable * samplerState = 0;
	samplerState = effect_->GetVariableByName( "colorSampler" )->AsSampler();
	samplerState->SetSampler( 0, samplerState_ );

	ID3DX11EffectMatrixVariable * worldMatrix = 0;
	worldMatrix = effect_->GetVariableByName( "worldMatrix" )->AsMatrix();
	worldMatrix->SetMatrix( ( float * )&worldMat_ );

	ID3DX11EffectMatrixVariable * viewMatrix = 0;
	viewMatrix = effect_->GetVariableByName( "viewMatrix" )->AsMatrix();
	viewMatrix->SetMatrix( ( float * )&viewMatrix_ );

	ID3DX11EffectMatrixVariable * projMatrix = 0;
	projMatrix = effect_->GetVariableByName( "projMatrix" )->AsMatrix();
	projMatrix->SetMatrix( ( float * )&projMatrix_ );

	ID3DX11EffectTechnique * colorInvTechnique = 0;
	colorInvTechnique = effect_->GetTechniqueByName( "MultiTexture" );

	D3DX11_TECHNIQUE_DESC techDesc;
	colorInvTechnique->GetDesc( &techDesc );

	for( unsigned int p = 0; p < techDesc.Passes; ++p )
	{
		ID3DX11EffectPass * pass = colorInvTechnique->GetPassByIndex( p );

		if( pass != 0 )
		{
			pass->Apply( 0, d3dContext_ );
			d3dContext_->DrawIndexed( 36, 0, 0 );
		}
	}

	swapChain_->Present( 0, 0 );
}