示例#1
0
void Game::Init()
{
	//Vertex data[3] = {Vertex(Vector3f(-1,-1,0)),
	//				 Vertex(Vector3f(0,1,0)),
	//				 Vertex(Vector3f(1,-1,0))};

	//mesh.addVertices(data, ARRAY_SIZE(data));

	//Vertex data[] = {Vertex(Vector3f(-1.0f, -1.0f, 0.5773f), Vector2f(0.0f, 0.0f)),
	//				 Vertex(Vector3f(0.0f, -1.0f, -1.15475f), Vector2f(0.5f, 0.0f)),
	//				 Vertex(Vector3f(1.0f, -1.0f, 0.5773f), Vector2f(1.0f, 0.0f)),
	//				 Vertex(Vector3f(0.0f, 1.0f, 0.0f), Vector2f(0.5f, 1.0f))};

	//int indices[] = { 0, 3, 1,
	//				  1, 3, 2,
	//				  2, 3, 0,
	//				  1, 2, 0};

	float fieldDepth = 10.0f;
	float fieldWidth = 10.0f;
		
	Vertex data[] = { 	Vertex( Vector3f(-fieldWidth, 0.0f, -fieldDepth), Vector2f(0.0f, 0.0f)),
						Vertex(Vector3f(-fieldWidth, 0.0f, fieldDepth * 3), Vector2f(0.0f, 1.0f)),
						Vertex(Vector3f(fieldWidth * 3, 0.0f, -fieldDepth), Vector2f(1.0f, 0.0f)),
						Vertex(Vector3f(fieldWidth * 3, 0.0f, fieldDepth * 3),Vector2f(1.0f, 1.0f))};
		
	int indices[] = { 0, 1, 2,
					  2, 1, 3};

	m_mesh.AddVertices(data, ARRAY_SIZE_IN_ELEMENTS(data), indices, ARRAY_SIZE_IN_ELEMENTS(indices));

	m_color.Set(1,1,1);

	//m_texture = Texture("test.png");
	m_texture = new Texture("test.png");
	m_material = Material(m_texture, m_color, 1, 8);

	m_shader = PhongShader::GetInstance();
	//PhongShader::SetAmbientLight(Vector3f(0.1f,0.1f,0.1f));
	PhongShader::SetDirectionalLight(DirectionalLight(BaseLight(Vector3f(1,1,1),0.1f),Vector3f(1,1,1)));

	m_pLights = new PointLight[2];
	m_pLights[0] = PointLight(BaseLight(Vector3f(1,0.5f,0), 0.8f), Attenuation(0,0,1), Vector3f(-2,0,5), 10);
	m_pLights[1] = PointLight(BaseLight(Vector3f(0,0.5f,1), 0.8f), Attenuation(0,0,1), Vector3f(2,0,7), 10);

	m_sLights = new SpotLight[1];
	m_sLights[0] = SpotLight(PointLight(BaseLight(Vector3f(0,1,1), 0.8f), Attenuation(0,0,0.1f), Vector3f(-2,0,5), 30),Vector3f(1,1,1).Normalized(),0.8f);

	PhongShader::SetPointLights(m_pLights, 2);
	PhongShader::SetSpotLights(m_sLights, 1);

	m_camera = Camera();

	Transform::SetProjection(70.0f, (float)Window::GetWidth(), (float)Window::GetHeight(), 0.1f, 1000.0f);
	Transform::SetCamera(m_camera);
}
示例#2
0
void Scene::setupLights()
{
	ngl::ShaderManager* shader = ngl::ShaderManager::instance();
	
	for( unsigned int i = 0; i < m_pointlights.size(); i++ ) {
		ngl::Vector tmp;
		tmp = ngl::Vector( sin( i ) * 2.0, ( float )i * 0.06, cos( i ) * 2.0 ) + 0.5;
		m_pointlights[i] = PointLight( tmp + ngl::Vector( 5, 0, 5 ), 2.2, ngl::Vector( 1, 1, 1 ) );
	}
	
	////////////////////////
	//setup light points
	( *shader )["DemoPL"]->use();
	
	float vertices[] = {0.0, 0.0, 0.0};
	
	glGenVertexArrays( 1, &m_lightVAO );
	glBindVertexArray( m_lightVAO );
	
	GLuint vboIDLight;
	glGenBuffers( 1, &vboIDLight );
	
	glBindBuffer( GL_ARRAY_BUFFER, vboIDLight );
	glBufferData( GL_ARRAY_BUFFER, 3 * sizeof( GLfloat ), vertices, GL_STATIC_DRAW );
	
	( *shader )["DemoPL"]->vertexAttribPointer( "a_VertPos", 3, GL_FLOAT, 0, 0 );
	( *shader )["DemoPL"]->enableAttribArray( "a_VertPos" );
	
	glEnableVertexAttribArray( 0 );
	glBindVertexArray( 0 );
}
示例#3
0
文件: main.cpp 项目: shadercoder/scge
void fillLightsGrid(std::vector<PointLight> &lights, Window &window)
{
	lights.clear();
	for(int x = 0; x < 8; ++x)
		for(int y = 0; y < 8; ++y)
			for(int z = 0; z < 8; ++z)
				lights.push_back(PointLight(window.GetGraphicsDevice().getRenderer3D(), Vector3(-1280.0f + (340.0f * x), 40.0f + (340.0f * y), -1280.0f + (340.0f * z)), Vector3(0.5f, 0.5f, 0.5f), 10, 510));
}
示例#4
0
 PointLight LightRenderer::CreatePointLight()
 {
     return PointLight(
         *this->_point.position,
         *this->_point.range,
         *this->_point.diffuseColor,
         *this->_point.specularColor);
 }
