Beispiel #1
0
void Scene::pointLightPass(RenderTarget *target)
{
    if(!this->pointLights.empty ())
    {
        for(int i =0;i<pointLights.size ();i++)
        {
            ShaderProgram * shader = ShaderPool::getInstance ()->get("point_light_pass");
            shader->use ();
            PointLight * light = this->pointLights[i];
            light->apply (shader,0);

            m_quad->setShaderProgram (shader);
            QMatrix4x4 m;
            m.setToIdentity ();
            auto camera = target->camera ();
            shader->setUniformMat4v ("g_MVP_matrix",m.data ());
            shader->setUniform2Float ("g_screen_size",1024,768);
            shader->setUniformInteger ("g_color_map",0);
            shader->setUniformInteger ("g_position_map",1);
            shader->setUniformInteger ("g_normal_map",2);
            shader->setUniform3Float ("g_eye_position",
                                      camera->pos ().x(),
                                      camera->pos ().y(),
                                      camera->pos ().z());
            m_quad->draw (true);
        }
    }
}
Beispiel #2
0
Vector3
Lambert::shade(const Ray& ray, const HitInfo& hit, const Scene& scene) const
{
	Vector3 L = Vector3(0.0f, 0.0f, 0.0f);

	const Vector3 viewDir = -ray.d; // d is a unit vector

	const Lights *lightlist = scene.lights();

	// loop over all of the lights
	Lights::const_iterator lightIter;
	for (lightIter = lightlist->begin(); lightIter != lightlist->end(); lightIter++)
	{
		PointLight* pLight = *lightIter;

		Vector3 l = pLight->position() - hit.P;

		// the inverse-squared falloff
		float falloff = l.length2();

		// normalize the light direction
		l /= sqrt(falloff);

		// get the irradiance
		Vector3 irradiance = (pLight->color() * pLight->wattage()) * std::max(0.0f, dot(hit.N, l)) / (4.0 * PI * falloff);

		L += irradiance * (m_kd / PI);
	}

	return L;
}
void
makeSponzaScene()
{
	g_camera = new Camera;
	g_scene = new Scene;
	g_image = new Image;

	g_image->resize(512, 512);

	// set up the camera
	g_camera->setBGColor(Vector3(0.0f, 0.0f, 0.2f));
	g_camera->setEye(Vector3(8, 1.5, 1));
	g_camera->setLookAt(Vector3(0, 2.5, -1));
	g_camera->setUp(Vector3(0, 1, 0));
	g_camera->setFOV(55);

	// create and place a point light source
	PointLight * light = new PointLight;
	light->setPosition(Vector3(0, 10.0, 0));
	light->setColor(Vector3(1, 1, 1));
	light->setWattage(4.0 * PI * 200);
	g_scene->addLight(light);

	Material* material = new Lambert(Vector3(1.0f));
	TriangleMesh * mesh = new TriangleMesh;
	mesh->load("sponza.obj");
	addMeshTrianglesToScene(mesh, material);
    
	// let objects do pre-calculations if needed
	g_scene->preCalc();
}
Beispiel #4
0
void setup()
{
	size(1024, 768);
	background(0);
	setFrameRate(60);

	// Setup lighting
	ambientLight(30);
	light.init(200, 200, 200, 0, 3, 0);

	// Uncomment this line to see the position of the light
	light.drawDebug(true);

	// Init 3d object's properties
	box.init(50, 25, 75);
	box.setPosition(width/2.0f, height/2.0f);

	sphere1.init(30);
	sphere2.init(60);
	sphere3.init(100);

	// Now, we make the spheres children of the box's (scene node)
	box.addChild( sphere1 );
	box.addChild( sphere2 );
	box.addChild( sphere3 );

	// Translate the sphere (relative to its parent, the box)
	// This way, when we rotate the box (parent object), the spheres will orbitate around it
	sphere1.setPosition( 2, 0, 0 );
	sphere2.setPosition( 5, 0, 0 );
	sphere3.setPosition( 7, 0, 0 );

	// Add the second light as child of one of the spheres
	sphere1.addChild( light );
}
Beispiel #5
0
void setup_rc() {
   glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
   shader_light = gltLoadShaderPairWithAttributes("gouraud_shading.vp", "gouraud_shading.fp", 3, GLT_ATTRIBUTE_VERTEX, "vertex_position", GLT_ATTRIBUTE_COLOR, "vertex_color", GLT_ATTRIBUTE_NORMAL, "vertex_normal");
   shader_color = gltLoadShaderPairWithAttributes("pass_thru_shader.vp", "pass_thru_shader.fp", 2, GLT_ATTRIBUTE_VERTEX, "vertex_position", GLT_ATTRIBUTE_COLOR, "vertex_color");
   mvp_matrix_location_shader_color = glGetUniformLocation(shader_color, "mvp_matrix");
   mvp_matrix_location = glGetUniformLocation(shader_light, "mvp_matrix");
   mv_matrix_location = glGetUniformLocation(shader_light, "mv_matrix");
   v_matrix_location = glGetUniformLocation(shader_light, "v_matrix");
   normal_matrix_location = glGetUniformLocation(shader_light, "normal_matrix");
   intensity_ambient_component_location = glGetUniformLocation(shader_light, "intensity_ambient_component");
   light_0_position_location = glGetUniformLocation(shader_light, "light_0.position");
   light_0_intensity_diffuse_location = glGetUniformLocation(shader_light, "light_0.intensity_diffuse");
   light_0_intensity_specular_location = glGetUniformLocation(shader_light, "light_0.intensity_specular");
   light_0_attenuation_location = glGetUniformLocation(shader_light, "light_0.attenuation");
   material_0_ka_location = glGetUniformLocation(shader_light, "material_0.ka");
   material_0_kd_location = glGetUniformLocation(shader_light, "material_0.kd");
   material_0_ks_location = glGetUniformLocation(shader_light, "material_0.ks");
   material_0_alpha_location = glGetUniformLocation(shader_light, "material_0.alpha");
   light_0.set_position(0.0f, 0.0f, 0.0f);
   light_0.set_intensity_diffuse(1.0f, 1.0f, 1.0f);
   light_0.set_intensity_specular(1.0f, 1.0f, 1.0f);
   light_0.set_attenuation(0.0f, 0.1f, 0.0f);
   material_0.set_parameters(1.0f, 1.0f, 1.0f, 200.0f);
   geometry_pipeline.SetMatrixStacks(mv_stack, p_stack);
   glEnable(GL_CULL_FACE);
   glEnable(GL_DEPTH_TEST);
   glFrontFace(GL_CCW);
}
void RenderController::RenderPointLight(PointLightSource *lightSourcePtr) {
	// Implement a solution for the Deferred Renderer Lab
	//RenderPointLightSolution(lightSourcePtr);

	DepthStencilStateManager::GetReference().ApplyState(DepthStencilStateManager::DSS_NoDepth);
	BlendStateManager::GetReference().ApplyState(BlendStateManager::BS_Additive);
	gBufferRT.ActivateSRVs(GBufferStartSlot);
	if ( lightSourcePtr->GetShadows() == EDGameCore::ILight::SOFT ) {
		PointLight *pointLight = lightSourcePtr->GetLightPtr();
		PointLightWithShadow *pointLightWithShadow = (PointLightWithShadow*)pointLight;
		RenderPointDepths(pointLightWithShadow);
		sceneTarget.ActivateTarget();
		sceneTarget.ClearDepthStencilView(D3D11_CLEAR_STENCIL);
		pointLightWithShadow->ActivateShadowTexture();
		pointLightWithShadowsContextHandle.GetContent()->RenderProcess();
		pointLightWithShadow->RevertShadowTexture();
		pointLightWithShadowsContextHandle.GetContent()->ClearRenderSet();

	} else {
		PointLight *pointLight = lightSourcePtr->GetLightPtr();
		pointLight->ApplyLight();
		sceneTarget.ActivateTarget();
		sceneTarget.ClearDepthStencilView(D3D11_CLEAR_STENCIL);
		pointLightContextHandle.GetContent()->RenderProcess();
		pointLightContextHandle.GetContent()->ClearRenderSet();
	}

	gBufferRT.DeactivateSRVs(GBufferStartSlot);
}
Beispiel #7
0
/* LOADERS */
void EditorLoader::AddPointLight()
{
	Vector3 look = m_pRenderContext->GetCamera()->GetLook();
	look.Normalize();

	PointLightDesc pDesc;

	pDesc.position = (m_pRenderContext->GetCamera()->GetPosition() + look * 2);

	BYTE r = 180;
	BYTE g = 180;
	BYTE b = 200;
    BYTE a = 255;

	pDesc.color = Color(r, g, b, a);
	pDesc.multiplier = 2.0f;
	pDesc.attenuationStart = 0;
	pDesc.attenuationEnd = 5;
            
	PointLight* pl = new PointLight(pDesc);
	pl->InitEditor();

	m_pRenderContext->GetLightController()->AddLight(pl);

	cout << "Added pointlight\n";
}
Beispiel #8
0
void
Scene::preCalc()
{
    Objects::iterator it;
    for (it = m_objects.begin(); it != m_objects.end(); it++)
    {
        Object* pObject = *it;
        pObject->preCalc();
    }
    Lights::iterator lit;
    float total_wattage = 0.f;
    for (lit = m_lights.begin(); lit != m_lights.end(); lit++)
    {
        PointLight* pLight = *lit;
        pLight->preCalc();
        total_wattage += pLight->wattage();
    }

    m_bvh.build(&m_objects);

    delete g_global_illum_map;
    g_global_illum_map = new Photon_map(m_global_photons);
    delete g_caustics_map;
    g_caustics_map = new Photon_map(m_caustics_photons);
    g_caustics_map->setCaustics(true);

    printf("Caustics map:\n");
    sampleMap(g_caustics_map, m_caustics_photons, total_wattage);
    printf("Global illum map:\n");
    sampleMap(g_global_illum_map, m_global_photons, total_wattage);
}
Beispiel #9
0
void
Scene::raytraceImage(Camera *cam, Image *img)
{
    Ray ray;
    HitInfo hitInfo;
    Vector3 shadeResult;
    bIntersect = 0;
    tIntersect = 0;
    bool useShadows = false;

    // loop over all pixels in the image
    for (int j = 0; j < img->height(); ++j)
    {
        for (int i = 0; i < img->width(); ++i)
        {
            ray = cam->eyeRay(i, j, img->width(), img->height());
            hitInfo.boxHit = 0;
            hitInfo.triHit = 0;
            if (trace(hitInfo, ray))
            {
                // printf("Traced...\n");
                hitInfo.u = i;
                hitInfo.v = j;
                const Material * mat = hitInfo.material;
                shadeResult = mat->shade(ray, hitInfo, *this);
                if (useShadows) {
                    Lights::const_iterator lightIter;
                    ray.o = hitInfo.P;
                    for (lightIter = m_lights.begin(); lightIter != m_lights.end(); lightIter++)
                    {
                        PointLight* pLight = *lightIter;
                        ray.d = pLight->position() - hitInfo.P;
                        ray.d.normalize();
                        ray.o = ray.o + ray.d * epsilon;
                        if (trace(hitInfo, ray)) {
                            if (hitInfo.t > EPSILON) {
                                shadeResult = Vector3(0);
                                break;
                            }
                        }
                    }
                }
                img->setPixel(i, j, shadeResult);
            }
            // bIntersect += hitInfo.boxHit;
            tIntersect += hitInfo.triHit;
            bIntersect += hitInfo.boxHit;
        }
        img->drawScanline(j);
        glFinish();
        // printf("Rendering Progress: %.3f%%\r", j/float(img->height())*100.0f);
        fflush(stdout);
    }

    printf("Rendering Progress: 100.000%\n");
    debug("done Raytracing!\n");
    printStats();
}
Beispiel #10
0
Light<real>* SceneImporter<real>::ReadPointLight( std::istream& stream, const std::string& name )
{
	PointLight<real>* light = new PointLight<real>;
	light->SetName( name );

	ReadLightHeader( stream, light );

	return light;
}
Beispiel #11
0
void project1() {
	// Create scene
	Scene scn;
	scn.SetSkyColor(Color(0.8f, 0.9f, 1.0f));

	// Create boxes
    LambertMaterial lambert1;
    lambert1.SetDiffuseColor(Color(0.3f,0.3f,0.3f));

	MeshObject box1;
	box1.MakeBox(5.0f,0.1f,5.0f, &lambert1);
	scn.AddObject(box1);
    
    
    LambertMaterial lambert2;
    lambert2.SetDiffuseColor(Color(0.7f,0.7f,0.7f));
	MeshObject box2;
	box2.MakeBox(1.0f,1.0f,1.0f, &lambert2);
    
	InstanceObject inst1(box2);
	Matrix34 mtx;
	mtx.MakeRotateX(0.5f);
	mtx.d.y=1.0f;
	inst1.SetMatrix(mtx);
	scn.AddObject(inst1);
    
	InstanceObject inst2(box2);
	mtx.MakeRotateY(1.0f);
	mtx.d.Set(-1.0f,0.0f,1.0f);
	inst2.SetMatrix(mtx);
	scn.AddObject(inst2);
    
	// Create lights
	DirectLight sunlgt;
	sunlgt.SetBaseColor(Color(1.0f, 1.0f, 0.9f));
	sunlgt.SetIntensity(0.5f);
	sunlgt.SetDirection(Vector3(-0.5f, -1.0f, -0.5f));
	scn.AddLight(sunlgt);
    
	PointLight redlgt;
	redlgt.SetBaseColor(Color(1.0f, 0.2f, 0.2f));
	redlgt.SetIntensity(2.0f);
	redlgt.SetPosition(Vector3(2.0f, 2.0f, 0.0f));
	scn.AddLight(redlgt);
    
	// Create camera
	Camera cam;
	cam.LookAt(Vector3(2.0f,2.0f,5.0f), Vector3(0.0f,0.0f,0.0f));
	cam.SetResolution(800,600);
	cam.SetFOV(40.0f);
	cam.SetAspect(1.33f);
    
	// Render image
	cam.Render(scn);
	cam.SaveBitmap("project1.bmp");
}
Action::ResultE ShadingCallbacks::pointlightRenderLeave(CNodePtr &pNode, 
                                                        Action   *action)
{
    PointLight *pPl = dynamic_cast<PointLight *>(pNode.getCPtr());

    if(pPl->getOn() == false)
        return Action::Continue;

    return lightRenderLeave(pPl, action);
}
Beispiel #13
0
void LegacyRenderer::render(const ICamera<float>& camera, const PointLight<float>& light, const TriangleBuffer& buffer)
{
	const auto& positions = buffer.getPositions().get();// buffers[0].get();
	const auto& normals = buffer.getNormals().get();//buffers[1].get();

	if (positions.empty()) {
		return;
	}

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);

	const auto& projectionMatrix = camera.getProjectionMatrix();
	const auto& modelviewMatrix = camera.getModelviewMatrix();;

	std::vector<float> lightPos = { light.getPos().getX(), light.getPos().getY(), light.getPos().getZ(), 1.0 };
	glLightfv(GL_LIGHT0, GL_POSITION, lightPos.data());
	glLightfv(GL_LIGHT0, GL_DIFFUSE, light.getDiffuse().toArray4().data());
