Пример #1
0
Vector3 Colorful::Shade(const HitInfo& hit, const Scene& scene) const {
    const Ray& ray = hit.eyeRay;
    const Vector3 viewDir = -ray.direction;
    const std::vector<Light*>& lights = scene.GetLights();
    Vector3 shadedColor(0.0f, 0.0f, 0.0f);

    // Loop over all lights
    std::vector<Light*>::const_iterator light_it = lights.begin();
    for (light_it=lights.begin(); light_it != lights.end(); ++light_it) {
		Light* light = *light_it;
		Vector3 direction = light->GetPosition() - hit.point;

		float distance2 = direction.Length2();
		float falloff = light->Falloff(distance2);
		direction.Normalize();

		const float intensity = hit.normal.Dot(direction) * falloff * light->GetWattage() * math::INV_PI;
		if( intensity > 0.0f ) {
			Vector3 color = light->GetColor();
			color *= intensity;

			color = Vector3 (  (1-hit.texCoord.y)*(1-hit.texCoord.y),
							hit.texCoord.x*hit.texCoord.x,
							hit.texCoord.x );

			shadedColor += color;
		}
	}

    return shadedColor;
}
Пример #2
0
void LightPass::UpdateShader(Light& light)
{
	glUniform3fv(m_lightColor_u, 1, glm::value_ptr(light.GetColor()));
	glUniform1f(m_lightAmbientIntencity_u,light.GetAmbientIntencity());
	glUniform1f(m_lightDiffuseIntencity_u, light.GetIntencity());
	glUniform1f(m_constantAttenuation_u, light.GetAttenuationConstant());
	glUniform1f(m_linearAttenuation_u, light.GetAttenuationLinear());
	glUniform1f(m_expAttenuation_u, light.GetAttenuationExp());
	glUniform1f(m_expAttenuation_u, light.GetAttenuationExp());
	glUniform3fv(m_position_u, 1, glm::value_ptr((glm::vec3)(light.GetBoundingSphere()->transform.position)));
}
Пример #3
0
void LightWidget::InitComponent(Component* pComponent)
{
	BaseComponentEditor::InitComponent(pComponent);

	BeginInit();

	Light* pLight = (Light*)pComponent;
	if(pLight != NULL)
	{
		selColor->setColor(pLight->GetColor());
		lblSpeInden->SetText(QString::number(pLight->GetSpecularIntensity()).toStdString().c_str());
		cboLightType->setCurrentIndex((int)pLight->GetLightType());
	}

	EndInit();
}
Пример #4
0
//applying the light at the "stencil-approved" areas
void DefRenderer::LightPass(Camera *cam, Renderer *r)
{
	//setting to pass the stencil test when != 0
	glStencilFunc(GL_NOTEQUAL, 0, 0xFF);

	//writing only on top of the colors from geometry pass
	glDrawBuffer(GL_COLOR_ATTACHMENT0);
	
	glDisable(GL_DEPTH_TEST);
	
	//using additive blending to mix the light and scene fragments
	glEnable(GL_BLEND);
	glBlendFunc(GL_ONE, GL_ONE);

	//try to render from the back to preserve depth information
	glEnable(GL_CULL_FACE);
	glCullFace(GL_FRONT);

	r->Ready();
	mat4 model = r->GetParentGO()->GetModelMatrix();
	mat4 mvp = cam->Get() * model;
	r->GetProgram()->SetUniform("Model", value_ptr(model));
	r->GetProgram()->SetUniform("MVP", value_ptr(mvp));
	vec4 deviceCenter = vec4(mvp * vec4(0, 0, 0, 1)); //center in device coords
	vec3 center(deviceCenter.x, deviceCenter.y, deviceCenter.z);
	r->GetProgram()->SetUniform("Center", &center);
	Light *l = r->GetParentGO()->GetLight();
	float intensity = l->GetIntensity();
	r->GetProgram()->SetUniform("Intensity", &intensity);
	vec4 color = l->GetColor();
	r->GetProgram()->SetUniform("Color", &color);
	r->Render();

	glCullFace(GL_BACK);

	glDisable(GL_BLEND);
	CHECK_GL_ERROR();
}
void
TerrainPatch::Illuminate(Color ambient, List<Light>& lights)
{
	if (!model || model->NumVerts() < 1) return;
	Surface* s = model->GetSurfaces().first();
	if (!s) return;

	illuminating = true;

	// clear the solid lights to ambient:
	VertexSet*  vset   = s->GetVertexSet();
	int         nverts = vset->nverts;
	DWORD       aval   = ambient.Value();

	for (int i = 0; i < nverts; i++) {
		vset->diffuse[i]  = aval;
	}

	TerrainRegion* trgn     = terrain->GetRegion();
	bool           eclipsed = false;
	bool           first    = terrain->IsFirstPatch(this);

	if (trgn && !first) {
		eclipsed = trgn->IsEclipsed();
	}

	// for sun and back lights:
	ListIter<Light> iter = lights;
	while (++iter) {
		Light* light = iter.value();

		if (!light->IsDirectional())                                // only do sun and
		continue;                                                // back lights

		if (light->CastsShadow() && first) {
			eclipsed  = light->Location().y < -100 ||                // has sun set, or

			scene->IsLightObscured(vset->loc[0],         // is sun in eclipse
			light->Location(),    // by orbital body
			radius);              // such as a moon?
		}

		if (!light->CastsShadow() || !eclipsed) {
			Vec3 vl = light->Location();
			vl.Normalize();

			for (int i = 0; i < nverts; i++) {
				Vec3&  nrm = vset->nrm[i];
				double val = 0;
				double gain = vl * nrm;

				if (gain > 0) {
					val = light->Intensity() * (0.85 * gain);

					if (val > 1)
					val = 1;
				}

				if (val > 0.01)
				vset->diffuse[i] = ((light->GetColor().dim(val)) + vset->diffuse[i]).Value();
			}
		}
	}

	// combine blend weights:
	if (ndetail >= 2) {
		for (int i = 0; i < nverts; i++) {
			vset->diffuse[i] = vset->specular[i] | (vset->diffuse[i] & 0x00ffffff);
		}
	}

	if (trgn && first) {
		trgn->SetEclipsed(eclipsed);
	}

	InvalidateSurfaceData();
	illuminating = false;
}
void GameObjectLightComponentWidget::InitFields()
{
	Light* light = nullptr;

	////////////////////////////////////////
	// Set Ready to false, so Light cannot change
	// properties while been initialized
	m_IsReady = false;

	////////////////////////////////////////
	// Check Engine Viewer
	AEAssert(m_EngineViewer != nullptr);
	if (m_EngineViewer == nullptr)
	{
		return;
	}

	////////////////////////////////////////
	// Verify LOC and Get Light Object
	light = GetLight();

	if(light == nullptr)
	{
		AETODO("Add log");

		return;
	}

	////////////////////////////////////////
	// Set Light Type
	SetLightTypeComboBoxIndex(light->GetLightType());

	////////////////////////////////////////
	// Set Enabled
	m_GameObjectLightComponentWidgetQtUI.m_Enabled->setChecked(light->IsEnabled());

	////////////////////////////////////////
	// Set Intensity
	m_GameObjectLightComponentWidgetQtUI.m_IntensitySB->setValue(static_cast<double>(light->GetIntensity()));

	////////////////////////////////////////
	// Set Color
	QColor qColor = AEQTHelpers::GetQColorFromColor(light->GetColor());

	SetColorToColorWidget(qColor);

	////////////////////////////////////////
	// Set Near and Far Attenuation
	m_GameObjectLightComponentWidgetQtUI.m_NearAttSB->setValue(static_cast<double>(light->GetNearAttenuation()));
	m_GameObjectLightComponentWidgetQtUI.m_FarAttSB->setValue(static_cast<double>(light->GetFarAttenuation()));

	////////////////////////////////////////
	// Set Shadow Enabled
	m_GameObjectLightComponentWidgetQtUI.m_ShadowEnabled->setChecked(light->IsShadowEnabled());
	m_GameObjectLightComponentWidgetQtUI.m_DrawFrustum->setEnabled(light->IsShadowEnabled());

	////////////////////////////////////////
	// Enable/Visibility of Angle options
	if(light->GetLightType() == LightType::Spot)
	{
		m_GameObjectLightComponentWidgetQtUI.m_LabelAngle->setVisible(true);
		m_GameObjectLightComponentWidgetQtUI.m_LabelFalloffAngle->setVisible(true);

		m_GameObjectLightComponentWidgetQtUI.m_AngleSB->setVisible(true);
		m_GameObjectLightComponentWidgetQtUI.m_FalloffAngleSB->setVisible(true);

		////////////////////////////////////////
		// Get Spot Light
		SpotLight* spotLight = reinterpret_cast<SpotLight*>(light);

		////////////////////////////////////////
		// Set Angle and Fall out Angle
		m_GameObjectLightComponentWidgetQtUI.m_AngleSB->setValue(static_cast<double>(spotLight->GetAngle()));
		m_GameObjectLightComponentWidgetQtUI.m_FalloffAngleSB->setValue(static_cast<double>(spotLight->GetFallOffAngle()));
	}
	else
	{
		m_GameObjectLightComponentWidgetQtUI.m_LabelAngle->setVisible(false);
		m_GameObjectLightComponentWidgetQtUI.m_LabelFalloffAngle->setVisible(false);

		m_GameObjectLightComponentWidgetQtUI.m_AngleSB->setVisible(false);
		m_GameObjectLightComponentWidgetQtUI.m_FalloffAngleSB->setVisible(false);
	}

	////////////////////////////////////////
	// Enable/Visibility of Draw Frustum Cascades
	if (light->GetLightType() == LightType::Directional)
	{
		m_GameObjectLightComponentWidgetQtUI.m_DrawCascadeFrustums->setVisible(true);
	}
	else
	{
		m_GameObjectLightComponentWidgetQtUI.m_DrawCascadeFrustums->setVisible(false);
	}

	////////////////////////////////////////
	// Light is Ready to change properties
	m_IsReady = true;
}
Пример #7
0
void Shader::SetUniform(const string& name, const Light& value) {
	SetUniform(name + ".color", value.GetColor());
	SetUniform(name + ".ambientIntensity", value.GetAmbientIntensity());
	SetUniform(name + ".diffuseIntensity", value.GetDiffuseIntensity());
}
void TerrainShader::LoadLight(Light& light, float ambientLight)
{
	LoadVector(location_lightPosition, light.GetPosition());
	LoadVector(location_lightColor, light.GetColor());
	LoadFloat(location_ambientLight, ambientLight);
}