Exemplo n.º 1
0
void setTorchLight(float x, float y, float z, float radius) {
	//PLight
	PointLight p;
	p.SetColor(fireLightColor[0], fireLightColor[1], fireLightColor[2]);
	p.SetPosition(x, y, z);
	p.SetAttenuation(0.01, 0.1, 0.1);
	//p.SetAttenuation(1.0, 0.05, 0.0);
	p.SetRadius(radius);
	p.SetGrain(10);

	plights.push_back(p);  
}
Exemplo n.º 2
0
World::World(sf::RenderWindow& inWindow)
: window(inWindow), gbuffer(WINDOW_WIDTH, WINDOW_HEIGHT), hdrDownsampleTexture(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, true), hdrBlurTexture(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, true), hdrDownsample2Texture(WINDOW_WIDTH / 4, WINDOW_HEIGHT / 4, true), hdrBlur2Texture(WINDOW_WIDTH / 4, WINDOW_HEIGHT / 4, true), fullscreenQuad(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT), aaTexture(WINDOW_WIDTH, WINDOW_HEIGHT)
{
    // OpenGL State
    glBlendEquation(GL_FUNC_ADD);
    glBlendFunc(GL_ONE, GL_ONE);
    glStencilOpSeparate(GL_BACK, GL_KEEP, GL_INCR_WRAP, GL_KEEP);
    glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_DECR_WRAP, GL_KEEP);

    // Seed the PRNG.
    srand(static_cast<unsigned int>(time(0)));

    // Load light meshes.
    pointLightMesh.LoadFromFile("Models/pointlightMesh.obj");
    spotLightMesh.LoadFromFile("Models/spotlightMesh.obj");
    directionalLightMesh.LoadFromFile("Models/directionalMesh.obj");

    // Lighting Shaders.
    pointLightShader.LoadFromFile("Shaders/lightShader.vert", "Shaders/pointlightShader.frag");
    spotLightShader.LoadFromFile("Shaders/lightShader.vert", "Shaders/spotlightShader.frag");
    directionalLightShader.LoadFromFile("Shaders/lightShader.vert", "Shaders/directionalShader.frag");

    // HDR Shaders.
    hdrDownsample.LoadFromFile("Shaders/fsquad.vert", "Shaders/hdrDownsample.frag");
    hdrTonemap.LoadFromFile("Shaders/fsquad.vert", "Shaders/hdrTonemap.frag");
    hdrBlur.LoadFromFile("Shaders/fsquad.vert", "Shaders/hdrBlur.frag");
    hdrBrightness.LoadFromFile("Shaders/fsquad.vert", "Shaders/hdrBrightness.frag");

    // Load Models.
    mdl2.LoadFromFile("Models/sphere.obj");
    mdl.LoadFromFile("Models/floor.obj");
    mdl3.LoadFromFile("Models/sphere.obj");
    quadMesh.LoadFromFile("Models/quad.obj");

    // Load Shaders
    basicShader.LoadFromFile("Shaders/basic.vert", "Shaders/basic.frag");
    pass1Shader.LoadFromFile("Shaders/drpass1.vert", "Shaders/drpass1.frag");
    pass2Shader.LoadFromFile("Shaders/drpass2.vert", "Shaders/drpass2.frag");
    pass2ShaderDirectional.LoadFromFile("Shaders/empty.vert", "Shaders/drpass2directional.frag");
    quadShader.LoadFromFile("Shaders/fsquad.vert", "Shaders/hdrTonemap.frag");
    terrainShader.LoadFromFile("Shaders/terrainshader.vert", "Shaders/terrainshader.frag");
    flatShader.LoadFromFile("Shaders/basic.vert", "Shaders/flatshade.frag");
    emptyShader.LoadFromFile("Shaders/empty.vert", "Shaders/empty.frag");
    sphereShader.LoadFromFile("Shaders/sphere.vert", "Shaders/sphere.frag");

    // Anti-Aliasing Shaders
#if USE_FXAA == 1
    fxaaShader.LoadFromFile("Shaders/fxaa.vert", "Shaders/fxaa.frag");