/*LLeafNode definition*/
LindenmayerTreeNode::LLeafNode::LLeafNode(Shader* s, Mesh* m, float max_growth) : max_growth(max_growth), SceneNode(s, m) {
	modelScale = Vector3(0, 0, 0);
	/*Initialise a light that may or may not be rendered depending on when
	the node was grown (each tree will render a single leaf light in the 
	deferred pass)*/
	light = PointLight();
	float r = 0.5f + (float)(rand() % 129) / 128.0f;
	float g = 0.5f + (float)(rand() % 129) / 128.0f;
	float b = 0.5f + (float)(rand() % 129) / 128.0f;
	light.SetColour(Vector4(r, g, b, 1));
	light.SetRadius(300 - ((((float)rand()) / (float)400)) + (float)100);
}
示例#6
0
PointLight *Scene::addPointLight()
{
	if (_numLights >= MAX_SCENE_LIGHTS) return NULL;
	_pointLights[_numPointLights] = PointLight();
	_pointLights[_numPointLights].cColor = Float3(0.1f, 0.3f, 0.7f);
	_pointLights[_numPointLights].cPos = Float3();
	_pointLights[_numPointLights].cRadius = 1.0f;

	_numPointLights++;
	_numLights++;

	return &_pointLights[_numPointLights - 1];
}
示例#7
0
int main(int argc, char *argv[])
{

    World world(QColor(0,180,180));

    int samples = 1;

    Material *material = new Reflective (QColor(2,255,255), 0.4, 1, 300, 0.6);
    PinholeCamera camera(Vector3(0,0,0),Vector3(0,0,1),Vector3(0,-1,0),Vector2(1,0.75),1);


    world.add(new Sphere(Vector3(-2,-1.15,1), 2,  material));
    world.add(new Sphere(Vector3(2,-1.15,1), 2,  material));
    world.add(new Sphere(Vector3(0,3.45-1.15,1), 2,  material));
    world.add(new Sphere(Vector3(0,1.15-1.15,3.45+1), 2,  material));

    JitteredGenerator gener(0);
    SquareDistributor dist;
    Sampler distributor(gener,dist,samples,60,0);




    world.add_light(PointLight(Vector3(0,0,3.45-2), MyColor(1,1,1)));

    Raytracer tracer(5);
    QImage image;
    image = tracer.ray_trace(world, camera, QSize(800, 600), &distributor);




    QApplication a(argc, argv);
    MainWindow w;

    w.copy_world(image, world);
    w.show_image();
   // w.new_world();
    w.show();
    
    return a.exec();
}
bool LightManager::Initialize(ID3D11Device* _device, int _currentLevel)
{
	HRESULT result;
	int count;


#pragma region Pointlight level positioning
	// Level 1
	XMFLOAT4 hus01_lightPos[] = { XMFLOAT4(15.0f, 30.0f, -11.0f, 1.0f), XMFLOAT4(-46.0f, 28.0f, 8.0f, 1.0f), 
								  XMFLOAT4(-20.0f, 31.0f, -3.0f, 1.0f), XMFLOAT4(37.0f, 11.0f, 9.0f, 1.0f), 
								  XMFLOAT4(0.0f, 5.0f, -5.0f, 1.0f) 
								};

	// Level 2
	XMFLOAT4 hus02_lightPos[] = { XMFLOAT4(-1.0f, 46.0f, 7.5f, 1.0f), XMFLOAT4(-1.3f, 26.0f, 65.0f, 1.0f),
								  XMFLOAT4(-3.70f, 65.20f, 70.5f, 1.0f), XMFLOAT4(-113.8f, 26.7f, 81.5f, 1.0f),
								  XMFLOAT4(-121.3f, 64.7f, 61.0f, 1.0f), XMFLOAT4(-117.8f, 51.7f, 37.2f, 1.0f),
								  XMFLOAT4(-111.8f, 50.7f, -12.5f, 1.0f), XMFLOAT4(-175.8f, 57.7f, -10.5f, 1.0f),
								  XMFLOAT4(-227.8f, 69.7f, 77.5f, 1.0f), XMFLOAT4(-233.8f, 73.7f, 36.5f, 1.0f),
								  XMFLOAT4(-266.4f, 56.7f, 23.5f, 1.0f), XMFLOAT4(-266.4f, 64.7f, 68.5f, 1.0f),		// End of crystal lights

								  XMFLOAT4(0.0f, 0.0f, 35.0f, 1.0f), XMFLOAT4(0.0f, 19.0f, 31.0f, 1.0f),			// Start of scene lights
								  XMFLOAT4(0.0f, 19.0f, 3.0f, 1.0f), XMFLOAT4(0.0f, 38.0f, 44.0f, 1.0f),
								  XMFLOAT4(-11.8f, 60.1f, 32.7f, 1.0f), XMFLOAT4(85.4f, 72.9f, 8.5f, 1.0f),
								  XMFLOAT4(-74.7f, 38.2f, 33.0f, 1.0f), XMFLOAT4(-176.6f, 46.0f, 33.0f, 1.0f),
								  XMFLOAT4(-200.0f, 68.3f, 68.1f, 1.0f)
								};

	// Level 3
	XMFLOAT4 hus03_lightPos[] = { XMFLOAT4(50.1f, 28.2f, -22.6f, 1.0f), XMFLOAT4(26.9f, 27.6f, 29.6f, 1.0f), XMFLOAT4(59.5f, 30.7f, 33.0f, 1.0f), 
								  XMFLOAT4(62.3f, 31.9f, 88.6f, 1.0f), XMFLOAT4(62.6f, 29.6f, 173.3f, 1.0f), XMFLOAT4(-14.5f, 5.2f, 166.2f, 1.0f),
								  XMFLOAT4(-37.4f, 21.8f, 190.2f, 1.0f), XMFLOAT4(-66.2f, 35.7f, 166.0f, 1.0f), XMFLOAT4(-104.2f, 46.6f, 239.0f, 1.0f),
								  XMFLOAT4(-104.3f, 45.5f, 295.6f, 1.0f), XMFLOAT4(-75.5f, 45.6f, 296.7f, 1.0f), XMFLOAT4(-18.1f, 43.0f, 358.0f, 1.0f),
								  XMFLOAT4(-71.0f, 25.3f, 389.8f, 1.0f), XMFLOAT4(-71.0f, 25.3f, 448.8f, 1.0f), XMFLOAT4(-71.0f, 25.3f, 496.5f, 1.0f),
								  XMFLOAT4(-18.0f, 44.4f, 478.9f, 1.0f), XMFLOAT4(-18.0f, 44.4f, 417.6f, 1.0f),		// End of crystal lights

								  XMFLOAT4(0.0f, 21.4f, 15.3f, 1.0f), XMFLOAT4(58.1f, 21.4f, -7.2f, 1.0f), XMFLOAT4(58.1f, 28.4f, 60.9f, 1.0f),		// Start of scene lights
								  XMFLOAT4(58.1f, 28.4f, 136.7f, 1.0f), XMFLOAT4(45.7f, 28.4f, 195.8f, 1.0f), XMFLOAT4(0.5f, 52.7f, 171.9f, 1.0f),
								  XMFLOAT4(-49.8f, 7.8f, 177.7f, 1.0f), XMFLOAT4(-106.0f, 29.8f, 180.7f, 1.0f), XMFLOAT4(-106.0f, 29.8f, 257.0f, 1.0f),
								  XMFLOAT4(-103.7f, 29.8f, 298.2f, 1.0f), XMFLOAT4(-42.3f, 29.8f, 298.2f, 1.0f), XMFLOAT4(-33.0f, 29.8f, 359.1f, 1.0f),
								  XMFLOAT4(-33.3f, 29.8f, 416.4f, 1.0f), XMFLOAT4(-42.9f, 29.8f, 499.1f, 1.0f), XMFLOAT4(-42.9f, 29.8f, 499.1f, 1.0f)
								};

#pragma endregion


	// Directional light
	enviroLightObj.light.direction = { 0.0f, 1.0f, 2.0f };
	enviroLightObj.light.diffuse = { 0.0f, 0.0f, 0.0f, 1.0f };
	enviroLightObj.light.ambient = { 0.2f, 0.2f, 0.2f, 1.0f };

	XMFLOAT4 crystalDiff = { 0.2f, 0.4f, 1.0f, 1.0f };


	lightBufferObj.lights = new PointLight[LIGHT_COUNT];
	if (!lightBufferObj.lights)
	{
		return false;
	}

	for (int i = 0; i < LIGHT_COUNT; i++)
	{
		lightBufferObj.lights[i] = PointLight();
	}

	
	// Point lights
	switch (_currentLevel)
	{
	case 0:
		count = 5;

		for (int i = 0; i < count; i++)
		{
			lightBufferObj.lights[i].position = hus01_lightPos[i];
			lightBufferObj.lights[i].diffuse = crystalDiff;
			lightBufferObj.lights[i].intensity = 10;
			lightBufferObj.lights[i].attenuation = { 0.0f, 0.0f, 0.6f };
		}

		lightBufferObj.lights[4].diffuse = { 0.8f, 0.8f, 0.8f, 1.0f };
		lightBufferObj.lights[4].attenuation = { 0.0f, 0.2f, 0.0f };
		lightBufferObj.lights[4].intensity = 5;

		break;

	case 1:
		count = 21;

		// Crystal lights
		for (int i = 0; i < count - 8; i++)
		{
			lightBufferObj.lights[i].position = hus02_lightPos[i];
			lightBufferObj.lights[i].diffuse = crystalDiff;
			lightBufferObj.lights[i].intensity = 10;
			lightBufferObj.lights[i].attenuation = { 0.0f, 0.0f, 0.6f };
		}

		// Enviroment lights
		for (int i = 12; i < count; i++)
		{
			lightBufferObj.lights[i].position = hus02_lightPos[i];
			lightBufferObj.lights[i].diffuse = { 0.7f, 0.5f, 0.5f, 1.0f };
			lightBufferObj.lights[i].intensity = 3;
			lightBufferObj.lights[i].attenuation = { 0.0f, 0.5f, 0.0f };
		}
		break;

	case 2:
		count = 32;

		// Crystal lights
		for (int i = 0; i < count - 15; i++)
		{
			lightBufferObj.lights[i].position = hus03_lightPos[i];
			lightBufferObj.lights[i].diffuse = crystalDiff;
			lightBufferObj.lights[i].intensity = 10;
			lightBufferObj.lights[i].attenuation = { 0.0f, 0.0f, 0.6f };
		}

		// Enviroment lights
		for (int i = 15; i < count; i++)
		{
			lightBufferObj.lights[i].position = hus03_lightPos[i];
			lightBufferObj.lights[i].diffuse = { 0.6f, 0.6f, 0.8f, 1.0f };
			lightBufferObj.lights[i].intensity = 5;
			lightBufferObj.lights[i].attenuation = { 0.0f, 0.5f, 0.0f };
		}
		break;
	}


	lightBuffer = new ID3D11Buffer*[2];

	D3D11_BUFFER_DESC lightBufferDesc;

	ZeroMemory(&lightBufferDesc, sizeof(D3D11_BUFFER_DESC));
	lightBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	lightBufferDesc.Usage = D3D11_USAGE_DEFAULT;

	lightBufferDesc.ByteWidth = sizeof(DirectionalLight);
	result = _device->CreateBuffer(&lightBufferDesc, NULL, &lightBuffer[0]);
	if (FAILED(result))
	{
		return false;
	}


	lightBufferDesc.ByteWidth = sizeof(PointLight) * LIGHT_COUNT;
	result = _device->CreateBuffer(&lightBufferDesc, NULL, &lightBuffer[1]);
	if (FAILED(result))
	{
		return false;
	}

	return true;
}
示例#9
0
    void LightingPass::CreateLightBufferData(const std::vector<Light *> & lights)
    {
        m_pointLights.clear();
        m_directionalLights.clear();

        for (auto light : lights)
        {
            unsigned int dindex = m_directionalLights.size();
            unsigned int pindex = m_pointLights.size();

            switch(light->GetLightType())
            {
            case LightType::DIRECTIONAL:
                m_directionalLights.push_back(DirectionalLight());

                m_directionalLights[dindex].direction = Vector4(light->GetLightDirection(), 1.f);

                m_directionalLights[dindex].ambient = light->GetAmbientLight();
                m_directionalLights[dindex].diffuse = light->GetDiffuseLight();
                m_directionalLights[dindex].specular = light->GetSpecularLight();
                break;

            case LightType::POINT:
                m_pointLights.push_back(PointLight());

                //LOG_ERR(light->GetAttenuationConstant(), ", ", light->GetAttenuationLinear(), ", ", light->GetAttenuationQuadratic());

                m_pointLights[pindex].position = Vector4(light->worldTransform.Position(), 1.f);

                m_pointLights[pindex].ambient = light->GetAmbientLight();
                m_pointLights[pindex].diffuse = light->GetDiffuseLight();
                m_pointLights[pindex].specular = light->GetSpecularLight();

                m_pointLights[pindex].constant = light->GetAttenuationConstant();
                m_pointLights[pindex].linear = light->GetAttenuationLinear();
                m_pointLights[pindex].quadratic = light->GetAttenuationQuadratic();
                break;

            default:
                LOG_WARN("Unknown light type, unable to render: ", light->GetLightType());
                break;
            }
        }

        // XXX hack
        // make sure at least 2 point lights exist, and 1 directional light
        switch (m_directionalLights.size())
        {
        case 0:
            m_directionalLights.push_back(DirectionalLight());
            break;
        }

        switch (m_pointLights.size())
        {
        case 1:
            m_pointLights.push_back(PointLight());
            
            m_pointLights[m_pointLights.size() - 1].constant = 1.f;
            m_pointLights[m_pointLights.size() - 1].linear = 0.045f;
            m_pointLights[m_pointLights.size() - 1].quadratic = 0.0075f;

            break;

        case 0:
            for (int i = 0; i < 2; i++)
            {
                m_pointLights.push_back(PointLight());
            }
            break;
        }
    }
