示例#1
0
bool lcLight::Setup(int LightIndex)
{
	GLenum LightName = (GLenum)(GL_LIGHT0 + LightIndex);

	if (mState & LC_LIGHT_DISABLED)
		return false;

	glEnable(LightName);

	glLightfv(LightName, GL_AMBIENT, mAmbientColor);
	glLightfv(LightName, GL_DIFFUSE, mDiffuseColor);
	glLightfv(LightName, GL_SPECULAR, mSpecularColor);

	if (!IsDirectionalLight())
	{
		glLightf(LightName, GL_CONSTANT_ATTENUATION, mAttenuation[0]);
		glLightf(LightName, GL_LINEAR_ATTENUATION, mAttenuation[1]);
		glLightf(LightName, GL_QUADRATIC_ATTENUATION, mAttenuation[2]);

		lcVector4 Position(mPosition, 1.0f);
		glLightfv(LightName, GL_POSITION, Position);
	}
	else
	{
		lcVector4 Position(mPosition, 0.0f);
		glLightfv(LightName, GL_POSITION, Position);
	}

	if (IsPointLight())
	{
		glLightf(LightName, GL_SPOT_CUTOFF, 180.0f);
	}
	else if (IsSpotLight())
	{
		lcVector3 Dir(mTargetPosition - mPosition);
		Dir.Normalize();

		glLightf(LightName, GL_SPOT_CUTOFF, mSpotCutoff);
		glLightf(LightName, GL_SPOT_EXPONENT, mSpotExponent);
		glLightfv(LightName, GL_SPOT_DIRECTION, Dir);
	}

	return true;
}
示例#2
0
bool ON_Light::GetSpotLightRadii( double* inner_radius, double* outer_radius ) const
{
  bool rc = IsSpotLight()?true:false;
  if (rc)
  {
    double angle = SpotAngleRadians();
    if ( !ON_IsValid(angle) || angle <= 0.0 || angle >= 0.5*ON_PI )
      angle = 0.25*ON_PI;
    double spot = HotSpot();
    if ( !ON_IsValid(spot) || spot < 0.0 || spot > 1.0 )
      spot = 0.5;
    double cone_height = Direction().Length();
    if ( !ON_IsValid(cone_height) || cone_height <= 0.0 )
      cone_height = 1.0;

    if ( outer_radius )
      *outer_radius = tan( angle) * cone_height;
    if ( inner_radius )
      *inner_radius = tan( angle * spot) * cone_height;
  }
  return rc;
}
示例#3
0
文件: shader.c 项目: xetxeberria/VEV2
void BeforeDrawShader(ShaderProgram *theProgram) {

	RenderState *rs;
	Light *oneLight;
	Material *mat;
	Texture *tex;
	int i;

	if (theProgram == NULL) return;

	rs = RenderStateScene();

	shader_set_uniform_matrix4(theProgram->modeltoCamera_unif, OpenGLRS(rs, MG_MODELVIEW));
	shader_set_uniform_matrix4(theProgram->modeltoWorld_unif, OpenGLRS(rs, MG_MODEL));
	shader_set_uniform_matrix4(theProgram->CameraToClip_unif, OpenGLRS(rs, MG_PROJECTION));
	shader_set_uniform_matrix4(theProgram->modeltoClip_unif, OpenGLRS(rs, MG_MODELVIEW_PROJECTION));

	i = 0;
	oneLight = StartLoop(rs->lightList);
	while (oneLight) {
		if (IsOnLight(oneLight)) {
			if (i == 4) { // MG_MAX_LIGHTS
				fprintf(stderr, "[W] too many active lights. Discarding the rest\n");
				break;
			}
			shader_set_uniform_4fv(theProgram->light_unif[i].position, GetPositionLight(oneLight));
			shader_set_uniform_3fv(theProgram->light_unif[i].diffuse, GetDiffuseLight(oneLight));
			shader_set_uniform_3fv(theProgram->light_unif[i].ambient, GetAmbientLight(oneLight));
			shader_set_uniform_3fv(theProgram->light_unif[i].specular, GetSpecularLight(oneLight));
			shader_set_uniform_3fv(theProgram->light_unif[i].attenuation, GetAttenuationVectorLight(oneLight));
			if (IsSpotLight(oneLight)) {
				shader_set_uniform_3fv(theProgram->light_unif[i].spotDir, GetSpotDirectionLight(oneLight));
				shader_set_uniform_1f(theProgram->light_unif[i].exponent, GetSpotExponentLight(oneLight));
				shader_set_uniform_1f(theProgram->light_unif[i].cosCutOff, cosf(GetSpotCutoffLight(oneLight)));
			} else {
				shader_set_uniform_1f(theProgram->light_unif[i].cosCutOff, 0.0f); // if (cos) cutoff is zero -> no spotLight
			}
			++i;
		}
		oneLight = GetNext(rs->lightList);
	}
	shader_set_uniform_1i(theProgram->activeLights_unif, i);

	mat = rs->frontMaterial;
	if (mat != NULL) {
		shader_set_uniform_3fv(theProgram->mat_unif.ambient, GetAmbientMaterial(mat));
		shader_set_uniform_3fv(theProgram->mat_unif.diffuse, GetDiffuseMaterial(mat));
		shader_set_uniform_3fv(theProgram->mat_unif.specular, GetSpecularMaterial(mat));
		shader_set_uniform_1f(theProgram->mat_unif.shininess, GetShininessMaterial(mat));
		shader_set_uniform_1f(theProgram->mat_unif.alpha, GetAlphaMaterial(mat));

		tex = GetTextureMaterial(mat);
		if (tex != NULL) {
			// Set texture to unit 0
			BindGLTextureTunit(tex, 0);
			shader_set_uniform_1i(theProgram->texSampler_unif, 0); // Texture unit 0
		}
		tex = GetBumpMapTextureMaterial(mat);
		if (tex != NULL) {
			// bumpMapping in texture unit 1
			BindGLTextureTunit(tex, 1);
			shader_set_uniform_1i(theProgram->bumpSampler_unif, 1); // Bump Texture unit 1
		}
	}
}