//	glLightfv(GL_LIGHT0, GL_SPECULAR, light.getSpecular().toArray4().data());
	glLightfv(GL_LIGHT0, GL_AMBIENT, white);


	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glLoadMatrixf(projectionMatrix.toArray().data());

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glLoadMatrixf(modelviewMatrix.toArray().data());


	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, yellow);

	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_FLOAT, 0, positions.data());

	glEnableClientState(GL_NORMAL_ARRAY);
	glNormalPointer(GL_FLOAT, 0, normals.data());

	//glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(positions.size()) / 3);
	for (const auto& b : buffer.getBlocks()) {
		const auto& indices = b.getIndices();
		glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(indices.size()), GL_UNSIGNED_INT, indices.data());
	}

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);

	glDisable(GL_LIGHTING);
	glDisable(GL_LIGHT0);
	glDisable(GL_DEPTH_TEST);

}
/*! Sets the \a lightChunk fields based on light.
    
    \dev
    DeferredShadingStage can not use the light's own chunk, because
    it computes the light position based on DrawEnv::getCameraViewing(),
    which is just the ortho camera for rendering the full screen quads, not
    the perspective camera used during the gbuffer pass.
    \enddev
 */
void DeferredShadingStage::updateLightChunk(
    DSLightChunk *lightChunk, Light *light)
{
    lightChunk->setBeacon  (light->getBeacon  ());
    lightChunk->setAmbient (light->getAmbient ());
    lightChunk->setDiffuse (light->getDiffuse ());
    lightChunk->setSpecular(light->getSpecular());

    if(light->getType() == DirectionalLight::getClassType())
    {
        DirectionalLight *dirL = static_cast<DirectionalLight *>(light);

        Vec4f dir(dirL->getDirection());
        dir[3] = 0.f;

        lightChunk->setPosition(dir);
    }
    else if(light->getType() == PointLight::getClassType())
    {
        PointLight *pointL = static_cast<PointLight *>(light);

        Vec4f pos(pointL->getPosition());
        pos[3] = 1.f;

        lightChunk->setPosition            (pos                              );
        lightChunk->setConstantAttenuation (pointL->getConstantAttenuation ());
        lightChunk->setLinearAttenuation   (pointL->getLinearAttenuation   ());
        lightChunk->setQuadraticAttenuation(pointL->getQuadraticAttenuation());
        lightChunk->setCutoff              (180.f                            );
    }
    else if(light->getType() == SpotLight::getClassType())
    {
        SpotLight *spotL = static_cast<SpotLight *>(light);

        Vec4f pos(spotL->getPosition());
        pos[3] = 1.f;

        lightChunk->setPosition            (pos                             );
        lightChunk->setConstantAttenuation (spotL->getConstantAttenuation ());
        lightChunk->setLinearAttenuation   (spotL->getLinearAttenuation   ());
        lightChunk->setQuadraticAttenuation(spotL->getQuadraticAttenuation());
        lightChunk->setDirection           (spotL->getDirection           ());
        lightChunk->setExponent            (spotL->getSpotExponent        ());
        lightChunk->setCutoff              (
            osgRad2Degree(spotL->getSpotCutOff()));
    }
    else
    {
        SWARNING << "DeferredShadingStage::updateLightChunk: "
                 << "Unknown light type." << endLog;
    }
}
Beispiel #15
0
void MainForm::OnAddPointLight_Click(wxMouseEvent & evt)
{
	PointLightPtr ptr = scene->AddPointLight();
	PointLight * p = ptr.Get();
	p->SetPosition(0.0f, 0.0f, 0.0f);
	p->SetDiffuse(1.0f,1.0f,1.0f,1.0f);
	p->SetRange(100.0f);

	EditorPointLight * pl = new EditorPointLight(ptr);
	EditorSceneObjectsManager::GetPtr()->AddElement(pl);

	ActiveTool::Set(new SelectTool());
}
Action::ResultE ShadingCallbacks::pointlightRenderEnter(CNodePtr &pNode, 
                                                        Action   *action)
{
    PointLight *pPl = dynamic_cast<PointLight *>(pNode.getCPtr());

    if(pPl->getOn() == false)
        return Action::Continue;

    DrawActionBase *da    = dynamic_cast<DrawActionBase *>(action);

    da->getStatistics()->getElem(PointLight::statNPointLights)->inc();

    return lightRenderEnter(pPl, action);
}
Beispiel #17
0
Entity* BlenderSceneExporter::instantiatePointLight( const TamyLight& exportedLightEntity )
{
   Entity* lightEntity = new Entity( exportedLightEntity.name );
   PointLight* light = new PointLight();
   lightEntity->addChild( light );

   light->m_color = exportedLightEntity.lightColor;
   light->m_strength = exportedLightEntity.energy;
   light->m_radius = exportedLightEntity.distance;
   light->m_falloff = exportedLightEntity.quadraticAttenuation;
   light->setShadowsCaster( exportedLightEntity.castShadows );

   return lightEntity;
}
Beispiel #18
0
    void DebugRenderer::RenderSceneDebugSprites(Camera* camera) {
        SpriteRenderer::Get()->Begin(SpriteSortMode::BackToFront);

        BoundingFrustum cameraFrustum(camera->GetView() * camera->GetProjection());

        Vector2f lightSpriteSize(20.0f, 20.0f);

        const vector<AmbientLight*> ambientLights = SceneManager::Get()->GetAmbientLights();
        for(auto it = begin(ambientLights); it != end(ambientLights); ++it) {
            AmbientLight* light = *it;
            if (cameraFrustum.Contains(light->GetCenter())) {
                Vector2f screenPos = light->GetCenter().Project(Matrix::Identity, camera->GetView(), camera->GetProjection(), camera->GetViewport());
                F32 priority = Vector3f::Distance(camera->GetPosition(), light->GetCenter()) / 1000.0f;
                SpriteRenderer::Get()->Render(screenPos + lightSpriteSize, screenPos - lightSpriteSize, ResourceManager::Get()->LoadTextureResource("Icons\\ambient_light.png")->GetTexture(), priority);
            }       
        }

        const vector<PointLight*> pointLights = SceneManager::Get()->GetPointLights();
        for(auto it = begin(pointLights); it != end(pointLights); ++it) {
            PointLight* light = *it;
            if (cameraFrustum.Contains(light->GetCenter())) {
                Vector2f screenPos = light->GetCenter().Project(Matrix::Identity, camera->GetView(), camera->GetProjection(), camera->GetViewport());
                F32 priority = Vector3f::Distance(camera->GetPosition(), light->GetCenter()) / 1000.0f;
                SpriteRenderer::Get()->Render(screenPos + lightSpriteSize, screenPos - lightSpriteSize, ResourceManager::Get()->LoadTextureResource("Icons\\point_light.png")->GetTexture(), priority);
            }   
        }
        
        const vector<DirectionalLight*> directionalLight = SceneManager::Get()->GetDirectionalLights();
        for(auto it = begin(directionalLight); it != end(directionalLight); ++it) {
            DirectionalLight* light = *it;
            if (cameraFrustum.Contains(light->GetCenter())) {
                Vector2f screenPos = light->GetCenter().Project(Matrix::Identity, camera->GetView(), camera->GetProjection(), camera->GetViewport());
                F32 priority = Vector3f::Distance(camera->GetPosition(), light->GetCenter()) / 1000.0f;
                SpriteRenderer::Get()->Render(screenPos + lightSpriteSize, screenPos - lightSpriteSize, ResourceManager::Get()->LoadTextureResource("Icons\\directional_light.png")->GetTexture(), priority);
            }   
        }

        const vector<SpotLight*> spotLights = SceneManager::Get()->GetSpotLights();
        for(auto it = begin(spotLights); it != end(spotLights); ++it) {
            SpotLight* light = *it;
            if (cameraFrustum.Contains(light->GetCenter())) {
                Vector2f screenPos = light->GetCenter().Project(Matrix::Identity, camera->GetView(), camera->GetProjection(), camera->GetViewport());
                F32 priority = Vector3f::Distance(camera->GetPosition(), light->GetCenter()) / 1000.0f;
                SpriteRenderer::Get()->Render(screenPos + lightSpriteSize, screenPos - lightSpriteSize, ResourceManager::Get()->LoadTextureResource("Icons\\spot_light.png")->GetTexture(), priority);
            }   
        }

        SpriteRenderer::Get()->End(camera);
    }
