Exemple #1
0
bool Prism::Surface::SetTexture(const std::string& aResourceName, Texture* aTexture)
{
	DL_ASSERT_EXP(aTexture != nullptr
		, CU::Concatenate("Shader resource ( %s ) tried to use invalid texture", aResourceName.c_str()));

	ID3DX11EffectShaderResourceVariable* shaderVar = myEffect->GetEffect()->GetVariableByName(aResourceName.c_str())->AsShaderResource();
	if (shaderVar->IsValid() == false)
	{
		//DL_MESSAGE_BOX("Failed to get ShaderResource", "Surface Error", MB_ICONWARNING);
		RESOURCE_LOG("Failed to get ShaderResource");
		return false;
	}

	if (aResourceName == "EmissiveTexture")
	{
		myEmissive = true;
	}

	myTextures.Add(aTexture);
	myShaderResources.Add(aTexture->GetShaderView());
	myShaderResourceViews.Add(shaderVar);
	myShaderResourceNames.Add(aResourceName);

	return true;
}
Exemple #2
0
bool Prism::Surface::SetTexture(const std::string& aResourceName, const std::string& aFileName, bool aUseSRGB)
{
	aUseSRGB;

	DL_ASSERT_EXP(aFileName != ""
		, CU::Concatenate("Shader resource ( %s ) tried to use invalid filePath", aResourceName.c_str()));

	Texture* tex = Engine::GetInstance()->GetTextureContainer()->GetTexture(aFileName);
	ID3DX11EffectShaderResourceVariable* shaderVar = myEffect->GetEffect()->GetVariableByName(aResourceName.c_str())->AsShaderResource();

	if (shaderVar->IsValid() == false)
	{
		std::string errorMsg = "Failed to get ShaderResource: " + aResourceName;
		//DL_MESSAGE_BOX(errorMsg.c_str(), "Surface Error", MB_ICONWARNING);
		RESOURCE_LOG(errorMsg.c_str());
		return false;
	}

	if (aResourceName == "EmissiveTexture")
	{
		myEmissive = true;
	}

	myTextures.Add(tex);
	myShaderResources.Add(tex->GetShaderView());
	myShaderResourceViews.Add(shaderVar);
	myFilePaths.Add(aFileName);
	myShaderResourceNames.Add(aResourceName);

	return true;
}
	void TestMaterial::ClearState(ID3D11DeviceContext* context) 
	{
		if (texture != 0) {
			ID3DX11EffectShaderResourceVariable* shaderResource = effect->GetVariableByName("diffuseTexture")->AsShaderResource();
			shaderResource->SetResource(0);
		}
	}
Exemple #4
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;
}
Exemple #5
0
 void Effect::AddVariable(ID3DX11EffectVariable* var, const D3DX11_EFFECT_VARIABLE_DESC* varDesc, const D3DX11_EFFECT_TYPE_DESC* typeDesc) {
     _ASSERT(var && varDesc && typeDesc);
     switch (typeDesc->Class) {
         case D3D_SVC_SCALAR : {
             ID3DX11EffectScalarVariable* scalarVar = var->AsScalar();
             _ASSERT(scalarVar->IsValid());
             scalarVars[varDesc->Name] = scalarVar;
             break;
         }
         case D3D_SVC_VECTOR : {
             ID3DX11EffectVectorVariable* vectorVar = var->AsVector();
             _ASSERT(vectorVar->IsValid());
             vectorVars[varDesc->Name] = vectorVar;
             break;
         }
         case D3D_SVC_MATRIX_COLUMNS:
         case D3D_SVC_MATRIX_ROWS: {
             ID3DX11EffectMatrixVariable* matrixVar = var->AsMatrix();
             _ASSERT(matrixVar->IsValid());
             matrixVars[varDesc->Name] = matrixVar;
             break;
         }
         case D3D_SVC_STRUCT: structVars[varDesc->Name] = var;
             break;
         case D3D_SVC_OBJECT: {
             ID3DX11EffectShaderResourceVariable* resourceVar = var->AsShaderResource();
             if (resourceVar->IsValid()) {
                 resourceVars[varDesc->Name] = resourceVar;
             }
             break;
         }
         default:
             _ASSERT(false);
     }
 }
