Exemplo n.º 1
0
void DirectxEngine::RenderBlur(const PostProcessing& post)
{
    SetRenderState(false, false);
    EnableAlphaBlending(false, false);

    m_data->blurTarget.SetActive(m_data->context);

    SetSelectedShader(BLUR_HORIZONTAL_SHADER);
    auto& blurHorizontal = m_data->shaders[BLUR_HORIZONTAL_SHADER];

    blurHorizontal->UpdateConstantFloat("blurStep", &post.BlurStep(), 1);
    blurHorizontal->SendConstants(m_data->context);

    blurHorizontal->SendTexture(m_data->context, 0, m_data->preEffectsTarget);

    m_data->quad.Render(m_data->context);

    blurHorizontal->ClearTexture(m_data->context, 0);

    SetSelectedShader(BLUR_VERTICAL_SHADER);
    auto& blurVertical = m_data->shaders[BLUR_VERTICAL_SHADER];

    blurVertical->UpdateConstantFloat("blurStep", &post.BlurStep(), 1);
    blurVertical->SendConstants(m_data->context);

    m_data->blurTarget.CopyTextures(m_data->context);
    
    blurVertical->SendCopiedTexture(m_data->context, 0, m_data->blurTarget);
    
    m_data->quad.Render(m_data->context);
    
    blurHorizontal->ClearTexture(m_data->context, 0);
}
//Used to bind the postprocessing, and clear the screen and the colour buffer
//to get the screen ready, then renders the Skybox and other GameObjects
//then adds renders the postprocessing effects.
void SplashScreen::render(SDL_Window *window)
{
	postProcessor.bind();

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glClearDepth(1.0f);
	//clear the colour and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	renderSkyBox();

	//alternative sytanx
	for (auto iter = displayList.begin(); iter != displayList.end(); iter++)
	{
		renderGameObject((*iter));
	}

	postProcessor.preDraw();
	GLint colourFilterLocation = postProcessor.getUniformVariableLocation("colourFilter");
	glUniformMatrix3fv(colourFilterLocation, 1, GL_FALSE, glm::value_ptr(selectedColour));
	//draw
	postProcessor.draw();

	//post draw
	postProcessor.postDraw();

	SDL_GL_SwapWindow(window);
}
void TemplateParameters::readReweightingParameters(const Json::Value& reweighting, PostProcessing& postproc)
/*****************************************************************/
{
    vector<unsigned int> axes;
    const Json::Value ax = reweighting["axes"];
    if(!ax.isNull())
    {
        for(unsigned int index = 0; index < ax.size(); ++index)
        {
            unsigned int axis = ax[index].asUInt();
            axes.push_back(axis);
        }
    }
    vector< vector<double> > binss;
    const Json::Value binnings = reweighting["rebinning"];
    if(!binnings.isNull())
    {
        for(unsigned int index = 0; index < binnings.size(); ++index)
        {
            vector< double > bins;
            const Json::Value binning = binnings[index];
            for(unsigned int b = 0; b < binning.size(); ++b)
            {
                double boundary = binning[b].asDouble();
                bins.push_back(boundary);
            }
            binss.push_back(bins);
        }
    }
    postproc.addParameter("axes", axes);
    postproc.addParameter("rebinning", binss);
}
void TemplateParameters::readMirrorParameters(const Json::Value& mirror, PostProcessing& postproc)
/*****************************************************************/
{
    bool antiMirror = mirror.get("antisymmetric", false).asBool();
    unsigned int axis = mirror.get("axis", 1).asUInt();
    postproc.addParameter("antisymmetric", antiMirror);
    postproc.addParameter("axis", axis);
}
Exemplo n.º 5
0
PostProcessing* PostProcessing::create(Texture2D *texture)
{
	PostProcessing *layer = new PostProcessing();
	if (layer && layer->initWithTexture(texture))
	{
		layer->autorelease();
		layer->initProgram();
		CCNotificationCenter::sharedNotificationCenter()->addObserver(layer, callfuncO_selector(PostProcessing::listenBackToForeground), EVNET_COME_TO_FOREGROUND, NULL);
		return layer;
	}
	CC_SAFE_DELETE(layer);
	return NULL;
}
Exemplo n.º 6
0
    void glInit()
    {
        viewFramebuf.resize(framebufferSize());
        if (!viewFramebuf.areTexturesReady())
        {
            App::config("window.main.fsaa").audienceForChange() += this;
            updateSampleCount();

            viewFramebuf.glInit();
        }

        postProcessing.glInit();


        /*if (!frameDrawable.isReady())
        {
            ClientApp::shaders().build(frameDrawable.program(), "generic.texture")
                    << uMvpMatrix
                    << uFrameTex;

            using VBuf = GuiWidget::DefaultVertexBuf;

            auto *vbuf = new VBuf;
            frameDrawable.addBuffer(vbuf);

            VBuf::Builder verts;
            verts.makeQuad(Rectanglef(0, 0, 1, 1), Rectanglef(0, 1, 1, -1));
            vbuf->setVertices(gl::TriangleStrip, verts, gl::Static);
        }*/
    }
