예제 #1
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());
}
예제 #2
0
파일: World.cpp 프로젝트: aleios/3dapp
// ===================
// Point lights
// ===================
void World::DoLightingPass(const PointLight& l)
{
    gbuffer.StartLightingPass();

    // Disable depth test.
    glDisable(GL_DEPTH_TEST);

    // Setup for lighting pass.
    glStencilFunc(GL_NOTEQUAL, 0, 0xFF);

    glEnable(GL_BLEND);

    glEnable(GL_CULL_FACE);
    glCullFace(GL_FRONT);

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

    // Activate gbuffer textures.
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, gbuffer.GetColorID());
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, gbuffer.GetNormalID());
    glActiveTexture(GL_TEXTURE2);
    glBindTexture(GL_TEXTURE_2D, gbuffer.GetPositionID());

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

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

    // Set the eye position to the camera position.
    Vector3 cpos = cam.GetPosition();
    lpassShader->SetParameter("eyePosition", cpos.x, cpos.y, cpos.z);
    lpassShader->SetParameter("farClipDistance", cam.GetFarClippingPlane());

    // Texture locations
    lpassShader->SetParameter("difftex", 0);
    lpassShader->SetParameter("normtex", 1);
    lpassShader->SetParameter("postex", 2);

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

    const Vector3& pos = l.GetPosition();
    lpassShader->SetParameter("lightPos", pos.x, pos.y, pos.z);

    // Itensity.
    lpassShader->SetParameter("ambientIntensity", l.GetAmbientIntensity());
    lpassShader->SetParameter("diffuseIntensity", l.GetDiffuseIntensity());

    // Attenuation.
    lpassShader->SetParameter("attenuationConstant", l.GetAttenuationConstant());
    lpassShader->SetParameter("attenuationLinear", l.GetAttenuationLinear());
    lpassShader->SetParameter("attenuationExponential", l.GetAttenuationExponential());

    Color diffuseColor = l.GetColor();
    lpassShader->SetParameter("lightColor", diffuseColor.R(), diffuseColor.G(), diffuseColor.B());

    pointLightMesh.Draw();

    glCullFace(GL_BACK);
    glDisable(GL_BLEND);
}
예제 #3
0
void BaseLightShaderModule::Use(Mesh* mesh, mat4 toWorldTransform, Camera* camera)
{
	float specularPower = BaseLight::GetSpecularPower();
	float specularIntensity = BaseLight::GetSpecularIntensity();

	glUniform1f(_specularPowerLocation, specularPower);
	glUniform1f(_specularIntensityLocation, specularIntensity);

	vec3 eyePos = camera->GetPositionInWorld();
	glUniform3f(_eyeWorldPosLocation, eyePos.x, eyePos.y, eyePos.z);

	DirectionLight* dirLight = Director::GetInstance()->GetCurrentTree()->_directionLight;
	if (dirLight)
	{
		glUniform3f(_dirLightUniformLocation.color, dirLight->GetColor().r, dirLight->GetColor().g, dirLight->GetColor().b);

		glUniform1f(_dirLightUniformLocation.ambientIntensity, dirLight->GetAmbientIntensity());

		glUniform1f(_dirLightUniformLocation.diffuseIntensity, dirLight->GetDiffuseIntensity());

		vec3 direction = dirLight->GetDirection();
		direction = glm::normalize(direction);
		glUniform3f(_dirLightUniformLocation.direction, direction.x, direction.y, direction.z);
	}

	vector<PointLight*>& pointLights = Director::GetInstance()->GetCurrentTree()->_pointLights;
	glUniform1i(_pointLightsNumLocation, pointLights.size());
	for (int i = 0; i < pointLights.size(); i++)
	{
		PointLight* light = pointLights[i];
		tPointLightLocation& loc = _pointLightsLocation[i];

		glUniform3f(loc.color, light->GetColor().r, light->GetColor().g, light->GetColor().b);

		glUniform1f(loc.ambientIntensity, light->GetAmbientIntensity());

		glUniform1f(loc.diffuseIntensity, light->GetDiffuseIntensity());

		vec3 lightWorldPos = light->GetPositionInWorld();
		glUniform3f(loc.worldPos, lightWorldPos.x, lightWorldPos.y, lightWorldPos.z);

		glUniform1f(loc.constant, light->GetConstant());

		glUniform1f(loc.linear, light->GetLinear());

		glUniform1f(loc.exp, light->GetExp());
	}


	vector<SpotLight*>& spotLights = Director::GetInstance()->GetCurrentTree()->_spotLights;
	glUniform1i(_spotLightsNumLocation, spotLights.size());
	for (int i = 0; i < spotLights.size(); i++)
	{
		SpotLight* light = spotLights[i];
		tSpotLightLocation& loc = _spotLightsLocation[i];

		glUniform3f(loc.color, light->GetColor().r, light->GetColor().g, light->GetColor().b);

		glUniform1f(loc.ambientIntensity, light->GetAmbientIntensity());

		glUniform1f(loc.diffuseIntensity, light->GetDiffuseIntensity());

		vec3 lightWorldPos = light->GetPositionInWorld();
		glUniform3f(loc.worldPos, lightWorldPos.x, lightWorldPos.y, lightWorldPos.z);

		glUniform1f(loc.constant, light->GetConstant());

		glUniform1f(loc.linear, light->GetLinear());

		glUniform1f(loc.exp, light->GetExp());

		vec3 direction = light->GetDirection();
		direction = glm::normalize(direction);
		glUniform3f(loc.direction, direction.x, direction.y, direction.z);

		glUniform1f(loc.cutoff, light->GetCutoff());
	}

	glUniform1i(_openNormalMapLocation, mesh->HaveNormalMap() ? 1 : 0);
}