void
makeBunny1Scene()
{
	g_camera = new Camera;
	g_scene = new Scene;
	g_image = new Image;

	g_image->resize(512, 512);

	// set up the camera
	g_camera->setBGColor(Vector3(0.0f, 0.0f, 0.2f));
	g_camera->setEye(Vector3(0, 5, 15));
	g_camera->setLookAt(Vector3(0, 0, 0));
	g_camera->setUp(Vector3(0, 1, 0));
	g_camera->setFOV(45);

	// create and place a point light source
	PointLight * light = new PointLight;
	light->setPosition(Vector3(10, 20, 10));
	light->setColor(Vector3(1, 1, 1));
	light->setWattage(4.0 * PI * 1000);
	g_scene->addLight(light);

	Material* lambert = new Lambert(Vector3(1.0f));
	Material* mirror = new Mirror(Vector3(0.5f));
	TriangleMesh * bunny = new TriangleMesh;
	bunny->load("bunny.obj");
	addMeshTrianglesToScene(bunny, lambert);
    
	// create the floor triangle
	TriangleMesh * floor = new TriangleMesh;
	floor->createSingleTriangle();
	floor->setV1(Vector3(-100, 0, -100));
	floor->setV2(Vector3(   0, 0,  100));
	floor->setV3(Vector3( 100, 0, -100));
	floor->setN1(Vector3(0, 1, 0));
	floor->setN2(Vector3(0, 1, 0));
	floor->setN3(Vector3(0, 1, 0));
    
	Triangle* t = new Triangle;
	t->setIndex(0);
	t->setMesh(floor);
	t->setMaterial(lambert); 
	g_scene->addObject(t);
    
	// let objects do pre-calculations if needed
	g_scene->preCalc();
}
Beispiel #20
0
// ===================
// Stencil pass
// ===================
void World::DoStencilPass(const PointLight& l)
{
    gbuffer.StartStencilPass();
    glClear(GL_STENCIL_BUFFER_BIT);

    glEnable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);

    glStencilFunc(GL_ALWAYS, 0, 0);

    // Bind pass 2 shader.
    Shader* lpassShader = &emptyShader;
    Shader::Bind(lpassShader);

    // Matrices
    Matrix pmat = cam.GetProjectionMatrix();
    Matrix vmat = cam.GetViewMatrix();

    lpassShader->SetParameter("projectionMatrix", &pmat[0][0]);
    lpassShader->SetParameter("viewMatrix", &vmat[0][0]);

    // Draw point light.
    Matrix lmat = l.GetMatrix();
    lpassShader->SetParameter("modelMatrix", &lmat[0][0]);

    mdl3.Draw();
}
Beispiel #21
0
    virtual void draw()
    {
        vec4 diffuse = getDiffuseColor();
        vec4 glow = getGlowColor();
        vec4 light = m_light_color;
        vec4 flash = getDamageColor();

        if(getState()==State_Fadein) {
            float32 s   = (float32)m_st_frame / FADEIN_TIME;
            float shininess = diffuse.w;
            diffuse     *= stl::min<float32>(s*2.0f, 1.0f);
            diffuse.w   = shininess;
            glow        *= stl::max<float32>(s*2.0f-1.0f, 0.0f);
            light       *= s;
        }
        else if(getState()==State_Fadeout) {
            float32 s = 1.0f - ((float32)m_st_frame / FADEOUT_TIME);
            light   *= s;
        }

        if(m_light_radius > 0.0f) {
            if(atmGetConfig()->lighting_level>=atmE_Lighting_Medium) {
                PointLight l;
                l.setPosition(getPositionAbs() + vec3(0.0f, 0.0f, m_light_radius*0.5f));
                l.setColor(light);
                l.setRadius(m_light_radius);
                atmGetLightPass()->addLight(l);
            }
            else {
                flash += light*0.05f;
                glow *= 2.0f;
            }
        }
        if(m_state!=State_Fadeout) {
            PSetInstance inst;
            inst.diffuse = diffuse;
            inst.glow = glow;
            inst.flash = flash;
            inst.elapsed = getPastTime();
            inst.appear_radius = inst.elapsed * 0.004f;
            inst.transform = inst.rotate = getTransformMatrix();
            atmGetFluidPass()->addParticles(getModel(), inst, computeNumParticles());
            atmGetBloodStainPass()->addBloodstainParticles(getTransformMatrix(), getBloodStainParticles(), getNumBloodstainParticles());
        }
    }