//Cleans up the screen by destroying all objects rendered on the screen
//clears all gameobjects in displayList, and destroys the postprocessing
void  SplashScreen::cleanUp(){

	if (skyBoxObject)
	{
		skyBoxObject->destroy();
		delete skyBoxObject;
		skyBoxObject = NULL;
	}

	auto iter = displayList.begin();
	while (iter != displayList.end())
	{
		(*iter)->destroy();
		if ((*iter))
		{
			delete (*iter);
			(*iter) = NULL;
			iter = displayList.erase(iter);
		}
		else
		{
			iter++;
		}
	}

	displayList.clear();
	postProcessor.destroy();
}
void TemplateParameters::readSmoothingParameters(const Json::Value& smooth, PostProcessing& postproc)
/*****************************************************************/
{
    unsigned int entriesPerBin = smooth.get("entriesperbin", 200).asUInt();
    double rescaleWidth = smooth.get("rescalewidth", 1.).asDouble();
    string kernel = smooth.get("kernel", "adaptive").asString();
    if(kernel!="adaptive" && kernel!="k5b")
    {
        stringstream error;
        error << "TemplateParameters::readSmoothingParameters(): Unknown smoothing kernel '"<<kernel<<"'";
        throw runtime_error(error.str());
    }
    postproc.addParameter("kernel", kernel);
    postproc.addParameter("entriesperbin", entriesPerBin);
    postproc.addParameter("rescalewidth", rescaleWidth);
}
Exemplo n.º 9
0
void DirectxEngine::RenderPreEffects(const PostProcessing& post)
{
    SetRenderState(false, false);
    EnableAlphaBlending(false, false);

    m_data->preEffectsTarget.SetActive(m_data->context);

    SetSelectedShader(PRE_SHADER);
    auto& preShader = m_data->shaders[PRE_SHADER];
    
    preShader->UpdateConstantFloat("bloomStart", &post.BloomStart(), 1);
    preShader->UpdateConstantFloat("bloomFade", &post.BloomFade(), 1);
    preShader->SendConstants(m_data->context);

    preShader->SendTexture(m_data->context, 0, m_data->sceneTarget, SCENE_ID);
    
    m_data->quad.Render(m_data->context);

    preShader->ClearTexture(m_data->context, 0);
}
Exemplo n.º 10
0
void CleanUp()
{

	auto iter = displayList.begin();
	while (iter != displayList.end())
	{
		(*iter)->destroy();
		if ((*iter))
		{
			delete (*iter);
			(*iter) = NULL;
			iter = displayList.erase(iter);
		}
		else
		{
			iter++;
		}
	}
	displayList.clear();


	postProcessor.destroy();	//Clean up, reverse order
	/*
	if (physics){
		physics->destroy();
		delete physics;
		physics = NULL;
	}
	*/
	/*
	// clean up, reverse order!!!
	CleanUp2DScene();	//This gets rid of 2D elements
	CleanUp3DScene();	//This gets rid of 3D elements
	*/
	SDL_GL_DeleteContext(glcontext);	
	SDL_DestroyWindow(window);
	IMG_Quit();
	TTF_Quit();
	SDL_Quit();
}
Exemplo n.º 11
0
void DirectxEngine::RenderPostProcessing(const PostProcessing& post)
{
    m_data->useDiffuseTextures = post.UseDiffuseTextures();

    SetRenderState(false, false);
    EnableAlphaBlending(false, false);

    SetSelectedShader(POST_SHADER);
    auto& postShader = m_data->shaders[POST_SHADER];

    m_data->backBuffer.SetActive(m_data->context);

    postShader->SendTexture(m_data->context, 0, m_data->preEffectsTarget, SCENE_ID);
    postShader->SendTexture(m_data->context, 1, m_data->blurTarget, BLUR_ID);
    postShader->SendTexture(m_data->context, 2, m_data->sceneTarget, DEPTH_ID);

    postShader->UpdateConstantFloat("bloomIntensity", &post.BloomIntensity(), 1);
    postShader->UpdateConstantFloat("fadeAmount", &m_data->fadeAmount, 1);
    postShader->UpdateConstantFloat("contrast", &post.Contrast(), 1);
    postShader->UpdateConstantFloat("saturation", &post.Saturation(), 1);
    postShader->UpdateConstantFloat("dofStart", &post.DOFStart(), 1);
    postShader->UpdateConstantFloat("dofFade", &post.DOFFade(), 1);
    postShader->UpdateConstantFloat("fogStart", &post.FogStart(), 1);
    postShader->UpdateConstantFloat("fogFade", &post.FogFade(), 1);
    postShader->UpdateConstantFloat("fogColor", &post.FogColour().r, 3);
    postShader->UpdateConstantFloat("minimumColor", &post.MinColour().r, 3);
    postShader->UpdateConstantFloat("maximumColor", &post.MaxColour().r, 3);

    postShader->UpdateConstantFloat("finalMask", &post.Mask(PostProcessing::FINAL_MAP), 1);
    postShader->UpdateConstantFloat("sceneMask", &post.Mask(PostProcessing::SCENE_MAP), 1);
    postShader->UpdateConstantFloat("depthMask", &post.Mask(PostProcessing::DEPTH_MAP), 1);
    postShader->UpdateConstantFloat("blurSceneMask", &post.Mask(PostProcessing::BLUR_MAP), 1);
    postShader->UpdateConstantFloat("depthOfFieldMask", &post.Mask(PostProcessing::DOF_MAP), 1);
    postShader->UpdateConstantFloat("fogMask", &post.Mask(PostProcessing::FOG_MAP), 1);
    postShader->UpdateConstantFloat("bloomMask", &post.Mask(PostProcessing::BLOOM_MAP), 1);

    postShader->SendConstants(m_data->context);
    m_data->quad.Render(m_data->context);

    postShader->ClearTexture(m_data->context, 0);
    postShader->ClearTexture(m_data->context, 1);
    postShader->ClearTexture(m_data->context, 2);
}
Exemplo n.º 12
0
 void glDeinit()
 {
     viewFramebuf.glDeinit();
     postProcessing.glDeinit();
 }
