本文整理汇总了C++中Light::GetEffectiveColor方法的典型用法代码示例。如果您正苦于以下问题:C++ Light::GetEffectiveColor方法的具体用法?C++ Light::GetEffectiveColor怎么用?C++ Light::GetEffectiveColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Light
的用法示例。
在下文中一共展示了Light::GetEffectiveColor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Prepare
//.........这里部分代码省略.........
for (unsigned i = 0; i < lights.Size(); ++i)
{
Light* vertexLight = lights[i];
Node* vertexLightNode = vertexLight->GetNode();
LightType type = vertexLight->GetLightType();
// Attenuation
float invRange, cutoff, invCutoff;
if (type == LIGHT_DIRECTIONAL)
invRange = 0.0f;
else
invRange = 1.0f / Max(vertexLight->GetRange(), M_EPSILON);
if (type == LIGHT_SPOT)
{
cutoff = Cos(vertexLight->GetFov() * 0.5f);
invCutoff = 1.0f / (1.0f - cutoff);
}
else
{
cutoff = -1.0f;
invCutoff = 1.0f;
}
// Color
float fade = 1.0f;
float fadeEnd = vertexLight->GetDrawDistance();
float fadeStart = vertexLight->GetFadeDistance();
// Do fade calculation for light if both fade & draw distance defined
if (vertexLight->GetLightType() != LIGHT_DIRECTIONAL && fadeEnd > 0.0f && fadeStart > 0.0f && fadeStart < fadeEnd)
fade = Min(1.0f - (vertexLight->GetDistance() - fadeStart) / (fadeEnd - fadeStart), 1.0f);
Color color = vertexLight->GetEffectiveColor() * fade;
vertexLights[i * 3] = Vector4(color.r_, color.g_, color.b_, invRange);
// Direction
vertexLights[i * 3 + 1] = Vector4(-(vertexLightNode->GetWorldDirection()), cutoff);
// Position
vertexLights[i * 3 + 2] = Vector4(vertexLightNode->GetWorldPosition(), invCutoff);
}
if (lights.Size())
graphics->SetShaderParameter(VSP_VERTEXLIGHTS, vertexLights[0].Data(), lights.Size() * 3 * 4);
}
}
if (light && graphics->NeedParameterUpdate(SP_LIGHT, light))
{
// Deferred light volume batches operate in a camera-centered space. Detect from material, zone & pass all being null
bool isLightVolume = !material_ && !pass_ && !zone_;
Matrix3x4 cameraEffectiveTransform = camera_->GetEffectiveWorldTransform();
Vector3 cameraEffectivePos = cameraEffectiveTransform.Translation();
Node* lightNode = light->GetNode();
Matrix3 lightWorldRotation = lightNode->GetWorldRotation().RotationMatrix();
graphics->SetShaderParameter(VSP_LIGHTDIR, lightWorldRotation * Vector3::BACK);
float atten = 1.0f / Max(light->GetRange(), M_EPSILON);
graphics->SetShaderParameter(VSP_LIGHTPOS, Vector4(lightNode->GetWorldPosition(), atten));
if (graphics->HasShaderParameter(VS, VSP_LIGHTMATRICES))
{
示例2: Prepare
//.........这里部分代码省略.........
CalculateSpotMatrix(shadowMatrices[0], light);
bool isShadowed = shadowMap && graphics->HasTextureUnit(TU_SHADOWMAP);
if (isShadowed)
CalculateShadowMatrix(shadowMatrices[1], lightQueue_, 0, renderer);
graphics->SetShaderParameter(VSP_LIGHTMATRICES, shadowMatrices[0].Data(), isShadowed ? 32 : 16);
}
break;
case LIGHT_POINT:
{
Matrix4 lightVecRot(lightNode->GetWorldRotation().RotationMatrix());
// HLSL compiler will pack the parameters as if the matrix is only 3x4, so must be careful to not overwrite
// the next parameter
#ifdef ATOMIC_OPENGL
graphics->SetShaderParameter(VSP_LIGHTMATRICES, lightVecRot.Data(), 16);
#else
graphics->SetShaderParameter(VSP_LIGHTMATRICES, lightVecRot.Data(), 12);
#endif
}
break;
}
}
float fade = 1.0f;
float fadeEnd = light->GetDrawDistance();
float fadeStart = light->GetFadeDistance();
// Do fade calculation for light if both fade & draw distance defined
if (light->GetLightType() != LIGHT_DIRECTIONAL && fadeEnd > 0.0f && fadeStart > 0.0f && fadeStart < fadeEnd)
fade = Min(1.0f - (light->GetDistance() - fadeStart) / (fadeEnd - fadeStart), 1.0f);
// Negative lights will use subtract blending, so write absolute RGB values to the shader parameter
graphics->SetShaderParameter(PSP_LIGHTCOLOR, Color(light->GetEffectiveColor().Abs(),
light->GetEffectiveSpecularIntensity()) * fade);
graphics->SetShaderParameter(PSP_LIGHTDIR, lightDir);
graphics->SetShaderParameter(PSP_LIGHTPOS, lightPos);
if (graphics->HasShaderParameter(PSP_LIGHTMATRICES))
{
switch (light->GetLightType())
{
case LIGHT_DIRECTIONAL:
{
Matrix4 shadowMatrices[MAX_CASCADE_SPLITS];
unsigned numSplits = Min(MAX_CASCADE_SPLITS, lightQueue_->shadowSplits_.Size());
for (unsigned i = 0; i < numSplits; ++i)
CalculateShadowMatrix(shadowMatrices[i], lightQueue_, i, renderer);
graphics->SetShaderParameter(PSP_LIGHTMATRICES, shadowMatrices[0].Data(), 16 * numSplits);
}
break;
case LIGHT_SPOT:
{
Matrix4 shadowMatrices[2];
CalculateSpotMatrix(shadowMatrices[0], light);
bool isShadowed = lightQueue_->shadowMap_ != 0;
if (isShadowed)
CalculateShadowMatrix(shadowMatrices[1], lightQueue_, 0, renderer);
graphics->SetShaderParameter(PSP_LIGHTMATRICES, shadowMatrices[0].Data(), isShadowed ? 32 : 16);
}
break;