Exemple #6
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()));
    }
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());
				}
			}
		}
	}
}
Exemple #8
0
bool CD3DEffect::SetResources(LPCSTR handle, ID3D11ShaderResourceView** ppSRViews, size_t count)
{
  if (m_effect)
  {
    ID3DX11EffectShaderResourceVariable* var = m_effect->GetVariableByName(handle)->AsShaderResource();
    if (var->IsValid())
      return SUCCEEDED(var->SetResourceArray(ppSRViews, 0, count));
  }
  return false;
}
Exemple #9
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());
	}
void DX11Shader::setTextureArray(const char* strName, Texture texture, UINT uTexture)
{
    ID3DX11EffectShaderResourceVariable*  pTextureVariable;

    pTextureVariable = m_pEffect->pEffect->GetVariableByName(strName)->AsShaderResource();
    if (pTextureVariable->IsValid()) {
        pTextureVariable->SetResourceArray(&texture.getData()->m_pShaderResource, uTexture, 1);
    }
    else {
        EventManager::Instance().postMessage("Unknown shaderresource variable: %s in shader: %s", strName, m_pEffect->strName);
    }
}
Exemple #12
0
bool Prism::Surface::SetTexture(const std::string& aResourceName, ID3D11ShaderResourceView* aResource)
{
	ID3DX11EffectShaderResourceVariable* shaderVar = myEffect->GetEffect()->GetVariableByName(aResourceName.c_str())->AsShaderResource();
	if (shaderVar->IsValid() == false)
	{
		//DL_MESSAGE_BOX("Failed to get ShaderResource", "Surface Error", MB_ICONWARNING);
		RESOURCE_LOG("Failed to get ShaderResource");
		return false;
	}

	myShaderResources.Add(aResource);
	myShaderResourceViews.Add(shaderVar);
	myShaderResourceNames.Add(aResourceName);
	return true;
}
Exemple #13
0
bool Surface::SetTexture(const std::string& aResourceName, const std::string& aFileName, const bool aUseSRGB)
{
	aUseSRGB;

	Texture* tex = Engine::GetInstance()->GetTextureContainer().GetTexture(aFileName);
	ID3DX11EffectShaderResourceVariable* shaderVar = myEffect->GetEffect()->GetVariableByName(aResourceName.c_str())->AsShaderResource();

	if (shaderVar->IsValid() == false)
	{
		DL_MESSAGE_BOX("Failed to get ShaderResource", "Surface Error", MB_ICONWARNING);
		return false;
	}

	myTextures.Add(tex);
	myShaderViews.Add(shaderVar);

	return true;
}
	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());
		}
	}
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;
	}
}
Exemple #16
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;
}
Exemple #17
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);
}
Exemple #18
0
void Prism::Surface::ReloadSurface()
{
	myTextures.RemoveAll();
	myShaderResourceViews.RemoveAll();
	myShaderResources.RemoveAll();

	for (int i = 0; i < myFilePaths.Size(); ++i)
	{
		Texture* tex = Engine::GetInstance()->GetTextureContainer()->GetTexture(myFilePaths[i]);
		ID3DX11EffectShaderResourceVariable* shaderVar = myEffect->GetEffect()->GetVariableByName(myShaderResourceNames[i].c_str())->AsShaderResource();

		if (shaderVar->IsValid() == false)
		{
			std::string errorMsg = "Failed to get ShaderResource: " + myShaderResourceNames[i];
			//DL_MESSAGE_BOX(errorMsg.c_str(), "Surface Error", MB_ICONWARNING);
			RESOURCE_LOG(errorMsg.c_str());
		}

		myTextures.Add(tex);
		myShaderResources.Add(tex->GetShaderView());
		myShaderResourceViews.Add(shaderVar);
	}
}
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 );
}