void RayTracerMaterial::initialize(Effect * effect)
{
	Material::initialize(effect);
	MATERIAL_VARIABLE_RETRIEVE(TextureSize);
	MATERIAL_VARIABLE_RETRIEVE(Color);
	MATERIAL_VARIABLE_RETRIEVE(ColorTexture);
	MATERIAL_VARIABLE_RETRIEVE(OutputTexture);
	MATERIAL_VARIABLE_RETRIEVE(DepthTexture);
	MATERIAL_VARIABLE_RETRIEVE(CameraPosition);
	MATERIAL_VARIABLE_RETRIEVE(ViewMatrix);
	MATERIAL_VARIABLE_RETRIEVE(ProjectionMatrix);
	MATERIAL_VARIABLE_RETRIEVE(InverseViewMatrix);
	MATERIAL_VARIABLE_RETRIEVE(InverseProjectionMatrix);
	MATERIAL_VARIABLE_RETRIEVE(LightPosition);
	MATERIAL_VARIABLE_RETRIEVE(Position);

	D3D11_INPUT_ELEMENT_DESC inputElementDescriptions[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }
	};

	createInputLayout("render", "p0", inputElementDescriptions, ARRAYSIZE(inputElementDescriptions));

}
Ejemplo n.º 2
0
void Tree::init(const char* filename, ID3D11Device* g_device, ID3D11DeviceContext* g_context)
{
	
	Mesh::init(filename, g_device, g_context);
	
	_leaves.init("", g_device, g_context);

	//////////////////////////
	bFire = false;

	m_numSubsets = 1;

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


	createEffect("../Desert_Island/shaders/tree.fxo", g_device);

	fx_m_World				= getFX()->GetVariableByName("m_World")->AsMatrix();
	fx_m_WorldViewProj		= getFX()->GetVariableByName("m_WorldViewProj")->AsMatrix();
	fx_m_L_ViewProj			= getFX()->GetVariableByName("m_L_ViewProj")->AsMatrix();
	
	fx_tex_shadow_map		= getFX()->GetVariableByName("tex_shadow_map")->AsShaderResource();

	fx_lights				= getFX()->GetVariableByName("lights");

	fx_num_lights			= getFX()->GetVariableByName("num_lights")->AsScalar();

	fx_pEye					= getFX()->GetVariableByName("pEye")->AsVector();
	fx_bShadowed			= getFX()->GetVariableByName("bShadowed")->AsScalar();
	fx_bUsePCSS				= getFX()->GetVariableByName("bUsePCSS")->AsScalar();

	///////////

	HRESULT hr = D3DX11CreateShaderResourceViewFromFile(g_dev(), L"../Desert_island/media/tree_heightmap.jpg", 0, 0, &srv_heightmap, 0);
	if (FAILED(hr))
		MessageBoxA(0, "Error creating tree heightmap srv", 0, 0);

	
	
	///////////

	// Input layout - Vertex IA
	D3D11_INPUT_ELEMENT_DESC vertex_layout[] = {
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
        { "NORMAL", 0,  DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TANGENT", 0,  DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEX_COORDS", 0,  DXGI_FORMAT_R32G32_FLOAT, 0, 36, D3D11_INPUT_PER_VERTEX_DATA, 0 }
	};

	D3DX11_PASS_DESC passDesc;
	ID3DX11EffectTechnique* tech = getFX()->GetTechniqueByIndex(0);
	tech->GetPassByIndex(0)->GetDesc(&passDesc);

	hr = createInputLayout(g_dev(), vertex_layout, 4, passDesc.pIAInputSignature, passDesc.IAInputSignatureSize);
	if (FAILED(hr))
		MessageBoxA(0, "Error creating tree IA", 0, 0);

}
Ejemplo n.º 3
0
bool ShaderClass::createVertexShaderAndInputLayout(ID3D11Device* pDevice, WCHAR* fileName, CHAR* EntryPoint, D3D11_INPUT_ELEMENT_DESC *vertexDesc, int numElements, ID3D11VertexShader** ppVshader, ID3D11InputLayout** ppLayout)
{
	HRESULT hr;
	bool result;
	// Initialize the vertex shader
	ID3D10Blob* vertexShaderBuffer;
	ID3D10Blob* errorMessages;

	hr = D3DCompileFromFile(
		fileName,
		NULL,
		NULL,
		EntryPoint,
		"vs_5_0",
		0,
		0,
		&vertexShaderBuffer,
		&errorMessages);

	if (FAILED(hr))
	{
		// If the shader failed to compile it should have writen something to the error message.
		if (errorMessages)
		{
			OutputShaderErrorMessage(errorMessages, fileName);
			return false;
		}
		// If there was nothing in the error message then it simply could not find the shader file itself.
		else
		{
			MessageBox(0, fileName, L"Missing Shader File", MB_OK);
			return false;
		}
	}

	// Create the vertex shader from the buffer.
	hr = pDevice->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, ppVshader);
	if (FAILED(hr))
	{
		MessageBox(0, L"Failed to create vertex shader", 0, MB_OK);
		return false;
	}

	if (FAILED(hr))
	{
		MessageBox(0, L"Could not create VertexShader.", 0, 0);
		return false;
	}

	result = createInputLayout(pDevice, vertexDesc, vertexShaderBuffer, numElements, ppLayout);
	if (!result)
	{
		return false;
	}

	vertexShaderBuffer->Release();
	return true;
}
Ejemplo n.º 4
0
void VCShader::setupInputLayout() //override
{
  D3D11_INPUT_ELEMENT_DESC ve[2];
    
  // vc
  ve[0] = makeInputElement( "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0 ) ;
  ve[1] = makeInputElement( "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, (3)*sizeof( float ) ) ;
  
  createInputLayout( ve, 2 ) ;
}
Ejemplo n.º 5
0
void VTCShader::setupInputLayout() //override
{
  int accum = 0 ;

  D3D11_INPUT_ELEMENT_DESC ve[3];

  ve[0] = makeInputElement( "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0 ) ;
  ve[1] = makeInputElement( "TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, accum += 3*sizeof( float ) ) ;
  ve[2] = makeInputElement( "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, accum += 4*sizeof( float ) ) ;
  
  createInputLayout( ve, 3 ) ;
}
	void BasicMaterial::initialize(Effect * effect)
	{
		Material::initialize(effect);
		MATERIAL_VARIABLE_RETRIEVE(WorldViewProjection);
		D3D11_INPUT_ELEMENT_DESC inputElementDescriptions[] =
		{
			{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		};

		createInputLayout("main11", "p0", inputElementDescriptions, ARRAYSIZE(inputElementDescriptions));
	}
Ejemplo n.º 7
0
void VTTTTNCShader::setupInputLayout() //override
{
  D3D11_INPUT_ELEMENT_DESC ve[7] ;
  int accum = 0 ;
  ve[ 0 ] = makeInputElement( "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0 ) ;
  ve[ 1 ] = makeInputElement( "TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, accum+=3*sizeof(float) ) ;
  ve[ 2 ] = makeInputElement( "TEXCOORD", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, accum+=4*sizeof(float) ) ;
  ve[ 3 ] = makeInputElement( "TEXCOORD", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, accum+=4*sizeof(float) ) ;
  ve[ 4 ] = makeInputElement( "TEXCOORD", 3, DXGI_FORMAT_R32G32B32A32_FLOAT, accum+=4*sizeof(float) ) ;
  ve[ 5 ] = makeInputElement( "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, accum += 4*sizeof(float) ) ;
  ve[ 6 ] = makeInputElement( "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, accum += 3*sizeof(float) ) ;
  createInputLayout( ve, 7 ) ;
}
Ejemplo n.º 8
0
void VNCShader::setupInputLayout() //override
{
  int accum = 0 ;

  // vnc
  D3D11_INPUT_ELEMENT_DESC ve[3];
    
  ve[0] = makeInputElement( "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0 ) ; // first one, no offset
  ve[1] = makeInputElement( "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, accum += 3*sizeof( float ) ) ; // there are 3 floats before me
  ve[2] = makeInputElement( "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, accum += 3*sizeof( float ) ) ; // there are 6 floats before me
  
  createInputLayout( ve, 3 ) ;
}
Ejemplo n.º 9
0
bool D3DCodePath::loadVertexShader(DataStream& stream)
{
    HRESULT hr = mDevice.getDevice().CreateVertexShader(stream.getData(), stream.getDataSize(), NULL, &mpVertexShader);
    if ( FAILED(hr) )
    {
        return false;
    }

    if ( !createInputLayout(stream) )
    {
        return false;
    }

    return true;
}
Ejemplo n.º 10
0
void VT10NC10Shader::setupInputLayout() //override
{
  const int numElts = 1 + 10 + 1 + 10 ;
  D3D11_INPUT_ELEMENT_DESC ve[ numElts ] ;
  int accum = 0 ;

  int j = 0 ;
  ve[ j++ ] = makeInputElement( "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0 ) ;
  
  // 10 texcoord 
  ve[ j++ ] = makeInputElement( "TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, accum+=3*sizeof(float) ) ; //3
  for( int k = 1 ; k <= 9 ; k++ )  // LOOP UNTIL TEXCOORD9
    ve[ j++ ] = makeInputElement( "TEXCOORD", k, DXGI_FORMAT_R32G32B32A32_FLOAT, accum+=4*sizeof(float) ) ;  //ve[ 2 ] = makeInputElement( "TEXCOORD", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, accum+=4*sizeof(float) ) ;

  ve[ j++ ] = makeInputElement( "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, accum += 4*sizeof(float) ) ;
  
  // 10 color
  ve[ j++ ] = makeInputElement( "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, accum += 3*sizeof(float) ) ; //3
  for( int k = 1 ; k <= 9 ; k++ )
    ve[ j++ ] = makeInputElement( "COLOR", k, DXGI_FORMAT_R32G32B32A32_FLOAT, accum += 4*sizeof(float) ) ;
  
  createInputLayout( ve, numElts ) ;
}
Ejemplo n.º 11
0
gl::Error InputLayoutCache::updateInputLayout(gl::Program *program,
                                              GLenum mode,
                                              const SortedAttribArray &sortedAttributes,
                                              const SortedIndexArray &sortedSemanticIndices,
                                              size_t attribCount,
                                              GLsizei numIndicesPerInstance)
{
    const std::vector<sh::Attribute> &shaderAttributes = program->getAttributes();
    PackedAttributeLayout layout;

    ProgramD3D *programD3D = GetImplAs<ProgramD3D>(program);
    bool programUsesInstancedPointSprites =
        programD3D->usesPointSize() && programD3D->usesInstancedPointSpriteEmulation();
    bool instancedPointSpritesActive = programUsesInstancedPointSprites && (mode == GL_POINTS);

    if (programUsesInstancedPointSprites)
    {
        layout.flags |= PackedAttributeLayout::FLAG_USES_INSTANCED_SPRITES;
    }

    if (instancedPointSpritesActive)
    {
        layout.flags |= PackedAttributeLayout::FLAG_INSTANCED_SPRITES_ACTIVE;
    }

    if (numIndicesPerInstance > 0)
    {
        layout.flags |= PackedAttributeLayout::FLAG_INSTANCED_RENDERING_ACTIVE;
    }

    const auto &semanticToLocation = programD3D->getAttributesByLayout();

    for (size_t attribIndex = 0; attribIndex < attribCount; ++attribIndex)
    {
        const auto &attrib = *sortedAttributes[attribIndex];
        int sortedIndex    = sortedSemanticIndices[attribIndex];

        if (!attrib.active)
            continue;

        gl::VertexFormatType vertexFormatType =
            gl::GetVertexFormatType(*attrib.attribute, attrib.currentValueType);

        // Record the type of the associated vertex shader vector in our key
        // This will prevent mismatched vertex shaders from using the same input layout
        GLenum glslElementType =
            GetGLSLAttributeType(shaderAttributes, semanticToLocation[sortedIndex]);

        layout.addAttributeData(glslElementType, sortedIndex, vertexFormatType, attrib.divisor);
    }

    ID3D11InputLayout *inputLayout = nullptr;
    if (layout.numAttributes > 0 || layout.flags != 0)
    {
        auto layoutMapIt = mLayoutMap.find(layout);
        if (layoutMapIt != mLayoutMap.end())
        {
            inputLayout = layoutMapIt->second;
        }
        else
        {
            gl::Error error =
                createInputLayout(sortedAttributes, sortedSemanticIndices, attribCount, mode,
                                  program, numIndicesPerInstance, &inputLayout);
            if (error.isError())
            {
                return error;
            }
            if (mLayoutMap.size() >= mCacheSize)
            {
                TRACE("Overflowed the limit of %u input layouts, purging half the cache.",
                      mCacheSize);

                // Randomly release every second element
                auto it = mLayoutMap.begin();
                while (it != mLayoutMap.end())
                {
                    it++;
                    if (it != mLayoutMap.end())
                    {
                        // c++11 erase allows us to easily delete the current iterator.
                        SafeRelease(it->second);
                        it = mLayoutMap.erase(it);
                    }
                }
            }

            mLayoutMap[layout] = inputLayout;
        }
    }

    if (inputLayout != mCurrentIL)
    {
        mDeviceContext->IASetInputLayout(inputLayout);
        mCurrentIL = inputLayout;
    }

    return gl::Error(GL_NO_ERROR);
}
QTInputDevices::QTInputDevices(GUID deviceGUID, std::string name, unsigned int playerID) : 
	InputDevice(deviceGUID, name, playerID)
{
	createInputLayout();
	createInputObjectsFromLayout();
}
QTInputDevices::QTInputDevices() :
	InputDevice(GUID(), "")
{
	createInputLayout();
	createInputObjectsFromLayout();
}
Ejemplo n.º 14
0
void ShaderManagerDX::initialize()
{
	createShaders();
	createInputLayout();
	createConstantBuffers();
}