Beispiel #22
0
void
Scene::preCalc()
{
    Objects::iterator it;
    for (it = m_objects.begin(); it != m_objects.end(); it++)
    {
        Object* pObject = *it;
        pObject->preCalc();
    }
    Lights::iterator lit;
    for (lit = m_lights.begin(); lit != m_lights.end(); lit++)
    {
        PointLight* pLight = *lit;
        pLight->preCalc();
    }

    m_bvh.build(&m_objects);
}
Beispiel #23
0
	void Scene::UpdateAllPointLights()
	{
		int size = m_pointLightList.size();
		LowLevelGraphics::ShaderProgram::UpdateGlobalShaderParameter(LowLevelGraphics::POINTLIGHTSSIZE, &size, SHADER_INT);
		//PointLight* light = m_pointLightList.at(0)
		//LowLevelGraphics::ShaderProgram::UpdateGlobalShaderParameter(LowLevelGraphics::POINTLIGHTSDIFFUSE, &(light->GetDiffuse()), SHADER_LIGHT_DIFFUSE);

		for(int i = 0; i<m_pointLightList.size(); i++)
		{
			PointLight* light = m_pointLightList.at(i);
			float rad = light->GetRadius();
			LowLevelGraphics::ShaderProgram::UpdateGlobalShaderParameter(LowLevelGraphics::POINTLIGHTSDIFFUSE, &(light->GetDiffuse()), i, SHADER_LIGHT_DIFFUSE);
			LowLevelGraphics::ShaderProgram::UpdateGlobalShaderParameter(LowLevelGraphics::POINTLIGHTSAMBIENT, &(light->GetAmbient()), i, SHADER_LIGHT_AMBIENT);
			LowLevelGraphics::ShaderProgram::UpdateGlobalShaderParameter(LowLevelGraphics::POINTLIGHTSSPECULAR, &(light->GetSpecular()), i, SHADER_LIGHT_SPECULAR);
			LowLevelGraphics::ShaderProgram::UpdateGlobalShaderParameter(LowLevelGraphics::POINTLIGHTSRADIUS, &rad, i, SHADER_LIGHT_RADIUS);
			LowLevelGraphics::ShaderProgram::UpdateGlobalShaderParameter(LowLevelGraphics::POINTLIGHTSTRANSFORM, &(light->GetTransform()->GetMatrix()), i, SHADER_LIGHT_TRANSFORM);
		}
	}
