示例#1
0
RenderPass* RenderFrame::StartNewRenderPass()
{
	dDAssert( m_currPass < MAX_PASSES );
	RenderPass* ret = &m_passes[m_currPass++];
	ret->Clear();
	return ret;
}
示例#2
0
void HDRPass::Draw( RenderFrame* frame )
{
	static GraphicsManager& mgr = GraphicsManager::Instance();

	glm::mat4 persp = glm::ortho( 0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f );

	RenderPass* pass = frame->StartNewRenderPass();

	const Mesh::SubMesh* screenSpaceQuad = mgr.GetScreenSpaceQuad()->GetSubMesh( 0 );

	GraphicsManager::CameraDataBuffer* camData = m_cameraData.GetDataTyped();
	camData->model = glm::mat4( 1.0f ); // TODO(daviD) Make this 0
	camData->proj = persp;
	camData->view = glm::mat4();

	DrawCall hdrDrawCall;
	hdrDrawCall.vbo = screenSpaceQuad->m_vertexHandle;
	hdrDrawCall.ibo = screenSpaceQuad->m_indexBufferHandle;
	hdrDrawCall.indexCount = screenSpaceQuad->m_indexCount;
	hdrDrawCall.pipeline = m_pipeline;
	hdrDrawCall.dataSet.push_back( &m_cameraData );
	hdrDrawCall.dataSet.push_back( &m_blitSrc );
	hdrDrawCall.dataSet.push_back( &m_hdrParams );

	pass->AddDrawCall( hdrDrawCall );
}
void AtmosphericPass::Draw(RenderFrame* frame)
{
	static GraphicsManager& mgr = GraphicsManager::Instance();

	Camera* cam = mgr.GetCamera();

	glm::mat4 atmosPersp = glm::perspective( cam->GetFieldOfView(), cam->GetAspect(), .1f, OUTTER_RAD + 1.0f );
	atmosPersp[1][1] *= -1.0f; // TODO( daviD ): Need to get rid of this hack. Vulkan needs it, other things don't

	RenderPass* pass = frame->StartNewRenderPass();
	pass->m_target = SharedGraphicsResources::Instance().m_testFb;

	const Mesh::SubMesh* sphereSubMesh = mgr.GetSphereMesh()->GetSubMesh( 0 );

	GraphicsManager::CameraDataBuffer* camData = m_cameraData.GetDataTyped();
	glm::vec3 camPos = cam->GetPosition();
	camPos.y -= glm::mix( INNER_RAD, OUTTER_RAD, HEIGHT_RATIO );
	glm::mat4 model = glm::scale( glm::translate(glm::mat4(), camPos), glm::vec3( OUTTER_RAD ) );
	camData->model = model;
	camData->proj = atmosPersp;
	camData->view = cam->GetView();

	DrawCall atmosDrawCall;
	atmosDrawCall.vbo = sphereSubMesh->m_vertexHandle;
	atmosDrawCall.ibo = sphereSubMesh->m_indexBufferHandle;
	atmosDrawCall.indexCount = sphereSubMesh->m_indexCount;
	atmosDrawCall.pipeline = m_pipeline;
	atmosDrawCall.dataSet.push_back( &m_atmoshericData );
	atmosDrawCall.dataSet.push_back( &m_cameraData );

	pass->AddDrawCall( atmosDrawCall );
}
示例#4
0
		inline void doRenderNonInstanced( RenderPass const & pass
			, UniformBuffer & ubo
			, Scene const & scene
			, PickingPass::NodeType type
			, MapType & nodes )
		{
			uint32_t count{ 1u };

			for ( auto itPipelines : nodes )
			{
				pass.updatePipeline( *itPipelines.first );
				itPipelines.first->apply();
				auto drawIndex = ubo.getUniform< UniformType::eUInt >( DrawIndex );
				auto nodeIndex = ubo.getUniform< UniformType::eUInt >( NodeIndex );
				drawIndex->setValue( uint8_t( type ) + ( ( count & 0x00FFFFFF ) << 8 ) );
				uint32_t index{ 0u };

				for ( auto & renderNode : itPipelines.second )
				{
					nodeIndex->setValue( index++ );
					ubo.update();

					if ( renderNode.m_data.isInitialised() )
					{
						doRenderNodeNoPass( renderNode );
					}
				}

				count++;
			}
		}