Exemplo n.º 13
0
//Function to draw/render
void render()
{
	/*
	//Set the clear color(background)
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	//Clear the color and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	//Make the new VBO active. Repeat here as a sanity check( may have changed since initialisation)
	glBindBuffer(GL_ARRAY_BUFFER, triangleVBO);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, triangleEBO);

	glUseProgram(shaderProgram);	//This line and the three below might have to go below the EBO linkBuffer
	//Gets the location of the MVP, Creates a combined Model View Projection Matrix and then sends it to the shader
	GLint MVPLocation = glGetUniformLocation(shaderProgram, "MVP");
	mat4 MVP = projMatrix * viewMatrix * worldMatrix;
	glUniformMatrix4fv(MVPLocation, 1, GL_FALSE, glm::value_ptr(MVP));

	//Tells the Shader that 0 is the position element
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void**)(sizeof(vec3)+sizeof(vec2)));
	glEnableVertexAttribArray(2);
	glVertexArrayAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void**)(sizeof(vec3)+sizeof(vec2)));
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void**)sizeof(vec3));
	
	GLint texture0Location = glGetUniformLocation(shaderProgram, "texture0");	//This gets the texture location and sends the location of the texture to the shader
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, texture);

	//Changed in Lab 2 - 3D to allow to draw both EBOs and VBOs
	glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);

	//required to swap the back and front buffer
	SDL_GL_SwapWindow(window);
	*/		//Not needed anymore
	postProcessor.bind();

	//old imediate mode!
	//Set the clear colour(background)
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glClearDepth(1.0f);
	//clear the colour and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


	//Alterantive Syntax
	for (auto iter = displayList.begin(); iter != displayList.end(); iter++)
	{
		renderGameObject((*iter));
	}

	/*
	render2D();		//Calls the render 2D function
	render3D();		//Calls the render 3D function
	*/
	//Switching to the normal framebuffer
	postprocessor.preDraw();
	//Grab stuff from the shader
	GLint colourFilterLocation = postProcessor.getUniformVariableLocation("colourFilter");
	glUniformMatrix3fv(colourFilterLocation, 1, GL_FALSE, glm::value_ptr(SEPIA_FILTER));

	//Draw
	postProcessor.Draw();

	//Post Draw
	postProcessor.postDraw();

	SDL_GL_SwapWindow(window);

}
Exemplo n.º 14
0
void TemplateParameters::readRescalingParameters(const Json::Value& rescaling, PostProcessing& postproc)
/*****************************************************************/
{
    double factor = rescaling.get("factor", 1.).asDouble();
    postproc.addParameter("factor", factor);
}
Exemplo n.º 15
0
//This is where all the content is loaded into the game.
//Used for setting up GameObjects, setting their translations/positions
//Used to load up multiple models by calling another class.
//Also used to intialize the postprocessing.
//Adds all GameObjects into a vector array.
void SplashScreen::LoadContent(){

	std::string vsPath = ASSET_PATH + SHADER_PATH + "/passThroughVS.glsl";
	std::string fsPath = ASSET_PATH + SHADER_PATH + "/colourFilterPostFS.glsl";  //change this to boxFilterBlurFS for blur

	postProcessor.init(1024, 768, vsPath, fsPath);

	createSkyBox();

	type = new primitiveType();

	mainCamera = new GameObject();
	mainCamera->setName("MainCamera");

	Transform *t = new Transform();
	t->setPosition(0.0f, 0.0f, 2.0f);
	mainCamera->setTransform(t);

	Camera * c = new Camera();
	c->setAspectRatio((float)(1024 / 768));
	c->setFOV(45.0f);
	c->setNearClip(0.1f);
	c->setFarClip(1000.0f);

	mainCamera->setCamera(c);
	displayList.push_back(mainCamera);

	mainLight = new GameObject();
	mainLight->setName("MainLight");

	t = new Transform();
	t->setPosition(46.0f, 32.0f, -47.0f);
	mainLight->setTransform(t);

	Light * light = new Light();
	mainLight->setLight(light);
	displayList.push_back(mainLight);

	//Model loading
	type->setModelsBump("plane.fbx", "pavement_color.png", "pavement_spec.png", "pavement_normal.png");
	type->setTransformation(vec3(-10, -1, 0), vec3(-90, 0, 0), vec3(1, 1, 1));
	type->loadModels(bump);
	//don't touch above model CONOR!


	primitiveType* pointType = new primitiveType();

	//include file for models
	//pointType->setModelsBump("sword4.fbx", "sword2_C.png", "sword_S.png", "sword_N.png");
	//pointType->setModelsBump("2h_axe.fbx", "2h_axe.png", "2h_axeS.png", "2h_axeN.png");
	//pointType->setModelsBump("knife2.fbx", "kn5_COL.png", "kn5_SPEC.png", "kn5_NRM.png");

	pointType->setModelsBump("shield_deco3.fbx", "shield_C.png", "shield_D.png", "shield_N.png");//shield 1//
	pointType->setModelsBump("constuct_bridge.fbx", "s_12.png", "s_12S.png", "s_12N.png");//bridge//
	pointType->setModelsBump("constuct_shild_A.fbx", "p_1.png", "p_1S.png", "s_12N.png");//sign//

	pointType->setModelsBump("constuct_understand_wood.fbx", "u_8.png", "u_8S.png", "u_8N.png");
	//the positioned models
	pointType->setModelsBump("2h_axe.fbx", "2h_axe.png", "2h_axeS.png", "2h_axeN.png");		//axe//
	pointType->setModelsBump("fachwerkhaus2_2_LOD.fbx", "LOD_f_22.png", "LOD_f_22.png", "LOD_f_22.png"); //single house 1//
	pointType->setModelsBump("fachwerkhaus2_LOD.fbx", "LOD_f_2.png", "LOD_f_2.png", "LOD_f_2.png");//double house 1//

	pointType->setModelsBump("constuct_soldier.fbx", "marble.png", "marble.png", "marble.png");//green marble statue//
	pointType->setModelsBump("fachwerkhaus2_2_LOD.fbx", "LOD_f_22.png", "LOD_f_22.png", "LOD_f_22.png");//single house 2//
	pointType->setModelsBump("fachwerkhaus2_2_LOD.fbx", "LOD_f_22.png", "LOD_f_22.png", "LOD_f_22.png");//single house 3//

	pointType->setModelsBump("fachwerkhaus2_2_LOD.fbx", "LOD_f_22.png", "LOD_f_22.png", "LOD_f_22.png");//single house 4//
	pointType->setModelsBump("fachwerkhaus2_2_LOD.fbx", "LOD_f_23.png", "LOD_f_23.png", "LOD_f_23.png");//single house 5//
	pointType->setModelsBump("fachwerkhaus2_LOD.fbx", "LOD_f_2.png", "LOD_f_2.png", "LOD_f_2.png");//double house 2//

	pointType->setModelsBump("shield_deco3.fbx", "shield3.png", "shield3.png", "shield3.png");//position for shield 2//
	pointType->setModelsBump("fachwerkhaus2_3_LOD.fbx", "LOD_f_23.png", "LOD_f_23.png", "LOD_f_23.png");//single house type 2 number 1//
	pointType->setModelsBump("armorstand.fbx", "2h_axe.png", "2h_axeS.png", "2h_axeN.png");//Armorstand 1//

	pointType->setModelsBump("sword2.fbx", "sword2_C.png", "sword2_C.png", "sword2_C.png");//sword2  number 1//
	pointType->setModelsBump("sword4.fbx", "sword4_c.png", "sword4_c.png", "sword4_c.png");//sword4  number 1//
	pointType->setModelsBump("sword.fbx", "sword_C.png", "sword_C.png", "sword_C.png");//sword  number 1//

	pointType->setModelsBump("holzbank.fbx", "whitemarble.png", "whitemarble.png", "whitemarble.png");//bench  number 1//


	////co-ordinates for the models i.e. little village//

	//


	////set transformations for models

	//pointType->setTransformation(vec3(-1, 1, -10), vec3(-89.4, 0, 0), vec3(.01, .01, .01));
	//pointType->setTransformation(vec3(-10, 1, -10), vec3(-89.4, 0, 0), vec3(0.01, .01, .01));
	//pointType->setTransformation(vec3(-1, 1, -10), vec3(-89.4, 0, 0), vec3(0.01, 0.01, 0.01));

	pointType->setTransformation(vec3(-8, 1, -6), vec3(-89.4, 0, 0), vec3(.002, .002, .002));//shield 1//
	pointType->setTransformation(vec3(-3.75, -1, -10), vec3(-89.52, 0, 0), vec3(.009, .009, .009));  //bridge//
	pointType->setTransformation(vec3(-15, 1, -6.5), vec3(-89.52, 0, 0), vec3(.008, .008, .008));//sign//

	pointType->setTransformation(vec3(-13, -1, -5.5), vec3(-89.52, 0, 0), vec3(.008, .008, .008));//wood canopy//
	//the positioned co-ordinates
	pointType->setTransformation(vec3(-10.25, -0.75, -6), vec3(-89.5, 0, 0), vec3(0.002, 0.002, 0.002)); //position for the ax//
	pointType->setTransformation(vec3(-1.5, -1, -10), vec3(-89.5, 0, 0), vec3(0.01, 0.01, 0.01));//position for house 1//
	pointType->setTransformation(vec3(-15, -1, -10), vec3(-89.5, 0, 0), vec3(0.01, 0.01, 0.01));//postion for double house 1//

	pointType->setTransformation(vec3(-10.5, 2, -10), vec3(-89.52, 0, 0), vec3(0.01, 0.01, 0.01));//position for green marble statue//
	pointType->setTransformation(vec3(-17.75, -1, -10), vec3(-89.5, 0, 0), vec3(0.01, 0.01, 0.01));//position for house 2//
	pointType->setTransformation(vec3(-12.25, -1, -10), vec3(-89.5, 0, 0), vec3(0.01, 0.01, 0.01));//position for house 3//

	pointType->setTransformation(vec3(-6, -1, -10), vec3(-89.5, 0, 0), vec3(0.01, 0.01, 0.01));//posiotion for house 4//
	pointType->setTransformation(vec3(-19.5, -1, -10), vec3(-89.5, 0, 0), vec3(0.01, 0.01, 0.01));//posiotion for house 5//
	pointType->setTransformation(vec3(-22.5, -1, -7), vec3(-89.52, 0, 89.5), vec3(0.01, 0.01, 0.01));//postion for double house 2//

	pointType->setTransformation(vec3(-16, -0.8, -9), vec3(-89.52, 0, 0), vec3(0.009, 0.009, 0.009));//position for Shield 2//
	pointType->setTransformation(vec3(-15, -1, -5.5), vec3(-89.52, 0, 89.5), vec3(0.01, 0.01, 0.01));//position for single house type 2 number 1//
	pointType->setTransformation(vec3(-10, -1, -6), vec3(-89.52, 0, 0), vec3(0.004, 0.004, 0.004));//position for Armorstand number 1//

	pointType->setTransformation(vec3(-9.8, -0.75, -6), vec3(-89.52, 0, 0), vec3(0.0005, 0.0005, 0.0005));//position for sword2 number 1//
	pointType->setTransformation(vec3(-9.85, -0.75, -6), vec3(-89.52, 0, 0), vec3(0.002, 0.002, 0.002));//position for sword4 number 1//
	pointType->setTransformation(vec3(-9.7, -0.75, -6), vec3(-89.52, 0, 89.5), vec3(0.001, 0.001, 0.001));//position for sword number 1//

	pointType->setTransformation(vec3(-11.5, -1.25, -8.5), vec3(-89.52, 0, 0), vec3(0.009, 0.009, 0.009));//position for bench number 1//

	pointType->loadModels(point);

	//primitiveType* parralaxType = new primitiveType();
	////parralaxType->setModelsParrallax("armoredrecon.fbx", "armoredrecon_diff.png", "armoredrecon_spec.png", "armoredrecon_N.png", "armoredrecon_Height.png");
	////parralaxType->setTransformation(vec3(0, 0, 2), vec3(0, 0, 0), vec3(1, 1, 1));
	//parralaxType->loadModels(parralax);

	primitiveType* primimtiveShapes = new primitiveType();
	//primimtiveShapes->setModelsBump("plane.fbx", "pavement_color.png", "pavement_spec.png", "pavement_normal.png");
	primimtiveShapes->setModelsBump("plane.fbx", "pavement_color.png", "pavement_spec.png", "pavement_normal.png");
	//primimtiveShapes->setTransformation(vec3(-10, -2, 10), vec3(0, 0, 0), vec3(1, 1, 1));
	primimtiveShapes->setTransformation(vec3(-10, -1.5, 0), vec3(-89.5, 0, 0), vec3(1, .8, 1));
	primimtiveShapes->loadModels(point);

	////Add to the displaylist in order for models etc to be loaded/rendered
	displayList.insert(displayList.end(), pointType->displayList.begin(), pointType->displayList.end());
	displayList.insert(displayList.end(), primimtiveShapes->displayList.begin(), primimtiveShapes->displayList.end());
	displayList.insert(displayList.end(), type->displayList.begin(), type->displayList.end());
	//displayList.insert(displayList.end(), parralaxType->displayList.begin(), parralaxType->displayList.end());
}
Exemplo n.º 16
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();


	mainLayer = Layer::create();
	mainLayerParent = Layer::create();
	postProcessingLayer = Layer::create();
	uiLayer = Layer::create();

	this->addChild(mainLayerParent);
	mainLayerParent->addChild(mainLayer);
	this->addChild(postProcessingLayer);
	this->addChild(uiLayer);

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    auto closeItem = MenuItemImage::create(
                                           "CloseNormal.png",
                                           "CloseSelected.png",
                                           CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
    
	closeItem->setPosition(Point(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
                                origin.y + closeItem->getContentSize().height/2));

	auto switchItem = MenuItemImage::create(
											"switchuser.png",
											"switchuser.png",
											CC_CALLBACK_1(HelloWorld::switchCallback, this));

	switchItem->setPosition(Point(origin.x + visibleSize.width - closeItem->getContentSize().width - switchItem->getContentSize().width/2,
		origin.y + closeItem->getContentSize().height / 2));

    // create menu, it's an autorelease object
	auto menu = Menu::create(closeItem, switchItem, NULL);
    menu->setPosition(Point::ZERO);
	uiLayer->addChild(menu, 1);

    
	// shader 顯示

	SpriteMask* pSprite2 = SpriteMask::create("wall_77.png");
	pSprite2->setPosition(ccp(visibleSize.width / 2 - 90, visibleSize.height / 2));
	mainLayer->addChild(pSprite2, 0);

	SpriteMask* pSprite3 = SpriteMask::create("wall_77.png");
	pSprite3->setMask("wall0.png");
	pSprite3->setPosition(ccp(visibleSize.width / 2 -30, visibleSize.height / 2));
	mainLayer->addChild(pSprite3, 0);

	GrayMask* pSprite4 = GrayMask::create("wall_77.png");
	pSprite4->setPosition(ccp(visibleSize.width / 2 + 30, visibleSize.height / 2));
	mainLayer->addChild(pSprite4, 0);

	EdgeMask* pSprite5 = EdgeMask::create("wall_77.png");
	pSprite5->setPosition(ccp(visibleSize.width / 2 + 90, visibleSize.height / 2));
	mainLayer->addChild(pSprite5, 0);

	LightLayer *layer2 = LightLayer::create();
	layer2->setTag(LAYER_SPOT);
	mainLayer->addChild(layer2, 0);

	DynamicBackground *layer3 = DynamicBackground::create();
	layer3->setBackgroundPic();
	mainLayer->addChild(layer3, -1);

	renderTexture = RenderTexture::create(visibleSize.width, visibleSize.height);
	renderTexture->retain();

	mainLayerParent->setVisible(false);
	isPostProcessing = true;
	
	PostProcessing *test = PostProcessing::create(renderTexture->getSprite()->getTexture());
	test->setFlippedY(true);
	//test->setScale(0.4f);
	postProcessingLayer->addChild(test);
	test->setPosition(Point(test->boundingBox().size.width/2, 
							visibleSize.height - test->boundingBox().size.height / 2));
	
	// Register Touch Event
	auto listener = EventListenerTouchOneByOne::create();
	listener->setSwallowTouches(true);

	listener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this);
	listener->onTouchMoved = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
	listener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);

	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

	this->scheduleUpdate();
	return true;
}
Exemplo n.º 17
0
void Initialise()
{
	std::string vsPath = ASSET_PATH + SHADER_PATH + "/passThroughVS.glsl";
	std::string fsPath = ASSET_PATH + SHADER_PATH + "/boxFilterBlurFS.glsl";

	postProcessor.init(WINDOW_WIDTH, WINDOW_HEIGHT, vsPath, fsPath);

	mainCamera = new GameObject();
	mainCamera->setName("MainCamera");

	Transform *t = new Transform();
	t->setPosition(0.0f, 0.0f, 2.0f);
	mainCamera->setTransform(t);

	Camera * c = new Camera();
	c->setAspectRatio((float)(WINDOW_WIDTH / WINDOW_HEIGHT));
	c->setFOV(45.0f);
	c->setNearClip(0.1f);
	c->setFarClip(1000.0f);

	mainCamera->setCamera(c);
	displayList.push_back(mainCamera);

	mainLight = new GameObject();
	mainLight->setName("MainLight");

	t = new Transform();
	t->setPosition(0.0f, 0.0f, 0.0f);
	mainLight->setTransform(t);

	Light * light = new Light();
	mainLight->setLight(light);
	displayList.push_back(mainLight);

	//alternative sytanx
	for (auto iter = displayList.begin(); iter != displayList.end(); iter++)
	{
		(*iter)->init();
	}


	std::string modelPath = ASSET_PATH + MODEL_PATH + "armoredrecon.fbx";
	GameObject * go = loadFBXFromFile(modelPath);
	for (int i = 0; i < go->getChildCount(); i++)
	{
		Material * material = new Material();
		material->init();
		std::string vsPath = ASSET_PATH + SHADER_PATH + "/BumpmappingVS.glsl";
		std::string fsPath = ASSET_PATH + SHADER_PATH + "/BumpmappingFS.glsl";
		material->loadShader(vsPath, fsPath);

		std::string diffTexturePath = ASSET_PATH + TEXTURE_PATH + "/armoredrecon_diff.png";
		material->loadDiffuseMap(diffTexturePath);

		std::string specTexturePath = ASSET_PATH + TEXTURE_PATH + "/armoredrecon_spec.png";
		material->loadSpecularMap(specTexturePath);

		std::string bumpTexturePath = ASSET_PATH + TEXTURE_PATH + "/armoredrecon_N.png";
		material->loadBumpMap(bumpTexturePath);

		go->getChild(i)->setMaterial(material);
	}
	go->getTransform()->setPosition(2.0f, -2.0f, -6.0f);
	go->getTransform()->setRotation(0.0f, -40.0f, 0.0f);
	displayList.push_back(go);

	go = loadFBXFromFile(modelPath);
	for (int i = 0; i < go->getChildCount(); i++)
	{
		Material * material = new Material();
		material->init();
		std::string vsPath = ASSET_PATH + SHADER_PATH + "/ParallaxMappingVS.glsl";
		std::string fsPath = ASSET_PATH + SHADER_PATH + "/ParallaxMappingFS.glsl";
		material->loadShader(vsPath, fsPath);

		std::string diffTexturePath = ASSET_PATH + TEXTURE_PATH + "/armoredrecon_diff.png";
		material->loadDiffuseMap(diffTexturePath);

		std::string specTexturePath = ASSET_PATH + TEXTURE_PATH + "/armoredrecon_spec.png";
		material->loadSpecularMap(specTexturePath);

		std::string bumpTexturePath = ASSET_PATH + TEXTURE_PATH + "/armoredrecon_N.png";
		material->loadBumpMap(bumpTexturePath);

		std::string heightTexturePath = ASSET_PATH + TEXTURE_PATH + "/armoredrecon_Height.png";
		material->loadHeightMap(heightTexturePath);

		go->getChild(i)->setMaterial(material);
	}
	go->getTransform()->setPosition(-2.0f, -2.0f, -6.0f);
	go->getTransform()->setRotation(0.0f, -40.0f, 0.0f);
	displayList.push_back(go);

}