PointLight::PointLight(const PointLight &light) :
    PointLightBase(light),
    DiffuseLightBase(light){
  const float *attenuations;
  attenuations = light.GetAttenuations();
  for(int i = 0; i < 3; ++i){
    m_attenuations[i] = attenuations[i];
  }
}
Vector3
SpecularRefractionShading::shade(const Ray& ray, const HitInfo& hit, const Scene& scene) const
{
	Vector3 L = Vector3(0.0f, 0.0f, 0.0f);

	const Vector3 viewDir = -ray.d; // d is a unit vector

	const Lights *lightlist = scene.lights();

	// loop over all of the lights
	Lights::const_iterator lightIter;
	for (lightIter = lightlist->begin(); lightIter != lightlist->end(); lightIter++)
	{
		PointLight* pLight = *lightIter;

		Vector3 l = pLight->position() - hit.P;

		// the inverse-squared falloff
		float falloff = l.length2();

		// normalize the light direction
		l /= sqrt(falloff);

		// get the diffuse component
		float nDotL = dot(hit.N, l);
		Vector3 result = pLight->color();
		result *= m_kd;

		L += std::max(0.0f, nDotL / falloff * pLight->wattage() / PI) * result;

		Vector3 r = (-l + 2 * dot(l, hit.N) * hit.N).normalized();

		float eDotR = dot(viewDir, r);
		eDotR = 0.0f > eDotR ? 0.0f : 1.0f < eDotR ? 1.0f : eDotR; // clamp it to [0..1]
		eDotR = pow(eDotR, 3);
		L += std::max(0.0f, eDotR * falloff * pLight->wattage());
	}

	// add the ambient component
	L += m_ka;

	return L;
}
Beispiel #26
0
void setup_rc() {
    load_vertices("geode_vertices.dat", vertices);
    load_faces("geode_faces.dat", faces);
    glGenBuffers(1, &vertex_buffer);
    glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
    glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), &vertices[0], GL_STATIC_DRAW);
    glVertexAttribPointer(GLT_ATTRIBUTE_VERTEX, 4 ,GL_FLOAT,GL_FALSE, sizeof(float) * 7, (const GLvoid *)0);
    glVertexAttribPointer(GLT_ATTRIBUTE_NORMAL, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 7, (const GLvoid *)(4*sizeof(float)) );
    glEnableVertexAttribArray(GLT_ATTRIBUTE_VERTEX);
    glEnableVertexAttribArray(GLT_ATTRIBUTE_NORMAL);
    //---
    glGenBuffers(1, &faces_buffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, faces_buffer);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, faces.size() * sizeof(GLuint), &faces[0], GL_STATIC_DRAW);
    //---
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    shader_light = gltLoadShaderPairWithAttributes("gouraud_shading.vp", "gouraud_shading.fp", 3, GLT_ATTRIBUTE_VERTEX, "vertex_position", GLT_ATTRIBUTE_COLOR, "vertex_color", GLT_ATTRIBUTE_NORMAL, "vertex_normal");
    shader_color = gltLoadShaderPairWithAttributes("pass_thru_shader.vp", "pass_thru_shader.fp", 2, GLT_ATTRIBUTE_VERTEX, "vertex_position", GLT_ATTRIBUTE_COLOR, "vertex_color");
    mvp_matrix_location_shader_color = glGetUniformLocation(shader_color, "mvp_matrix");
    mvp_matrix_location = glGetUniformLocation(shader_light, "mvp_matrix");
    mv_matrix_location = glGetUniformLocation(shader_light, "mv_matrix");
    v_matrix_location = glGetUniformLocation(shader_light, "v_matrix");
    normal_matrix_location = glGetUniformLocation(shader_light, "normal_matrix");
    intensity_ambient_component_location = glGetUniformLocation(shader_light, "intensity_ambient_component");
    light_0_position_location = glGetUniformLocation(shader_light, "light_0.position");
    light_0_intensity_diffuse_location = glGetUniformLocation(shader_light, "light_0.intensity_diffuse");
    light_0_intensity_specular_location = glGetUniformLocation(shader_light, "light_0.intensity_specular");
    light_0_attenuation_location = glGetUniformLocation(shader_light, "light_0.attenuation");
    material_0_ka_location = glGetUniformLocation(shader_light, "material_0.ka");
    material_0_kd_location = glGetUniformLocation(shader_light, "material_0.kd");
    material_0_ks_location = glGetUniformLocation(shader_light, "material_0.ks");
    material_0_alpha_location = glGetUniformLocation(shader_light, "material_0.alpha");
    light_0.set_position(0.0f, 0.0f, 0.0f);
    light_0.set_intensity_diffuse(1.0f, 1.0f, 1.0f);
    light_0.set_intensity_specular(1.0f, 1.0f, 1.0f);
    light_0.set_attenuation(0.0f, 0.1f, 0.0f);
    material_0.set_parameters(1.0f, 1.0f, 1.0f, 200.0f);
    geometry_pipeline.SetMatrixStacks(mv_stack, p_stack);
    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    glFrontFace(GL_CCW);
}
void PhotonMapper::forwardPassRay(Ray ray, int x, int y, float weight, int depth){
	Intersection is;
	if (weight > 0 && depth < maxForwardPassDepth && mScene->intersect(ray, is)){
		Hitpoint* hp = new Hitpoint();
		hp->pixelX = x;
		hp->pixelY = y;
		hp->is = is;
		hp->radius = startRadius;
		

		Color reflectedC, refractedC, emittedC;
		Material* m = is.mMaterial;
		float reflectivity = m->getReflectivity(is);
		float transparency = m->getTransparency(is);
		float diffuse = (1.0f - reflectivity - transparency)*weight;
		hp->pixelWeight = (1.0f - reflectivity - transparency) * weight;
		if (reflectivity > 0.0f) {
			Ray reflectedRay = is.getReflectedRay();
			forwardPassRay(reflectedRay, x, y, reflectivity * weight, depth+1);
		}
		if (transparency > 0.0f) {
			Ray refractedRay = is.getRefractedRay();
			forwardPassRay(refractedRay, x, y, transparency * weight, depth+1);
		}

		if (diffuse){
			for (int i = 0; i < mScene->getNumberOfLights(); ++i){
				PointLight* l = mScene->getLight(i);
				if (!mScene->intersect(is.getShadowRay(l))){
					Vector3D lightVec = l->getWorldPosition() - is.mPosition;
					float d2 = lightVec.length2();
					lightVec.normalize();
					Color radiance = l->getRadiance();
					Color brdf = is.mMaterial->evalBRDF(is, lightVec);
					float angle = max(lightVec * is.mNormal, 0.0f);
					hp->directIllumination += radiance * brdf * angle / d2;
				}
			}
			vec.push_back(hp);
		}
	}
}
Beispiel #28
0
void keyPressed()
{
	// Turn light shadows on/off
	if ( key == 'o' )
	{
		shadowsOn = !shadowsOn;
		light.castShadows(shadowsOn);
	}
	// You can control the light attenuation over distance
	else if ( key == '1' )
	{
		// With some attenuation
		light.setAttenuation( 100000, 1, 0.0025, 0 );
	}
	else if ( key == '2' )
	{
		// With no attenuation
		light.setAttenuation( 100000, 1, 0, 0 );
	}
}
Beispiel #29
0
Action::ResultE MergeGraphOp::excludeListLeave(Node * const node, Action::ResultE res)
{
    DirectionalLight *dlight = dynamic_cast<DirectionalLight *>(node->getCore());
    if (dlight!=NULL)
        addToExcludeList(dlight->getBeacon());
    
    Light *light = dynamic_cast<Light *>(node->getCore());
    if (light!=NULL)
        addToExcludeList(light->getBeacon());    
    
    PointLight *plight = dynamic_cast<PointLight *>(node->getCore());
    if (plight!=NULL)
        addToExcludeList(plight->getBeacon());
    
    SpotLight *slight = dynamic_cast<SpotLight *>(node->getCore());
    if (slight!=NULL)
        addToExcludeList(slight->getBeacon());    
    
    return res;
}
Beispiel #30
0
void Shader::SetUniformPointLight(const std::string& uniformName, const PointLight& pointLight) const
{
	SetUniformVector3f(uniformName + ".base.color", pointLight.GetColor());
	SetUniformf(uniformName + ".base.intensity", pointLight.GetIntensity());
	SetUniformf(uniformName + ".atten.constant", pointLight.GetAttenuation().GetConstant());
	SetUniformf(uniformName + ".atten.linear", pointLight.GetAttenuation().GetLinear());
	SetUniformf(uniformName + ".atten.exponent", pointLight.GetAttenuation().GetExponent());
	SetUniformVector3f(uniformName + ".position", pointLight.GetTransform().GetTransformedPos());
	SetUniformf(uniformName + ".range", pointLight.GetRange());
}