示例#5
0
		inline void doTraverseNodes( RenderPass const & pass
			, UniformBuffer & ubo
			, MapType & nodes
			, PickingPass::NodeType type
			, FuncType function )
		{
			uint32_t count{ 1u };

			for ( auto itPipelines : nodes )
			{
				pass.updatePipeline( *itPipelines.first );
				itPipelines.first->apply();
				auto drawIndex = ubo.getUniform< UniformType::eUInt >( DrawIndex );
				auto nodeIndex = ubo.getUniform< UniformType::eUInt >( NodeIndex );
				drawIndex->setValue( uint8_t( type ) + ( ( count & 0x00FFFFFF ) << 8 ) );
				uint32_t index{ 0u };

				for ( auto itPass : itPipelines.second )
				{
					for ( auto itSubmeshes : itPass.second )
					{
						nodeIndex->setValue( index++ );
						ubo.update();
						function( *itPipelines.first
							, *itPass.first
							, *itSubmeshes.first
							, itSubmeshes.first->getInstantiation()
							, itSubmeshes.second );
					}
				}

				count++;
			}
		}
示例#6
0
文件: Material.cpp 项目: Kaaml/Vxy
void Material::Parse( pugi::xml_node Node )
{
	//Node -> <material name="Nazwa_Mat" >
	for( const auto &Child : Node.children() )
	{
		if( !strcmp( Child.name(), "pass" ) )
		{
			// tworz nowy pass
			RenderPass *Pass = new RenderPass();
			Pass->Parse( Child );
			pRenderPass = Pass;
		}
	}


}
Framebuffer::Framebuffer(Device *device, const RenderPass &rp, const RenderPassInfo &info)
    : Cookie(device)
    , device(device)
    , render_pass(rp)
    , info(info)
{
	width = UINT32_MAX;
	height = UINT32_MAX;
	VkImageView views[VULKAN_NUM_ATTACHMENTS + 1];
	unsigned num_views = 0;

	for (unsigned i = 0; i < info.num_color_attachments; i++)
	{
		if (info.color_attachments[i])
		{
			unsigned lod = info.color_attachments[i]->get_create_info().base_level;
			width = min(width, info.color_attachments[i]->get_image().get_width(lod));
			height = min(height, info.color_attachments[i]->get_image().get_height(lod));
			views[num_views++] = info.color_attachments[i]->get_view();
		}
	}

	if (info.depth_stencil)
	{
		unsigned lod = info.depth_stencil->get_create_info().base_level;
		width = min(width, info.depth_stencil->get_image().get_width(lod));
		height = min(height, info.depth_stencil->get_image().get_height(lod));
		views[num_views++] = info.depth_stencil->get_view();
	}

	VkFramebufferCreateInfo fb_info = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO };
	fb_info.renderPass = rp.get_render_pass();
	fb_info.attachmentCount = num_views;
	fb_info.pAttachments = views;
	fb_info.width = width;
	fb_info.height = height;
	fb_info.layers = 1;

	if (vkCreateFramebuffer(device->get_device(), &fb_info, nullptr, &framebuffer) != VK_SUCCESS)
		LOG("Failed to create framebuffer.");
}
示例#8
0
GameObject* Terrain::CreateGameObject(const char* diffuseTxt_filename, const char* normalTxt_filename, const char* heightTxt_filemane)
{
	std::vector<float2> texture_coordinate = calculateTextureCoordiate();
	std::vector<float2> boundsY = CalcAllPatchBoundsY();

	const int iNumVertices = m_initInfo.HeightmapWidth / 8 * (m_initInfo.HeightmapHeight) / 8 * 4;
	const int iNumIndices = iNumVertices;
	VertexTerrain* vertices = new VertexTerrain[iNumVertices];
	unsigned int* indices = new unsigned int[iNumIndices];

	// Translate the terrain, so that the mid-point of terrain is at (0, 0, 0)
	Matrix4 translate;
	translate.CreateTranslation(Vector3(-GetWidth() / 2.0f, 0.0f, -GetDepth() / 2.0f));

	// Initialize the index to the vertex buffer.
	int indexCounter = 0;

	// Load the vertex and index array with the terrain data.
	for (int j = 0; j < m_initInfo.HeightmapHeight - 8; j += 8)
	{
		for (int i = 0; i < m_initInfo.HeightmapWidth - 8; i += 8)
		{
			const int index_bl = m_initInfo.HeightmapWidth * j + i;
			const int index_br = m_initInfo.HeightmapWidth * j + (i + 8);
			const int index_ul = m_initInfo.HeightmapWidth * (j + 8) + i;
			const int index_ur = m_initInfo.HeightmapWidth * (j + 8) + (i + 8);

			const float2 bl_uv(
				texture_coordinate[index_bl].x, texture_coordinate[index_bl].y
				);
			const float2 br_uv(
				(texture_coordinate[index_br].x == 0.0f ? 1.0f : texture_coordinate[index_br].x),
				texture_coordinate[index_br].y
				);
			const float2 ul_uv(
				texture_coordinate[index_ul].x,
				(texture_coordinate[index_ul].y == 1.0f ? 0.0f : texture_coordinate[index_ul].y)
				);
			const float2 ur_uv(
				(texture_coordinate[index_ur].x == 0.0f ? 1.0f : texture_coordinate[index_ur].x),
				(texture_coordinate[index_ur].y == 1.0f ? 0.0f : texture_coordinate[index_ur].y)
				);

			Vector3 bl(i * m_initInfo.CellSpacing, m_HeightMap[index_bl] * m_initInfo.CellSpacing, j* m_initInfo.CellSpacing);
			Vector3 br((i + 8)* m_initInfo.CellSpacing, m_HeightMap[index_br] * m_initInfo.CellSpacing, j* m_initInfo.CellSpacing);
			Vector3 ul(i* m_initInfo.CellSpacing, m_HeightMap[index_ul] * m_initInfo.CellSpacing, (j + 8)* m_initInfo.CellSpacing);
			Vector3 ur((i + 8)* m_initInfo.CellSpacing, m_HeightMap[index_ur] * m_initInfo.CellSpacing, (j + 8)* m_initInfo.CellSpacing);

			const int patch_id = j + (i / m_initInfo.CellsPerPatch);
			// bottom left
			{
				vertices[indexCounter].m_pos = bl;
				vertices[indexCounter].m_UV[0] = bl_uv.x;
				vertices[indexCounter].m_UV[1] = bl_uv.y;
				vertices[indexCounter].m_boundsY[0] = boundsY[patch_id].x;
				vertices[indexCounter].m_boundsY[1] = boundsY[patch_id].y;
				indices[indexCounter] = indexCounter;
				indexCounter++;
			}

			// bottom right
			{
				vertices[indexCounter].m_pos = br;
				vertices[indexCounter].m_UV[0] = br_uv.x;
				vertices[indexCounter].m_UV[1] = br_uv.y;
				vertices[indexCounter].m_boundsY[0] = boundsY[patch_id].x;
				vertices[indexCounter].m_boundsY[1] = boundsY[patch_id].y;
				indices[indexCounter] = indexCounter;
				indexCounter++;
			}

			// upper left
			{
				vertices[indexCounter].m_pos = ul;
				vertices[indexCounter].m_UV[0] = ul_uv.x;
				vertices[indexCounter].m_UV[1] = ul_uv.y;
				vertices[indexCounter].m_boundsY[0] = boundsY[patch_id].x;
				vertices[indexCounter].m_boundsY[1] = boundsY[patch_id].y;
				indices[indexCounter] = indexCounter;
				indexCounter++;
			}

			// upper right
			{
				vertices[indexCounter].m_pos = ur;
				vertices[indexCounter].m_UV[0] = ur_uv.x;
				vertices[indexCounter].m_UV[1] = ur_uv.y;
				vertices[indexCounter].m_boundsY[0] = boundsY[patch_id].x;
				vertices[indexCounter].m_boundsY[1] = boundsY[patch_id].y;
				indices[indexCounter] = indexCounter;
				indexCounter++;
			}
		}
	}

	std::string diffuseTxt_filepath = std::string("../Assets/") + diffuseTxt_filename;
	std::string normalTxt_filepath = std::string("../Assets/") + normalTxt_filename;
	std::string heightTxt_filepath = std::string("../Assets/") + heightTxt_filemane;

	MeshData* meshData = new MeshData(vertices, iNumVertices, indices, iNumIndices, sizeof(VertexTerrain));
	meshData->SetBoundingBox(AABB(Vector3(0, 0, 0), Vector3(m_initInfo.HeightmapHeight, 0, m_initInfo.HeightmapWidth)));
	Handle hMeshComp(sizeof(MeshComponent));
	new (hMeshComp) MeshComponent(meshData);
	SceneGraph::GetInstance()->AddComponent((MeshComponent*) hMeshComp.Raw());

	RenderPass* renderPass = new RenderPass;
	renderPass->SetVertexShader("../DEngine/Shaders/VS_terrain.hlsl");
	renderPass->SetHullShader("../DEngine/Shaders/HS_terrain.hlsl");
	renderPass->SetDomainShader("../DEngine/Shaders/DS_terrain.hlsl");
	renderPass->SetPixelShader("../DEngine/Shaders/PS_terrain.hlsl");
	Handle hTexture1(sizeof(Texture));
	new (hTexture1) Texture(Texture::SHADER_RESOURCES, 1, diffuseTxt_filepath.c_str());
	Handle hTexture2(sizeof(Texture));
	new (hTexture2) Texture(Texture::SHADER_RESOURCES, 1, normalTxt_filepath.c_str());
	Handle hTexture3(sizeof(Texture));
	new (hTexture3) Texture(Texture::SHADER_RESOURCES, 1, heightTxt_filepath.c_str());
	renderPass->AddTexture(hTexture1);
	renderPass->AddTexture(hTexture2);
	renderPass->AddTexture(hTexture3);
	renderPass->SetTopology(D3D_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
	renderPass->SetBlendState(State::NULL_STATE);
	renderPass->SetRenderTargets(D3D11Renderer::GetInstance()->m_pRTVArray, 2);
	renderPass->SetDepthStencilView(D3D11Renderer::GetInstance()->m_depth->GetDSV());
	renderPass->SetDepthStencilState(State::DEFAULT_DEPTH_STENCIL_DSS);
	renderPass->SetRasterizerState(State::CULL_BACK_RS);
	((MeshComponent*) hMeshComp.Raw())->m_pMeshData->m_Material.AddPassToTechnique(renderPass);

	GameObject* terrain = new GameObject;
	terrain->AddComponent((Component*) hMeshComp.Raw());

	delete[] vertices;
	delete[] indices;

	return terrain;
}
示例#9
0
void GLRenderer::occlusion_cull(Scene* scene,
        std::vector<SceneObject*>& scene_objects, ShaderManager *shader_manager,
        glm::mat4 vp_matrix) {

    if(!occlusion_cull_init(scene, scene_objects))
        return;

    for (auto it = scene_objects.begin(); it != scene_objects.end(); ++it) {
        SceneObject *scene_object = (*it);
        RenderData* render_data = scene_object->render_data();
        if (render_data == 0 || render_data->material(0) == 0) {
            continue;
        }

        //If a query was issued on an earlier or same frame and if results are
        //available, then update the same. If results are unavailable, do nothing
        if (!scene_object->is_query_issued()) {
            continue;
        }

        //If a previous query is active, do not issue a new query.
        //This avoids overloading the GPU with too many queries
        //Queries may span multiple frames

        bool is_query_issued = scene_object->is_query_issued();
        if (!is_query_issued) {
            //Setup basic bounding box and material
            RenderData* bounding_box_render_data(new RenderData());
            Mesh* bounding_box_mesh = render_data->mesh()->createBoundingBox();
            Material *bbox_material = new Material(
                    Material::BOUNDING_BOX_SHADER);
            RenderPass *pass = new RenderPass();
            pass->set_material(bbox_material);
            bounding_box_render_data->set_mesh(bounding_box_mesh);
            bounding_box_render_data->add_pass(pass);

            GLuint *query = scene_object->get_occlusion_array();

            glDepthFunc (GL_LEQUAL);
            glEnable (GL_DEPTH_TEST);
            glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

            glm::mat4 model_matrix_tmp(
                    scene_object->transform()->getModelMatrix());
            glm::mat4 mvp_matrix_tmp(vp_matrix * model_matrix_tmp);

            //Issue the query only with a bounding box
            glBeginQuery(GL_ANY_SAMPLES_PASSED, query[0]);
            shader_manager->getBoundingBoxShader()->render(mvp_matrix_tmp,
                    bounding_box_render_data,
                    bounding_box_render_data->material(0));
            glEndQuery (GL_ANY_SAMPLES_PASSED);
            scene_object->set_query_issued(true);

            glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

            //Delete the generated bounding box mesh
            bounding_box_mesh->cleanUp();
            delete bbox_material;
            delete pass;
            delete bounding_box_render_data;
        }

        GLuint query_result = GL_FALSE;
        GLuint *query = (*it)->get_occlusion_array();
        glGetQueryObjectuiv(query[0], GL_QUERY_RESULT_AVAILABLE, &query_result);

        if (query_result) {
            GLuint pixel_count;
            glGetQueryObjectuiv(query[0], GL_QUERY_RESULT, &pixel_count);
            bool visibility = ((pixel_count & GL_TRUE) == GL_TRUE);

            (*it)->set_visible(visibility);
            (*it)->set_query_issued(false);
            addRenderData((*it)->render_data());
            scene->pick(scene_object);
        }
    }
    scene->unlockColliders();
}
示例#10
0
int main(int argc, char *argv[]) {
    GLFWwindow* window = generateWindow();

    float rotX = 0.0f;
    float rotY = 0.0f;
    float distance = 40.0;
    float scale = 1.0;

    mat4 projection = perspective(45.0f, getRatio(window), 0.1f, 100.0f);
    
    RenderPass* renderBalls = new RenderPass(
        new Quad(),
        new ShaderProgram("/Impostor/impostorSpheres.vert", "/Impostor/impostorSpheres.frag"),
        getWidth(window),
        getHeight(window));
    renderBalls->texture("tex", renderBalls->get("fragColor"));
    renderBalls->update("projection", projection);

    RenderPass* output = new RenderPass(
        new Quad(),
        new ShaderProgram("/Filters/fullscreen.vert", "/Filters/toneMapperLinear.frag"));
    output->texture("tex", renderBalls->get("fragColor"));

    std::vector<vec4> balls;
    for (int i = 0; i < num_balls; i++)
        balls.push_back(vec4(r(15),r(15),r(15),5 + r(2)));

    glDisable(GL_DEPTH_TEST);
    render(window, [&] (float deltaTime) {
        //rotY += deltaTime * 0.1;
        if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS) (rotY - deltaTime < 0)? rotY -= deltaTime + 6.283 : rotY -= deltaTime;
        if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS) (rotY + deltaTime > 6.283)? rotY += deltaTime - 6.283 : rotY += deltaTime;
        if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS) (rotX - deltaTime < 0)? rotX -= deltaTime + 6.283 : rotX -= deltaTime;
        if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS) (rotX + deltaTime > 6.283)? rotX += deltaTime - 6.283 : rotX += deltaTime;
        if (glfwGetKey(window, GLFW_KEY_PAGE_DOWN) == GLFW_PRESS) distance += deltaTime * 10;
        if (glfwGetKey(window, GLFW_KEY_PAGE_UP) == GLFW_PRESS) distance = max(distance - deltaTime * 10, 0.0f);
        if (glfwGetKey(window, GLFW_KEY_PERIOD) == GLFW_PRESS) scale += deltaTime;
        if (glfwGetKey(window, GLFW_KEY_COMMA) == GLFW_PRESS) scale = glm::max(scale - deltaTime, 0.01f);

        mat4 view = translate(mat4(1), vec3(0,0,-distance)) * eulerAngleXY(-rotX, -rotY);

        renderBalls->clear(0,0,0,999);

        for(vec4 b : balls) {
            renderBalls->update("view", view);
            renderBalls->update("position", vec3(b.x, b.y, b.z));
            renderBalls->update("size", vec2(b.w * scale));
            renderBalls->run();
        }

        output->clear();
        output->run();
    });
}
示例#11
0
文件: Renderer.cpp 项目: Kaaml/Vxy
void Renderer::InitRendering()
{
	// TO DO: NAPISAC SHADERY DO DIR LIGHT, SPOT LIGHT I POINT LIGHT I PRZETESTOWAC DZIALANIE!!!!!!!!!!
	DirectLightSurface = PrefabShape::GenerateRectangle();
	SpotLightSurface = PrefabShape::GenerateRectangle();
	//PointLightSurface = PrefabShape::GenerateRectangle();

	cShaderManager *ShaderMgr = cShaderManager::GetInstance();
	cProgramShader *DirectLightShader = ShaderMgr->GetProgram( "DirectLight" );
	cProgramShader *SpotLightShader   = ShaderMgr->GetProgram( "SpotLight" );
	//cProgramShader *PointLightShader  = ShaderMgr->GetProgram( "PointLight" );

	MaterialManager& MatMgr = MaterialManager::GetSingleton();
	//auto DirLight = MatMgr.GetMaterialPtr( "DirectLight" );	

	RenderPass *DirectLight = new RenderPass();
	RenderPass *SpotLight = new RenderPass();
	//RenderPass *PointLight = new RenderPass();
	
	DirectLight->SetShader( DirectLightShader );
	SpotLight->SetShader( SpotLightShader );
	//PointLight->SetShader( PointLightShader );

	Material *DirectLightMaterial = new Material();
	Material *SpotLightMaterial = new Material();
	//Material *PointLightMaterial = new Material();

	DirectLightMaterial->AddRenderPass( DirectLight );
	SpotLightMaterial->AddRenderPass( SpotLight );
	//PointLightMaterial->AddRenderPass( PointLight );

	DirectLightSurface->SetMaterial( DirectLightMaterial );
	SpotLightSurface->SetMaterial( SpotLightMaterial );
	//PointLightSurface->SetMaterial( pPointLightMaterial );

	pDeferred = new Fbo( (GLuint) mViewSize.x, (GLuint)mViewSize.y );

	mLayers.push_back( new Texture2D( (int)mViewSize.x, (int)mViewSize.y, 0, FORMAT::RGB ) );
	mLayers.push_back( new Texture2D( (int)mViewSize.x, (int)mViewSize.y, 0, FORMAT::RGBA16F ) );
	mLayers.push_back( new Texture2D( (int)mViewSize.x, (int)mViewSize.y, 0, FORMAT::RGB ) );
	mLayers.push_back( new Texture2D( (int)mViewSize.x, (int)mViewSize.y, 0, FORMAT::RGB ) );
	//mLayers.push_back( new Texture2D( (int)mViewSize.x, (int)mViewSize.y, 0, FORMAT::RGB ) );
	mLayers.push_back( new Texture2D( (int)mViewSize.x, (int)mViewSize.y, 0, FORMAT::DEPTH24 ) );
	pDeferred->AddTextureAtachament( BUFFERTARGET::COLOR_ATTACHMENT0, mLayers[0] );
	pDeferred->AddTextureAtachament( BUFFERTARGET::COLOR_ATTACHMENT1, mLayers[1] );
	pDeferred->AddTextureAtachament( BUFFERTARGET::COLOR_ATTACHMENT2, mLayers[2] );
	pDeferred->AddTextureAtachament( BUFFERTARGET::COLOR_ATTACHMENT3, mLayers[3] );
	//pDeferred->AddTextureAtachament( BUFFERTARGET::COLOR_ATTACHMENT4, mLayers[4] );
	pDeferred->AddDepthAtachament( mLayers[4] );
	pDeferred->SetDrawBuffers( COLOR_ATTACHMENT0, COLOR_ATTACHMENT1, COLOR_ATTACHMENT2, COLOR_ATTACHMENT3/*, COLOR_ATTACHMENT4*/ );
	
	TextureSampler *sampler1 = new TextureSampler( mLayers[0], 0, TF_LINEAR, TF_LINEAR, WM_CLAMP, WM_CLAMP );
	TextureSampler *sampler2 = new TextureSampler( mLayers[1], 1, TF_LINEAR, TF_LINEAR, WM_CLAMP, WM_CLAMP );
	TextureSampler *sampler3 = new TextureSampler( mLayers[2], 2, TF_LINEAR, TF_LINEAR, WM_CLAMP, WM_CLAMP );
	//TextureSampler *sampler4 = new TextureSampler( mLayers[3], 3, TF_LINEAR, TF_LINEAR, WM_CLAMP, WM_CLAMP );
	//TextureSampler *sampler5 = new TextureSampler( mLayers[4], 4 ); 
	DirectLight->AddTexture( sampler1 );				    // OutputAmbient = 0
	DirectLight->AddTexture( sampler2 );					// OutputNormal =1
	DirectLight->AddTexture( sampler3 );					// OutputPosition =2
	//PointLight->AddTexture( sampler4 );					// OutputDiffuse =3
	//PointLight->AddTexture( sampler5 );		

	SpotLight->AddTexture( sampler1 );						// OutputAmbient = 0
	SpotLight->AddTexture( sampler2 );					    // OutputNormal =1
	SpotLight->AddTexture( sampler3 );					    // OutputPosition =2

	//PointLight->AddTexture( sampler1 );						//OutputAmbient = 0
	//PointLight->AddTexture( sampler2 );					    // OutputNormal =1
	//PointLight->AddTexture( sampler3 );					    // OutputPosition =2
														  
}
示例#12
0
文件: proctex.cpp 项目: tapio/liblub
 void renderFrame(){
   defaultPass->render();
   float time = float(Timer::Instance().secoundsPassed) + float(Timer::Instance().nanosecoundsPassed)/1000000000.0;
   perlinNoise->use();
   perlinNoise->setUniform("time", time);
 }