#endif
    baseAAShader.LoadFromFile("Shaders/baseaa.vert", "Shaders/baseaa.frag");

    // Load textures.
    mdlTex.loadFromFile("Textures/test.png");
    terrainTexture.loadFromFile("Textures/terraintex.png");
    terrainWater.loadFromFile("Textures/terrainwater.png");

    // Main world directional light.
    DirectionalLight worldLight;
    worldLight.SetDirection(Vector3(-1.0f, 0.0f, 0.0f));
    worldLight.SetColor(Color(0.8f, 0.8f, 0.8f));
    worldLight.SetDiffuseIntensity(0.9f);
    worldLight.SetAmbientIntensity(0.4f);
    directionalLights.push_back(worldLight);

    // Lights
    const unsigned int numLights = 40;
    const float lightRadius = 2.0f;
    PointLight l;
    l.SetPosition(Vector3(10.0f, 2.0f, 10.0f));
    l.SetScale(Vector3(3.0f, 3.0f, 3.0f));
    l.SetColor(Color(0.0f, 0.0f, 1.4f, 1.0f));
    l.SetAttenuationConstant(0.4f);
    l.SetDiffuseIntensity(0.4f);
    l.SetAmbientIntensity(0.2f);
    pointLights.push_back(l);

    const int maxXZ = 15;
    const int minXZ = -15;
    const int maxY = 5;
    const float minRad = 0.3f;
    const float maxRad = 2.0f;
    for (int i = 0; i < numLights; i++)
    {
        PointLight l;
        
        // Generate position.
        int x = (rand() % (maxXZ - minXZ)) + minXZ;
        int y = (rand() % maxY);
        int z = (rand() % (maxXZ - minXZ)) + minXZ;
        l.SetPosition(Vector3(x, y, z));

        // Generate Scale
        float frand = ((float)rand() / (float)RAND_MAX);
        float fdiff = maxRad - minRad;

        //l.SetScale(Vector3(scale, scale, scale));

        // Generate Color
        float r = float_rand(0.0f, maxCol);
        float g = float_rand(0.0f, maxCol);
        float b = float_rand(0.0f, maxCol);
        l.SetColor(Color(r, g, b, 1.0f));

        float ambient = ((float)rand() / (float)RAND_MAX);
        float diff = ((float)rand() / (float)RAND_MAX);

        l.SetAmbientIntensity(ambient);
        l.SetDiffuseIntensity(diff);

        float catt = ((float)rand() / (float)RAND_MAX);
        float latt = ((float)rand() / (float)RAND_MAX);
        float eatt = ((float)rand() / (float)RAND_MAX);

        float mc = fmax(fmax((float)r, (float)g), (float)b);
        float ret = (-latt + sqrtf(latt * latt - 4 * eatt * (eatt - 256 * mc * diff))) / 2 * eatt;

        l.SetScale(Vector3(ret, ret, ret));

        l.SetAttenuationConstant(catt);
        l.SetAttenuationLinear(latt);
        l.SetAttenuationExponential(eatt);

        pointLights.push_back(l);
    }

    // Set the initial position of the sphere
    spherePos = Vector3(10.0f, 3.0f, 10.0f);

    // Setup the help text.
    defaultFont.loadFromFile("arial.ttf");
    helpText.setFont(defaultFont);
    helpText.setString("Controls:\n" \
                       "Mouse: Camera direction.\n" \
                       "WASD: Camera movement.\n" \
                       "I: Randomize light attenuations.\n" \
                       "K: Randomize light color and intensity.\n" \
                       "Insert: Disable mouse.\n" \
                       "Delete: Switch shown render target.\n" \
                       "Home: Disable/Enable terrain movement.\n"
                       );
    helpText.setCharacterSize(14);
    helpText.setColor(sf::Color(255, 0, 255, 255));

    targetText.setFont(defaultFont);
    targetText.setCharacterSize(14);
    targetText.setPosition(sf::Vector2f(0.0, window.getSize().y - 25));
    targetText.setString("Current Buffer: Final Output");
    targetText.setColor(sf::Color(255, 0, 255, 255));

    // Sounds
    sndExplodeBuffer.loadFromFile("explode.wav");
    sndExplode.setBuffer(sndExplodeBuffer);
    sndExplode.setAttenuation(10.0f);
    sndExplode.setMinDistance(60.0f);
    sndExplode.setPosition(sf::Vector3f(0.0f, 1.0f, 0.0f));
}