void gfx::BloomProgram::Render(){
	//Do brightpass
	ShaderProgram* prog = g_ShaderBank.GetProgramFromHandle(m_BrightPassShader);
	prog->Apply();
	const int WORK_GROUP_SIZE = 32;
	GLuint WorkGroupSizeX = GLuint((m_Width + WORK_GROUP_SIZE - 1) / float(WORK_GROUP_SIZE));
	GLuint WorkGroupSizeY = GLuint((m_Height + WORK_GROUP_SIZE - 1) / float(WORK_GROUP_SIZE));
	prog->SetUniformTextureHandle("g_Image", m_TargetTex, 1);
	prog->SetUniformVec2("g_ScreenSize", glm::vec2(m_Width, m_Height));
	prog->SetUniformFloat("g_Threshold", 0.4f);
	prog->SetUniformFloat("g_Smoothness", 0.8f);
	glBindImageTexture(0, m_BloomTexture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);
	glDispatchCompute(WorkGroupSizeX, WorkGroupSizeY, 1);
	//blur result
	m_BlurProgram->Render();
	//add to final target
	prog = g_ShaderBank.GetProgramFromHandle(m_BloomShader);
	prog->Apply();
	prog->SetUniformTextureHandle("g_BluredBloomTex", m_BlurProgram->GetBluredTexture(), 1);
	prog->SetUniformTextureHandle("g_ColorBuffer", m_TargetTex, 2);
	prog->SetUniformVec2("g_ScreenSize", glm::vec2(m_Width, m_Height));
	glBindImageTexture(0, m_BloomTexture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);
	glDispatchCompute(WorkGroupSizeX, WorkGroupSizeY, 1);

}
void ShadowMap::Render( RenderQueue* rq ) {
	ShaderProgram* prog = g_ShaderBank.GetProgramFromHandle( m_Shader );

	prog->Apply();
	glBindFramebuffer( GL_FRAMEBUFFER, m_FrameBuffer );

	glEnable( GL_DEPTH_TEST );
	glEnable(  GL_CULL_FACE );
	glCullFace( GL_BACK);
	const GLfloat one = 1.0f;
	glClearBufferfv( GL_DEPTH, 0, &one );
	glViewport( 0, 0, m_Size, m_Size );
	glEnable(GL_POLYGON_OFFSET_FILL);
	glPolygonOffset( 1.0f, 4.0f );

	//glm::mat4 viewProj = m_Proj * m_View;
	//prog->SetUniformMat4( "g_ViewProj", viewProj );
	//unsigned int bufferOffset  = 0;
	//unsigned int instanceCount = 0;
	//g_ModelBank.ApplyBuffers();
	//// for each model to be rendered
	//for ( auto& mo : rq->GetModelQueue() ) {
	//	const Model& model = g_ModelBank.FetchModel( mo.Model );
	//	instanceCount = mo.InstanceCount;
	//	prog->SetUniformUInt( "g_BufferOffset", bufferOffset );
	//	// for each mesh
	//	for ( auto& mesh : model.Meshes ) {
	//		glDrawElementsInstanced( GL_TRIANGLES, mesh.Indices, GL_UNSIGNED_INT,
	//			( GLvoid* )( 0 + ( ( model.IndexHandle + mesh.IndexBufferOffset ) * sizeof( unsigned int ) ) ), instanceCount );
	//	}
	//	bufferOffset += instanceCount;
	//}
	//glDisable(GL_POLYGON_OFFSET_FILL);
}
void TerrainDeformationProgram::Initialize(){
	m_FrameBuffer = new FrameBuffer();
	m_FrameBuffer->Init();

	glGenTextures(1, &m_BrushTexture);
	glBindTexture(GL_TEXTURE_2D, m_BrushTexture);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_BRUSH_RES, m_BRUSH_RES, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glBindTexture(GL_TEXTURE_2D, 0);
	//fill in brush
	m_BrushGenProgram = g_ShaderBank.LoadShaderProgram("../../../shader/BrushTexGenProgram.glsl");
	ShaderProgram* prog = g_ShaderBank.GetProgramFromHandle(m_BrushGenProgram);
	prog->Apply();
	prog->SetUniformFloat("hardness", 1.0f);
	glBindImageTexture(0, m_BrushTexture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);
	const int WORK_GROUP_SIZE = 32;
	GLuint WorkGroupSize = GLuint((m_BRUSH_RES + WORK_GROUP_SIZE - 1) / float(WORK_GROUP_SIZE));
	glDispatchCompute(WorkGroupSize, WorkGroupSize, 1);
	
	m_DrawProgram = g_ShaderBank.LoadShaderProgram("../../../shader/SpriteShader.glsl");
	m_BrushTex = new Texture();
	m_BrushTex->Init("../../../binasset/texture/brush.png", TEXTURE_COLOR);

	m_FilterProgram = g_ShaderBank.LoadShaderProgram("../../../shader/TerrainDeformFilter.glsl");
}
void gfx::LineRenderProgram::Draw()
{
	glDisable( GL_DEPTH_TEST );
	glLineWidth(4.0f);
	glEnable(GL_BLEND);
	ShaderProgram* prog = g_ShaderBank.GetProgramFromHandle(m_ProgramHandle);
	prog->Apply();
	glm::mat4 vp = m_RenderJobManager->GetProj() * m_RenderJobManager->GetView();
	prog->SetUniformMat4("vp", vp);
	
	rVector<Line>& lines = m_RenderJobManager->GetLines();
	for(int i = 0; i < lines.size(); i++)
	{
		prog->SetUniformVec4("Color", lines[i].Color);
		prog->SetUniformVec3("pos1", lines[i].Origin);
		prog->SetUniformVec3("pos2", lines[i].Destination);
		prog->SetUniformFloat("animation", lines[i].AnimationProgres);
		if(lines[i].Dashed)
		{
			prog->SetUniformTextureHandle("Tex", m_DashedTexture, 0);
		}
		else
		{
			prog->SetUniformTextureHandle("Tex", m_Texture, 0);
		}
		glBindVertexArray( 0 );
		glDrawArrays(GL_POINTS, 0, 1);
	}
	glUseProgram( 0 );
	glEnable( GL_DEPTH_TEST );
	glLineWidth(1.0f);
	glDisable(GL_BLEND);
}
void gfx::GraphicsEngine::RenderToTexture(RenderQueue* drawQueue){
	TextureHandle target = drawQueue->GetTargetTexture();
	m_FrameBuffer.SetTexture(target);
	m_FrameBuffer.Apply();

	ShaderProgram* spriteProg = g_ShaderBank.GetProgramFromHandle(m_SpriteShader);
	spriteProg->Apply();
	glBindVertexArray(0);
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	static bool additive = false; 
	ImGui::Checkbox("Additive", &additive);
	if (additive){
		glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	}
	else {
		glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
	}
	//static glm::vec4 color = glm::vec4(1);
	//ImGui::ColorEdit4("BrushColor", &color[0], true);

	for (auto& brush : drawQueue->GetBrushQueue()){
		Texture* brushTex = g_MaterialBank.GetTexture(brush.Texture);
		glm::vec2 brushSize(brush.Size / (m_Width * 0.5f), brush.Size / m_Height);

		spriteProg->SetUniformVec4("g_Pos", glm::vec4(glm::vec2(brush.Position.x - brushSize.x * 0.5f, 1.0f - brush.Position.y + brushSize.y * 0.5f), 0, 0));
		spriteProg->SetUniformVec4("g_Size", glm::vec4(brushSize.x, brushSize.y, 1, 1));
		spriteProg->SetUniformVec4("g_Color", ColorPicker::m_color);
		brushTex->Apply(spriteProg->FetchUniform("g_Texture"), 0);
		spriteProg->SetUniformBool("g_GreyScale", false);
		glDrawArrays(GL_POINTS, 0, 1);
	}
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void gfx::GraphicsEngine::RenderLines(RenderQueue* drawQueue){
	//Fill vertex buffer
	int bufferSize = 0;
	for (auto& it : drawQueue->GetLineQueue()){
		bufferSize += it.Lines.size();
	}
	int i = 0;
	for (auto& it : drawQueue->GetLineQueue()){
		memcpy(m_LineBuffer + i * sizeof(glm::vec2), it.Lines.data(), it.Lines.size() * sizeof(glm::vec2));
		i += it.Lines.size();
	}
	glBindBuffer(GL_ARRAY_BUFFER, m_LineVBO);
	glBufferSubData(GL_ARRAY_BUFFER, 0, bufferSize * sizeof(glm::vec2), m_LineBuffer);
	glBindVertexArray(m_LineVAO);
	//set shader
	ShaderProgram* prog = g_ShaderBank.GetProgramFromHandle(m_LineProgram);
	prog->Apply();
	prog->SetUniformVec2("g_ScreenSize", glm::vec2(m_Width, m_Height));
	prog->SetUniformVec2("g_ScreenPos", glm::vec2(0, 0));
	//issue draw calls
	i = 0;
	glViewport(0, 0,m_Width,m_Height);
	for (auto& it : drawQueue->GetLineQueue()){
		prog->SetUniformVec4("g_Color", it.Color);
		glDrawArrays(GL_LINES, i, it.Lines.size());
		i += it.Lines.size();
	}
	
}
void gfx::GraphicsEngine::RenderSprites(RenderQueue* drawQueue){
	glViewport(0, 0, m_Width, m_Height);
	//Render Sprites
	ShaderProgram* spriteProg = g_ShaderBank.GetProgramFromHandle(m_SpriteShader);
	spriteProg->Apply();
	glBindVertexArray(0);
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	for (int layer = 0; layer < 3; layer++){
		for (auto& spr : drawQueue->GetSpriteQueue()[layer]){
			spriteProg->SetUniformVec4("g_Pos", spr.GetPosFlt());
			spriteProg->SetUniformVec4("g_Size", spr.GetSizeFlt());
			spriteProg->SetUniformVec4("g_Color", spr.GetColor());
			g_MaterialBank.GetTexture(spr.GetTexture())->Apply(spriteProg->FetchUniform("g_Texture"), 0);
			if (g_MaterialBank.GetTexture(spr.GetTexture())->GetChannels() == 1){
				spriteProg->SetUniformBool("g_GreyScale", true);
			}
			else{
				spriteProg->SetUniformBool("g_GreyScale", false);
			}
			glDrawArrays(GL_POINTS, 0, 1);
		}
	}
}
void TerrainDeformationProgram::Render(RenderQueue* rq){
	ShaderProgram* prog = g_ShaderBank.GetProgramFromHandle(m_DrawProgram);
	prog->Apply();
	
	glBindVertexArray(0);
	glEnable(GL_BLEND);
	glDisable(GL_DEPTH_TEST);
	glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
	//glBlendFunc(GL_SRC_ALPHA, GL_ONE); //additive
	for (auto& td : rq->GetDeformations()){
		Terrain* terrain = g_TerrainManager.GetTerrainFromHandle(td.Terrain);
		glm::vec2 textureSize = terrain->GetHeightHighResSize();

		m_FrameBuffer->SetTexture(terrain->GetHeightMap(), textureSize.x, textureSize.y);
		m_FrameBuffer->Apply();
		glViewport(0, 0, textureSize.x, textureSize.y);
		//prog->SetUniformTextureHandle("g_Texture", m_BrushTexture, 0);
		m_BrushTex->Apply(prog->FetchUniform("g_Texture"), 0);
		prog->SetUniformVec4("g_Pos", glm::vec4(td.Position.x , 1.0f - td.Position.y, 0, 0));
		prog->SetUniformVec4("g_Size", glm::vec4(td.Size, 1, 1));
		glm::vec3 dir = td.Up ? glm::vec3(1) : glm::vec3(0);
		prog->SetUniformVec4("g_Color", glm::vec4(dir, td.Strength));
		prog->SetUniformBool("g_GreyScale", false);
		glDrawArrays(GL_POINTS, 0, 1);
		//filter area
		glm::vec4 pixelArea = glm::vec4((td.Position * textureSize) - glm::vec2(-2), (td.Size * textureSize) + glm::vec2(4));
		const int WORK_GROUP_SIZE = 32;
		GLuint WorkGroupSizeX = GLuint((pixelArea.z + WORK_GROUP_SIZE - 1) / float(WORK_GROUP_SIZE));
		GLuint WorkGroupSizeY = GLuint((pixelArea.w + WORK_GROUP_SIZE - 1) / float(WORK_GROUP_SIZE));

		ShaderProgram* prog = g_ShaderBank.GetProgramFromHandle(m_FilterProgram);
		prog->Apply();
		prog->SetUniformVec4("g_PixelArea", pixelArea);
		glBindImageTexture(0, terrain->GetHeightMap(), 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_R32F);
		glDispatchCompute(WorkGroupSizeX, WorkGroupSizeY, 1);
	}
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glDisable(GL_BLEND);
}
void gfx::GraphicsEngine::RenderGizmos(RenderQueue* drawQueue){
	ShaderProgram* prog = g_ShaderBank.GetProgramFromHandle(m_GizmoProgram);
	prog->Apply();
	prog->SetUniformMat4("g_ViewProj", m_Camera.GetViewProjection());
	glDisable(GL_DEPTH_TEST);
	for (auto& gizmo : drawQueue->GetGizmoQueue()){
		Model model = g_ModelBank.FetchModel(gizmo.Model);
		prog->SetUniformMat4("g_World", gizmo.world);
		for (auto& mesh : model.Meshes){
			prog->SetUniformVec4("g_Color", gizmo.Color);
			glDrawElements(GL_TRIANGLES, mesh.Indices, GL_UNSIGNED_INT,
				(GLvoid*)(0 + ((model.IndexHandle + mesh.IndexBufferOffset) * sizeof(unsigned int))));
		}
	}
	glEnable(GL_DEPTH_TEST);
}
void gfx::GraphicsEngine::RenderWireFrame(RenderObject ro){
	glViewport(0, 0, (GLsizei)(m_Width * 0.5f), (GLsizei)m_Height);
	glDepthFunc(GL_EQUAL);
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	g_ModelBank.ApplyBuffers();
	ShaderProgram* prog = g_ShaderBank.GetProgramFromHandle(m_Shader);
	prog->Apply();
	prog->SetUniformMat4("g_ViewProj", m_Camera.GetViewProjection());
	prog->SetUniformVec3("g_Campos", m_Camera.GetPosition());

	Model model = g_ModelBank.FetchModel(ro.Model);
	prog->SetUniformMat4("g_World", ro.world);
	for (auto& mesh : model.Meshes){
		glDrawElements(GL_TRIANGLES, mesh.Indices, GL_UNSIGNED_INT,
			(GLvoid*)(0 + ((model.IndexHandle + mesh.IndexBufferOffset) * sizeof(unsigned int))));
	}

	glDepthFunc(GL_LESS);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
void gfx::GraphicsEngine::RenderGeometry(RenderQueue* drawQueue){
	glViewport(0, BUTTON_SIZE, (GLsizei)(m_Width * 0.5f), (GLsizei)m_Height - BUTTON_SIZE * 2);
	//glDisable(GL_BLEND);
	glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_DEPTH_TEST);
	g_ModelBank.ApplyBuffers();
	ShaderProgram* prog = g_ShaderBank.GetProgramFromHandle(m_Shader);
	prog->Apply();
	prog->SetUniformMat4("g_ViewProj", m_Camera.GetViewProjection());
	prog->SetUniformVec3("g_Campos", m_Camera.GetPosition());
	glm::vec3 lightDir = glm::vec3(0.5f,-1,0.5f);
	static float lightangle = 4.0f;

	glm::vec4 temp = glm::vec4(lightDir, 0) * glm::rotate(lightangle, glm::vec3(0, 1, 0));
	prog->SetUniformVec3("g_LightDir", glm::vec3(temp.x, temp.y, temp.z));
	prog->SetUniformVec3("g_CamDir", m_Camera.GetForward());
	m_SkyTex->Apply(prog->FetchUniform("g_SkyCubeTex"), 1);
	m_IrradianceTex->Apply(prog->FetchUniform("g_IrradianceCubeTex"), 2);

	for (auto& object : drawQueue->GetQueue()){
		Model model = g_ModelBank.FetchModel(object.Model);
		prog->SetUniformMat4("g_World", object.world);
		for (auto& mesh : model.Meshes){
			Material* mat = g_MaterialBank.GetMaterial(model.MaterialOffset + mesh.Material);
			Texture* albedoTex = g_MaterialBank.GetTexture(mat->GetAlbedoTexture());
			Texture* normalTex = g_MaterialBank.GetTexture(mat->GetNormalTexture());
			Texture* roughnessTex = g_MaterialBank.GetTexture(mat->GetRoughnessTexture());
			Texture* metalTex = g_MaterialBank.GetTexture(mat->GetMetalTexture());
			prog->SetUniformTextureHandle("g_DiffuseTex", albedoTex->GetHandle(), 0);
			prog->SetUniformTextureHandle("g_NormalTex", normalTex->GetHandle(), 3);
			prog->SetUniformTextureHandle("g_RoughnessTex", roughnessTex->GetHandle(), 4);
			prog->SetUniformTextureHandle("g_MetallicTex", metalTex->GetHandle(), 5);
			glDrawElements(GL_TRIANGLES, mesh.Indices, GL_UNSIGNED_INT,
				(GLvoid*)(0 + ((model.IndexHandle + mesh.IndexBufferOffset) * sizeof(unsigned int))));
		}
	}
}
void gfx::GraphicsEngine::RenderActiveTarget(){
	glViewport((GLint)(m_Width * 0.5f), BUTTON_SIZE, (GLint)(m_Width * 0.5f), m_Height - BUTTON_SIZE * 2);
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	ShaderProgram* spriteProg = g_ShaderBank.GetProgramFromHandle(m_SpriteShader);
	spriteProg->Apply();
	glBindVertexArray(0);
	Texture* tex = g_MaterialBank.GetTexture(m_FrameBuffer.GetTexture());
	float sizeH;
	sizeH = tex->GetHeight() / tex->GetWidth();
	tex->Apply(spriteProg->FetchUniform("g_Texture"), 0);
	spriteProg->SetUniformVec4("g_Color", glm::vec4(1));
	spriteProg->SetUniformVec4("g_Pos", glm::vec4(0.0f, 0.5f + sizeH * 0.5f, 0.0f,0.0f));
	spriteProg->SetUniformVec4("g_Size", glm::vec4(1.0f, sizeH, 1.0f, 1.0f));
	if (tex->GetChannels() == 1){
		spriteProg->SetUniformBool("g_GreyScale", true);
	}
	else{
		spriteProg->SetUniformBool("g_GreyScale", false);
	}
	glDrawArrays(GL_POINTS, 0, 1);

}
Beispiel #13
0
	bool Init(int argc, char** argv)
	{
		GetCLDev();

		m_backend->Init(argc, argv);
		m_aspectRatio = m_win_h / (float)m_win_w;

		if (!m_backend->CreateWin(m_win_w, m_win_h, false, "OpenGL test app"))
		{
			fprintf(stderr, "Faild to create window");
			return false;
		}

		GLenum res = glewInit();
		if (res != GLEW_OK) {
			fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
			return false;
		}

		if (!InitCL())
		{
			return false;
		}

		wglSwapIntervalEXT(0);

		glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		//glFrontFace(GL_CW);
		//glCullFace(GL_BACK);
		//glEnable(GL_CULL_FACE);

		//glEnable(GL_DEPTH_TEST);

		m_bodies.push_back(Body(Vector2f(-0.8f, -0.8f), Vector2f(0.021f, 0.0f), Vector2f(-0.05f, 0.11f), Vector2f(0.0f, 0.0f)));
		m_bodies.push_back(Body(Vector2f(0.8f, 0.8f), Vector2f(0.021f, 0.0f), Vector2f(0.05f, -0.11f), Vector2f(0.0f, 0.0f)));
		m_bodies.push_back(Body(Vector2f(-0.8f, 0.8f), Vector2f(0.014f, 0.0f), Vector2f(0.01f, 0.1f), Vector2f(0.0f, 0.0f)));
		m_bodies.push_back(Body(Vector2f(0.8f, -0.8f), Vector2f(0.016f, 0.0f), Vector2f(0.01f, 0.1f), Vector2f(0.0f, 0.0f)));
		m_bodies.push_back(Body(Vector2f(0.0f, 0.0f), Vector2f(0.3f, 0.0f), Vector2f(0.0f, 0.0f), Vector2f(0.0f, 0.0f)));

		for (int i = 0; i < 5000; ++i)
		{
			m_bodies.push_back(Body(Vector2f((rand() % 100000) / 1000.0f - 1.0f, (rand() % 100000) / 1000.0f - 1.0f), Vector2f(rand() % 300 / 1000.0f, 0.0f), Vector2f((rand() % 2000) / 1000.0f - 1.0f, (rand() % 2000) / 1000.0f - 1.0f), Vector2f(0.0f, 0.0f)));
		}

		glGenBuffers(1, &m_VB);
		glBindBuffer(GL_ARRAY_BUFFER, m_VB);
		glBufferData(GL_ARRAY_BUFFER, sizeof(Body) * m_bodies.size(), &m_bodies[0], GL_DYNAMIC_DRAW);

		cl_int ret = 0;
		m_clVB = clCreateFromGLBuffer(m_clContext, CL_MEM_READ_WRITE, m_VB, &ret);
		clErrNoAssert(ret);
		ret = clSetKernelArg(m_kernelCalcForces, 0, sizeof(cl_mem), (void *)&m_clVB);
		clErrNoAssert(ret);
		ret = clSetKernelArg(m_kernelMove, 0, sizeof(cl_mem), (void *)&m_clVB);
		clErrNoAssert(ret);

		m_last_time_dt = 0;
		m_time_shift = 1;
		m_dt = 0.00001f;

		m_shaderProgram = new CommonShaderProgram("vertexshader.txt", "pixelshader.txt", "geometryshader.txt");
		m_shaderProgram->Compile();
		m_shaderProgram->Apply();
		m_shaderProgram->SetScale(m_scale);
		m_shaderProgram->SetOffset(m_offset);
		m_shaderProgram->SetAspectRatio(m_aspectRatio);

		return true;
	}
void gfx::BasicRenderProgram::Draw(DrawData* data)
{
	//draw
	int flag = data->ShaderFlags;
	g_ModelBank.ApplyBuffers( POS_NORMAL_TEX_TANGENT );
	ShaderProgram* prog = g_ShaderBank.GetProgramFromHandle(m_ProgramHandle);
	
	prog->Apply();
	m_RenderJobManager->BindBuffers(prog);
	GLint loc = -1;
	if(flag & FRAGMENT_DIFFUSEMAP)
	{
		Texture* diffuse = g_MaterialBank.GetTextureAtlasTex(Texture_Atlas_Type::Diffuse);
		loc = prog->FetchUniform("g_DiffuseTex");
		diffuse->Apply(loc, 0);
		prog->SetUniformBool("useDiffuse",true);
	}
	else
	{
		prog->SetUniformBool("useDiffuse",false);
	}
	if(flag & FRAGMENT_NORMALMAP)
	{
		Texture* normal = g_MaterialBank.GetTextureAtlasTex(Texture_Atlas_Type::Normal);
		loc = prog->FetchUniform("g_NormalTex");
		normal->Apply(loc, 1);
		prog->SetUniformBool("useNormal",true);
	}
	else
	{
		prog->SetUniformBool("useNormal",false);
	}
	if(flag & FRAGMENT_ROUGHNESSMAP)
	{
		Texture* roughness = g_MaterialBank.GetTextureAtlasTex(Texture_Atlas_Type::Roughness);
		loc = prog->FetchUniform("g_RoughnessTex");
		roughness->Apply(loc, 2);
		prog->SetUniformBool("useRoughness",true);
	}
	else
	{
		prog->SetUniformBool("useRoughness",false);
	}
	if(flag & FRAGMENT_METALMAP)
	{
		Texture* metal = g_MaterialBank.GetTextureAtlasTex(Texture_Atlas_Type::Metal);
		loc = prog->FetchUniform("g_MetalTex");
		metal->Apply(loc, 3);
		prog->SetUniformBool("useMetal",true);
	}
	else
	{
		prog->SetUniformBool("useMetal",false);
	}
	BasicData* frameData = (BasicData*)(data->ExtraData);
	prog->SetUniformInt("numPLights", frameData->PointLightCount);
	prog->SetUniformInt("numDLights", frameData->DirLightCount);
	prog->SetUniformUInt("BatchCounts",frameData->BatchOffset);
	prog->SetUniformVec2("g_WorldSize", frameData->WorldSize);
	prog->SetUniformMat4("ShadowMat",frameData->ShadowMat);
	loc = prog->FetchUniform("g_LightCubeTex");
	frameData->SkyTex->Apply(loc, 4);
	loc = prog->FetchUniform("g_IrradianceCube");
	frameData->IrradianceTex->Apply(loc, 5);

	//fog tex
	loc = prog->FetchUniform("g_FogOfWarTex");
	glUniform1i(loc,6);
	glActiveTexture(GL_TEXTURE6);
	glBindTexture(GL_TEXTURE_2D, frameData->FogTex);

	//fog tex
	loc = prog->FetchUniform("g_ShadowMap");
	glUniform1i(loc,7);
	glActiveTexture(GL_TEXTURE7);
	glBindTexture(GL_TEXTURE_2D, frameData->ShadowTex);

	
	if (m_HasDrawID)
	{
		GPU_PROFILE( AutoGPUProfiler gpMultiDraw( "BasicRenderProgramMultiDrawElementsIndirect" ); );
		glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, (GLvoid*)(sizeof(IndirectDrawCall) * (frameData->BatchOffset)), frameData->BatchCount, 0);
		GPU_PROFILE( gpMultiDraw.Stop(); );