示例#13
0
void Material::ReadFromFile(const char * filename, int meshType)
{
	FILE* pFile = fopen(filename, "r");
	RenderPass* pass = new RenderPass;

	char c[256];
	float r, g, b;
	fscanf(pFile, "%s", &c);
	// read factors
	fscanf(pFile, "%f %f %f", &r, &g, &b);
	m_vEmissive = Vector3(r, g, b);
	fscanf(pFile, "%f %f %f", &r, &g, &b);
	m_vDiffuse = Vector3(r, g, b);
	fscanf(pFile, "%f %f %f", &r, &g, &b);
	m_vSpecular = Vector3(r, g, b);
	fscanf(pFile, "%f", &r);
	m_fShininess = r;
	// read textures
	int size;
	fscanf(pFile, "%i", &size);
	for (int i = 0; i < size; ++i)
	{
		fscanf(pFile, "%s", &c);
		std::string str(c);
		if (!str.compare("DiffuseColor"))
		{
			m_TexFlag |= DIFFUSE;
		}
		else if (!str.compare("NormalMap") || !str.compare("Bump"))
		{
			m_TexFlag |= NORMAL;
		}
		else if (!str.compare("SpecularColor") || !str.compare("Specular"))
		{
			m_TexFlag |= SPECULAR;
		}
		fscanf(pFile, "%s", &c);
		Handle hTexture(sizeof(Texture));
		new (hTexture) Texture(Texture::SHADER_RESOURCES, 1, c, 10);
		pass->AddTexture(hTexture);
	}

	fclose(pFile);

	// decide which technique to use
	switch (meshType)
	{
	case eMeshType::OUTLINE:
		pass->SetVertexShader("../DEngine/Shaders/VS_vertex1P.hlsl");
		break;
	case eMeshType::STANDARD_MESH:
		pass->SetVertexShader("../DEngine/Shaders/VS_vertex1P1N1T1UV.hlsl");
		break;
	case eMeshType::SKELETAL_MESH:
		pass->SetVertexShader("../DEngine/Shaders/VS_vertex1P1N1T1UV4J.hlsl");
		break;
	}
	if (m_TexFlag == (DIFFUSE | NORMAL | SPECULAR))
	{
		pass->SetPixelShader("../DEngine/Shaders/PS_vertex1P1N1T1UV_DiffuseSpecularBump_deferred.hlsl");
	}
	else if (m_TexFlag == (DIFFUSE | NORMAL))
	{
		pass->SetPixelShader("../DEngine/Shaders/PS_vertex1P1N1T1UV_DiffuseBump_deferred.hlsl");
	}
	else if (m_TexFlag == (DIFFUSE | SPECULAR))
	{
		pass->SetPixelShader("../DEngine/Shaders/PS_vertex1P1N1T1UV_DiffuseSpecular_deferred.hlsl");
	}
	else if (m_TexFlag == DIFFUSE)
	{
		pass->SetPixelShader("../DEngine/Shaders/PS_vertex1P1N1T1UV_Diffuse_deferred.hlsl");
	}
	else
	{
		pass->SetPixelShader(nullptr);
	}
	pass->SetBlendState(State::NULL_STATE);
	pass->SetRenderTargets(D3D11Renderer::GetInstance()->m_pRTVArray, 2);
	pass->SetDepthStencilView(D3D11Renderer::GetInstance()->m_depth->GetDSV());
	pass->SetDepthStencilState(State::DEFAULT_DEPTH_STENCIL_DSS);
	((RenderTechnique*)m_hRenderTechnique.Raw())->AddPass(pass);
}
示例#14
0
bool	LoadScript( char* filename )
{
	FILE*	F;
	if ( ( F = fopen( filename , "rt" ) ) != NULL ) 
	{
		char*	lineptr;
		while ( !feof( F ) )
		{
			lineptr = getline( F );
			if ( lineptr != NULL )
			{
				char*	Token = getstring( lineptr );
				if ( ( stricmp( Token , "{" ) == 0 ) ||
					 ( stricmp( Token , "}" ) == 0 ) )
				{
					Debug("surface expected, got: %s",Token);
					return false;
				} else
				{
					if ( lineptr != NULL ) {
						Debug("surface name followed by unexpected token: %s",lineptr);
						return false;
					}

					Surface*	newSurface;
					if ( ( newSurface = CreateSurface( Token ) ) != NULL )
					{
						lineptr = getline( F );
						if ( lineptr == NULL ) {
							Error("unexpected end of file"); return false;
						}
						Token = getstring( lineptr );
						if ( stricmp( Token , "{" ) != 0 ) {
							Error("unexpected token found: %s", Token); return false;
						}
						if ( lineptr != NULL ) {
							Error("{ followed by unexpected token: %s", lineptr); 
							return false;
						}
						while ( ( ( Token = lineptr = getline( F ) ) != NULL ) &&
							    ( ( Token = getstring( lineptr ) ) != NULL ) &&
							    ( stricmp( Token , "}" ) != 0 ) )
						{
							if ( stricmp( Token , "{" ) != 0 )
							{
								newSurface->AddParam( Token , lineptr );
							} else
							{
								if ( lineptr != NULL ) {
									Error("{ followed by unexpected token: %s", lineptr); 
									return false;
								}
								RenderPass*	newPass = new RenderPass;
								while ( ( ( Token = lineptr = getline( F ) ) != NULL ) &&
										( ( Token = getstring( lineptr ) ) != NULL ) &&
										( stricmp( Token , "}" ) != 0 ) )
								{
									newPass->AddParam( Token , lineptr );
								}
								if ( Token == NULL ) {
									Error("unexpected end of file"); return false;
								}
								if ( lineptr != NULL ) {
									Error("} followed by unexpected token: %s ", lineptr); 
									return false;
								}
								newSurface->AddPass( newPass );
							}
						}
						if ( Token == NULL ) {
							Error("unexpected end of file"); return false;
						}
						if ( lineptr != NULL ) {
							Error("} followed by unexpected token: %s ", lineptr); 
							return false;
						}
					} else
						Error("failed to make surface");
				}
			}
		}
		fclose(F);
		return true;
	} else
		return false;
}
示例#15
0
void PortholeCustomDrawApplication::initializeRenderer(Renderer* r) 
{ 
	RenderPass* rp = new PortholeRenderPass(r, this);
	rp->setCameraMask(PORTHOLE_CAMERA_MASK);
	r->addRenderPass(rp);
}