示例#10
0
static void parseCommandLine(Ref<ParseStream> cin, const FileName& path)
{
    while (true)
    {
        std::string tag = cin->getString();
        if (tag == "") return;

        /* parse command line parameters from a file */
        else if (tag == "-c") {
            FileName file = path + cin->getFileName();
            parseCommandLine(new ParseStream(new LineCommentFilter(file, "#")), file.path());
        }

        /* load OBJ model*/
        else if (tag == "-i") {
            filename = path + cin->getFileName();
        }

        /* parse camera parameters */
        else if (tag == "-vp") g_camera.from = cin->getVec3fa();
        else if (tag == "-vi") g_camera.to = cin->getVec3fa();
        else if (tag == "-vd") g_camera.to = g_camera.from + cin->getVec3fa();
        else if (tag == "-vu") g_camera.up = cin->getVec3fa();
        else if (tag == "-fov") g_camera.fov = cin->getFloat();

        /* frame buffer size */
        else if (tag == "-size") {
            g_width = cin->getInt();
            g_height = cin->getInt();
        }

        /* full screen mode */
        else if (tag == "-fullscreen")
            g_fullscreen = true;

        /* output filename */
        else if (tag == "-o") {
            outFilename = cin->getFileName();
            g_interactive = false;
        }

        else if (tag == "-objlist") {
            keyframeList = cin->getFileName();
        }

        /* subdivision mode */
        else if (tag == "-cache")
            g_subdiv_mode = ",subdiv_accel=bvh4.subdivpatch1cached";

        else if (tag == "-pregenerate")
            g_subdiv_mode = ",subdiv_accel=bvh4.grid.eager";

        else if (tag == "-anim")
            g_anim_mode = true;

        else if (tag == "-instancing") {
            std::string mode = cin->getString();
            if      (mode == "none"    ) g_instancing_mode = 0;
            else if (mode == "geometry") g_instancing_mode = 1;
            else if (mode == "scene"   ) g_instancing_mode = 2;
            else throw std::runtime_error("unknown instancing mode: "+mode);
        }

        /* number of frames to render in benchmark mode */
        else if (tag == "-benchmark") {
            g_skipBenchmarkFrames = cin->getInt();
            g_numBenchmarkFrames  = cin->getInt();
            g_interactive = false;
        }

        /* rtcore configuration */
        else if (tag == "-rtcore")
            g_rtcore = cin->getString();

        /* number of threads to use */
        else if (tag == "-threads")
            g_numThreads = cin->getInt();

        /* ambient light source */
        else if (tag == "-ambientlight")
        {
            const Vec3fa L = cin->getVec3fa();
            g_scene->add(new SceneGraph::LightNode<AmbientLight>(AmbientLight(L)));
        }

        /* point light source */
        else if (tag == "-pointlight")
        {
            const Vec3fa P = cin->getVec3fa();
            const Vec3fa I = cin->getVec3fa();
            g_scene->add(new SceneGraph::LightNode<PointLight>(PointLight(P,I)));
        }

        /* directional light source */
        else if (tag == "-directionallight" || tag == "-dirlight")
        {
            const Vec3fa D = cin->getVec3fa();
            const Vec3fa E = cin->getVec3fa();
            g_scene->add(new SceneGraph::LightNode<DirectionalLight>(DirectionalLight(D,E)));
        }

        /* distant light source */
        else if (tag == "-distantlight")
        {
            const Vec3fa D = cin->getVec3fa();
            const Vec3fa L = cin->getVec3fa();
            const float halfAngle = cin->getFloat();
            g_scene->add(new SceneGraph::LightNode<DistantLight>(DistantLight(D,L,halfAngle)));
        }

        /* skip unknown command line parameter */
        else {
            std::cerr << "unknown command line parameter: " << tag << " ";
            while (cin->peek() != "" && cin->peek()[0] != '-') std::cerr << cin->getString() << " ";
            std::cerr << std::endl;
        }
    }
}
示例#11
0
void Light::addPointLight(D3DXVECTOR3 position, float intensity, D3DXVECTOR3 color)
{
	pointLights[m_addedPointLights] = PointLight(position, intensity, color);
	m_addedPointLights++;
}
示例#12
0
 ptr<PointLight> PointLight::create( const glm::vec3 position, const Color color, const float intensity, const float distance ){
     return make_shared<PointLight>(PointLight(position, color, intensity, distance));
 }