Ejemplo n.º 1
0
bool TerrainShaderClass::RenderDeferred(ID3D11DeviceContext* pDeviceContext, ObjectClass* pObject, CameraClass* pCamera)
{
	bool result;
	unsigned int bufferNumber;



	// Set the shader parameters that it will use for rendering.
	result = ShaderClass::SetConstantBufferParameters(pDeviceContext, pObject->GetWorldMatrix(), pCamera->GetViewMatrix(), pCamera->GetProjMatrix(), pCamera->GetPosition());
	if (!result)
	{
		return false;
	}



	// Set the position of the constant buffer in the vertex shader.
	bufferNumber = 0;

	// Set the constant buffer in the vertex shader with the updated values.
	pDeviceContext->GSSetConstantBuffers(bufferNumber, 1, &mMatrixBuffer);

	TextureClass* pTexture = pObject->GetTexture();

	ID3D11ShaderResourceView** tex = pTexture->GetShaderResourceView();

	// Set shader texture resource in the pixel shader.
	pDeviceContext->PSSetShaderResources(0, pTexture->GetTextureCount(), tex);

	if (pTexture->blendEnabled())
	{
		ID3D11ShaderResourceView* tex2 = pTexture->GetBlendMapShaderResourceView();
		pDeviceContext->PSSetShaderResources(3, 1, &tex2);
	}


	// Now render the prepared buffers with the shader.
	pDeviceContext->PSSetSamplers(0, 1, &mSampleState);

	// Set the vertex input layout.
	pDeviceContext->IASetInputLayout(mLayout);

	// Set the vertex and pixel shaders that will be used to render this triangle.
	pDeviceContext->VSSetShader(mVertexShader, nullptr, 0);
	pDeviceContext->HSSetShader(mHullShader, nullptr, 0);
	pDeviceContext->DSSetShader(mDomainShader, nullptr, 0);
	pDeviceContext->GSSetShader(mGeometryShader, nullptr, 0);
	pDeviceContext->PSSetShader(mDeferredPS, nullptr, 0);

	// Render mesh stored in active buffers
	pDeviceContext->DrawIndexed(pObject->GetIndexCount(0), 0, 0);

	return true;
}
Ejemplo n.º 2
0
HRESULT TextureManager::addChessBoardTexture(ID3D11Device* device,
	ID3D11DeviceContext* context)
{
	TextureClass* texture = new TextureClass;
	if (FAILED(texture->beChessBoard(device,context)))
	{
		return E_FAIL;
	}
	m_vec.push_back(std::unique_ptr<TextureClass>(texture));
	return S_OK;
}
Ejemplo n.º 3
0
int TextureManagerClass::LoadTexture(String a_sName)
{
	int nTexture = IdentifyTexure(a_sName);
	if(nTexture == -1)
	{
		TextureClass* texture = new TextureClass();
		texture->LoadTexture(a_sName);
		m_vTextures.push_back(texture);
		nTexture = GetNumberOfTextures() -1;
	}
	return nTexture;
}
Ejemplo n.º 4
0
HRESULT TextureManager::addTexture(ID3D11Device* device,
	ID3D11DeviceContext* context,
	MutableString&& filename)
	//add a brand new texture into texture manager class.
{
	TextureClass* texture = new TextureClass;
	std::string path = filename.getMultiByteString();
	if (FAILED(texture->LoadFile(device, context, path)))
	{
		return E_FAIL;
	}
	m_vec.push_back(std::unique_ptr<TextureClass>(texture));
	return S_OK;
}
Ejemplo n.º 5
0
bool LightShaderClass::RenderAnimated(ID3D11DeviceContext* pDeviceContext, ObjectClass* pObject, CameraClass* pCamera, PointLightClass** ppLights, UINT NrOfLights, FogClass* pDrawDistFog)
{
	bool result;
	unsigned int bufferNumber;

	// Set the position of the constant buffer in the vertex shader.
	bufferNumber = 0;

	result = SetTbufferParameters(pDeviceContext, pObject->GetWorldMatrix(), pCamera->GetViewMatrix(), pCamera->GetProjMatrix(), pObject);
	if (!result)
	{
		return false;
	}
	pDeviceContext->GSSetConstantBuffers(0, 1, &mBoneTBuffer);

	result = SetConstantBufferParameters(pDeviceContext, ppLights, NrOfLights, pObject, pDrawDistFog, pCamera);
	if (!result)
	{
		return false;
	}

	

	TextureClass* pTexture = pObject->GetTexture();
	ID3D11ShaderResourceView** tex = pTexture->GetShaderResourceView();

	// Set shader texture resource in the pixel shader.
	pDeviceContext->PSSetShaderResources(0, pTexture->GetTextureCount(), tex);

	// Now render the prepared buffers with the shader.
	pDeviceContext->PSSetSamplers(0, 1, &mSampleState);

	// Set the vertex input layout.
	pDeviceContext->IASetInputLayout(mLayout);

	// Set the vertex and pixel shaders that will be used to render this triangle.
	pDeviceContext->VSSetShader(mVertexShader, nullptr, 0);
	pDeviceContext->HSSetShader(mHullShader, nullptr, 0);
	pDeviceContext->DSSetShader(mDomainShader, nullptr, 0);
	pDeviceContext->GSSetShader(mAniGS, nullptr, 0);
	pDeviceContext->PSSetShader(mPixelShader, nullptr, 0);

	// Render mesh stored in active buffers
	pDeviceContext->DrawIndexed(pObject->GetIndexCount(0), 0, 0);

	return true;
}
Ejemplo n.º 6
0
bool Material::AddTexture(std::string textureName)
{
	TextureClass* texture = BE_NEW TextureClass;
	if (!texture)
	{
		return false;
	}

	if (!texture->Initialize(g_pApp->GetGraphicsManager()->GetRenderer()->GetDevice(), textureName))
	{
		return false;
	}

	m_material.Textures.push_back(texture);

	return true;
}
Ejemplo n.º 7
0
bool TerrainShaderClass::Render(ID3D11DeviceContext* pDeviceContext, ObjectClass* pObject, CameraClass* pCamera, LightObjectClass* pSunLightObject, FogClass* pDrawDistFog)
{
	bool result;
	unsigned int bufferNumber;



	// Set the shader parameters that it will use for rendering.
	result = ShaderClass::SetConstantBufferParameters(pDeviceContext, pObject->GetWorldMatrix(), pCamera->GetViewMatrix(), pCamera->GetProjMatrix(), pCamera->GetForward());
	if (!result)
	{
		return false;
	}

	// Set the position of the constant buffer in the vertex shader.
	bufferNumber = 0;

	// Set the constant buffer in the vertex shader with the updated values.
	pDeviceContext->GSSetConstantBuffers(bufferNumber, 1, &mMatrixBuffer);

	TextureClass* pTexture = pObject->GetTexture();

	result = SetConstantBufferParameters(pDeviceContext, pSunLightObject, pDrawDistFog);
	if (!result)
	{
		return false;
	}
	

	ID3D11ShaderResourceView** tex = pTexture->GetShaderResourceView();

	// Set shader texture resource in the pixel shader.
	pDeviceContext->PSSetShaderResources(0, pTexture->GetTextureCount(), tex);


	// Now render the prepared buffers with the shader.
	RenderShader(pDeviceContext, pObject->GetIndexCount(0));

	return true;
}
Ejemplo n.º 8
0
bool TerrainShaderClass::RenderShadowsDeferred(ID3D11DeviceContext* pDeviceContext, ObjectClass* pObject, CameraClass* pCamera, PointLightClass* pLights, ID3D11ShaderResourceView* pShadowmap, UINT indexCount, UINT indexStart)
{
	bool result;
	unsigned int bufferNumber;



	// Set the position of the constant buffer in the vertex shader.
	bufferNumber = 0;

	result = SetShadowConstantBufferParamters(pDeviceContext, pObject, pCamera, pLights);
	if (!result)
	{
		return false;
	}

	ModelClass* pModel = pObject->GetModel();

	pDeviceContext->PSSetShaderResources(0, 1, &pShadowmap);



	TextureClass* pTexture = pModel->GetDetailMap();

	ID3D11ShaderResourceView** tex = pTexture->GetShaderResourceView();

	// Set shader texture resource in the pixel shader.
	pDeviceContext->PSSetShaderResources(1, 1, tex);

	pTexture = pModel->GetNormalMap();

	tex = pTexture->GetShaderResourceView();

	// Set shader texture resource in the pixel shader.
	pDeviceContext->PSSetShaderResources(2, 1, tex);


	pTexture = pModel->GetTexture();

	tex = pTexture->GetShaderResourceView();

	// Set shader texture resource in the pixel shader.
	pDeviceContext->PSSetShaderResources(3, pTexture->GetTextureCount(), tex);



	pDeviceContext->PSSetSamplers(1, 1, &mPointSampleState);
	// Now render the prepared buffers with the shader.
	pDeviceContext->PSSetSamplers(0, 1, &mSampleState);

	// Set the vertex input layout.
	pDeviceContext->IASetInputLayout(mLayout);

	// Set the vertex and pixel shaders that will be used to render this triangle.
	pDeviceContext->VSSetShader(mShadowDeferredVS, nullptr, 0);
	pDeviceContext->HSSetShader(mHullShader, nullptr, 0);
	pDeviceContext->DSSetShader(mDomainShader, nullptr, 0);
	pDeviceContext->GSSetShader(mShadowDeferredGS, nullptr, 0);
	pDeviceContext->PSSetShader(mShadowDeferredPS, nullptr, 0);

	// Render mesh stored in active buffers
	pDeviceContext->DrawIndexed(indexCount, indexStart, 0);

	return true;
}
Ejemplo n.º 9
0
void MeshClass::LoadModel(string filename)
{
    string sinput;
    string s;

    ifstream is(filename, ifstream::binary);
    if (is.fail())
    {
        throw GenericException("File not found");
    }

    // get length of file:
    is.seekg(0, is.end);
    int length = (int)is.tellg();
    is.seekg(0, is.beg);

    char * buffer = new char[length];
    
    // read data as a block:
    is.read(buffer, length);
        
    s.reserve(sizeof(char) *length);
    s = string(buffer);

    // ...buffer contains the entire file...

    delete[] buffer;
    is.close();

    string::iterator it = s.begin();

    MaterialClass* focusMaterial = 0;
    TextureClass* focusTexture = 0;
    ObjectMeshClass* focusObject = 0;
    MeshDataClass* focusMesh = 0;
    MeshDataClass::MeshColorType focusType;

    // For each object in the model
    while ((*it) != 'e')
    {
        //get next command
        sinput = readStringUntilSpace(&it);

        if (sinput.compare("vtn") == 0)
        {
            //Load vertices until a new object starts
            MeshDataClass::MeshDataType newMeshData = readVtnLine(&it);
            focusMesh->addMeshData(newMeshData);
            
            //Should auto skip the new line
            if ((*it) == 'm' || (*it) == 'o')
            {
                //Push the last mesh
                focusObject->addMesh(focusMesh);

            }
        }
        else if (sinput.compare("o") == 0)
        {
            //If your not the first object
            if (focusObject != 0)
            {
                //Push the last object
                m_allObjects.push_back(focusObject);
            }
            string objectName = readStringUntilNewL(&it);

            focusObject = new ObjectMeshClass();
            focusObject->Initialize(objectName);

            //Should auto skip to the next line
            
            //Check if you need to use the prev material
            if ((*it) == 'v')
            {
                focusMesh = new MeshDataClass();

                if (focusType == MeshDataClass::MeshColorType::MATERIAL)
                {
                    focusMesh->Initialize(focusMaterial);
                }
                else
                {
                    focusMesh->Initialize(focusTexture);
                }
            }
        }
        else if (sinput.compare("mtl") == 0)
        {
            focusMesh = new MeshDataClass();
            MaterialClass::MaterialInfo focusColorInfo = MaterialClass::MaterialInfo();

            focusColorInfo = readMtlLine(&it);

            if (focusColorInfo.map_Kd.compare("material") == 0)
            {
                MaterialClass* material = new MaterialClass();
                material->Initialize(focusColorInfo);

                focusType = MeshDataClass::MeshColorType::MATERIAL;

                focusMesh->Initialize(material);
            }
            else
            {
                TextureClass* texture = new TextureClass();
                texture->Initialize(WindowsHelpers::ToLWideStr("data\\" + focusColorInfo.map_Kd));

                focusTexture = texture;
                focusType = MeshDataClass::MeshColorType::TEXTURE;

                focusMesh->Initialize(texture);
            }

            //Should auto skip to the next line
        }    
        else if (sinput.compare("gun") == 0)
        {
            XMFLOAT3 newGun = readGunLine(&it);
            m_guns.push_back(newGun);
        }
    }

    //Add the last objects
    focusObject->addMesh(focusMesh);
    m_allObjects.push_back(focusObject);
}