- auto tempViewProjectionMatrixIndex = shadowLightCamera.RegisterProperty("tempViewProjectionMatrix", Matrix::IDENTITY);
- Constraint projectionMatrixConstraint = Constraint::New<Matrix>(shadowLightCamera, tempViewProjectionMatrixIndex, [](Matrix& output, const PropertyInputContainer& inputs)
- {
- Matrix worldMatrix = inputs[0]->GetMatrix();
- float tangentFov_2 = tanf(inputs[4]->GetFloat());
- float nearDistance = inputs[5]->GetFloat();
- float farDistance = inputs[6]->GetFloat();
- float aspectRatio = inputs[7]->GetFloat();
- float nearY = 0.0f;
- float nearX = 0.0f;
- float farY = 0.0f;
- float farX = 0.0f;
- if(inputs[1]->GetInteger() == Dali::Camera::ProjectionMode::PERSPECTIVE_PROJECTION)
- {
- if(inputs[2]->GetInteger() == Dali::DevelCameraActor::ProjectionDirection::VERTICAL)
- {
- nearY = tangentFov_2 * nearDistance;
- nearX = nearY * aspectRatio;
- farY = tangentFov_2 * farDistance;
- farX = farY * aspectRatio;
- }
- else
- {
- nearX = tangentFov_2 * nearDistance;
- nearY = nearX / aspectRatio;
- farX = tangentFov_2 * farDistance;
- farY = farX / aspectRatio;
- }
- }
- else
- {
- if(inputs[2]->GetInteger() == Dali::DevelCameraActor::ProjectionDirection::VERTICAL)
- {
- nearY = inputs[3]->GetFloat();
- nearX = nearY * aspectRatio;
- }
- else
- {
- nearX = inputs[3]->GetFloat();
- nearY = nearX / aspectRatio;
- }
- farX = nearX;
- farY = nearY;
- }
-
- std::vector<Vector4> points;
- points.push_back(Vector4(nearX, nearY, nearDistance, 1.0f));
- points.push_back(Vector4(-nearX, nearY, nearDistance, 1.0f));
- points.push_back(Vector4(-nearX, -nearY, nearDistance, 1.0f));
- points.push_back(Vector4(nearX, -nearY, nearDistance, 1.0f));
- points.push_back(Vector4(farX, farY, farDistance, 1.0f));
- points.push_back(Vector4(-farX, farY, farDistance, 1.0f));
- points.push_back(Vector4(-farX, -farY, farDistance, 1.0f));
- points.push_back(Vector4(farX, -farY, farDistance, 1.0f));
-
- Matrix shadowCameraWorldMatrix = inputs[8]->GetMatrix();
- Vector4 worldCenter;
- for(auto&& point : points)
- {
- point = worldMatrix * point;
- worldCenter += point;
- }
- worldCenter /= 8.0f;
- shadowCameraWorldMatrix.SetTranslation(Vector3(worldCenter));
- Matrix shadowCameraViewMatrix = shadowCameraWorldMatrix;
- shadowCameraViewMatrix.Invert();
-
- Vector3 areaMin = Vector3::ONE * MAXFLOAT, areaMax = Vector3::ONE * -MAXFLOAT;
- for(auto&& point : points)
- {
- Vector4 pointV = shadowCameraViewMatrix * point;
- areaMin.x = std::min(areaMin.x, pointV.x);
- areaMin.y = std::min(areaMin.y, pointV.y);
- areaMin.z = std::min(areaMin.z, pointV.z);
- areaMax.x = std::max(areaMax.x, pointV.x);
- areaMax.y = std::max(areaMax.y, pointV.y);
- areaMax.z = std::max(areaMax.z, pointV.z);
- }
-
- Vector2 center = Vector2(areaMax + areaMin) * 0.5;
- float delta = std::max(std::abs(areaMax.x - areaMin.x), std::abs(areaMax.y - areaMin.y));
- float delta_2 = delta * 0.5f;
- Vector2 squareAreaMin = center - Vector2::ONE * delta_2;
- Vector2 squareAreaMax = center + Vector2::ONE * delta_2;
- float deltaZ = areaMax.z - areaMin.z;
-
- float right = -squareAreaMin.x;
- float left = -squareAreaMax.x;
- float top = squareAreaMin.y;
- float bottom = squareAreaMax.y;
- float near = areaMin.z;
- float far = areaMax.z;
-
- float* projMatrix = output.AsFloat();
-
- projMatrix[0] = -2.0f / delta;
- projMatrix[1] = 0.0f;
- projMatrix[2] = 0.0f;
- projMatrix[3] = 0.0f;
-
- projMatrix[4] = 0.0f;
- projMatrix[5] = -2.0f / delta;
- projMatrix[6] = 0.0f;
- projMatrix[7] = 0.0f;
-
- projMatrix[8] = 0.0f;
- projMatrix[9] = 0.0f;
- projMatrix[10] = 2.0f / deltaZ;
- projMatrix[11] = 0.0f;
-
- projMatrix[12] = -(right + left) / delta;
- projMatrix[13] = -(top + bottom) / delta;
- projMatrix[14] = -(near + far) / deltaZ;
- projMatrix[15] = 1.0f;
-
- output = output * shadowCameraViewMatrix;
- });
+ auto tempViewProjectionMatrixIndex = shadowLightCamera.RegisterProperty("tempViewProjectionMatrix", Matrix::IDENTITY);
+ Constraint projectionMatrixConstraint = Constraint::New<Matrix>(shadowLightCamera, tempViewProjectionMatrixIndex, [](Matrix& output, const PropertyInputContainer& inputs) {
+ Matrix worldMatrix = inputs[0]->GetMatrix();
+ float tangentFov_2 = tanf(inputs[4]->GetFloat());
+ float nearDistance = inputs[5]->GetFloat();
+ float farDistance = inputs[6]->GetFloat();
+ float aspectRatio = inputs[7]->GetFloat();
+ float nearY = 0.0f;
+ float nearX = 0.0f;
+ float farY = 0.0f;
+ float farX = 0.0f;
+ if(inputs[1]->GetInteger() == Dali::Camera::ProjectionMode::PERSPECTIVE_PROJECTION)
+ {
+ if(inputs[2]->GetInteger() == Dali::DevelCameraActor::ProjectionDirection::VERTICAL)
+ {
+ nearY = tangentFov_2 * nearDistance;
+ nearX = nearY * aspectRatio;
+ farY = tangentFov_2 * farDistance;
+ farX = farY * aspectRatio;
+ }
+ else
+ {
+ nearX = tangentFov_2 * nearDistance;
+ nearY = nearX / aspectRatio;
+ farX = tangentFov_2 * farDistance;
+ farY = farX / aspectRatio;
+ }
+ }
+ else
+ {
+ if(inputs[2]->GetInteger() == Dali::DevelCameraActor::ProjectionDirection::VERTICAL)
+ {
+ nearY = inputs[3]->GetFloat();
+ nearX = nearY * aspectRatio;
+ }
+ else
+ {
+ nearX = inputs[3]->GetFloat();
+ nearY = nearX / aspectRatio;
+ }
+ farX = nearX;
+ farY = nearY;
+ }
+
+ std::vector<Vector4> points;
+ points.push_back(Vector4(nearX, nearY, nearDistance, 1.0f));
+ points.push_back(Vector4(-nearX, nearY, nearDistance, 1.0f));
+ points.push_back(Vector4(-nearX, -nearY, nearDistance, 1.0f));
+ points.push_back(Vector4(nearX, -nearY, nearDistance, 1.0f));
+ points.push_back(Vector4(farX, farY, farDistance, 1.0f));
+ points.push_back(Vector4(-farX, farY, farDistance, 1.0f));
+ points.push_back(Vector4(-farX, -farY, farDistance, 1.0f));
+ points.push_back(Vector4(farX, -farY, farDistance, 1.0f));
+
+ Matrix shadowCameraWorldMatrix = inputs[8]->GetMatrix();
+ Vector4 worldCenter;
+ for(auto&& point : points)
+ {
+ point = worldMatrix * point;
+ worldCenter += point;
+ }
+ worldCenter /= 8.0f;
+ shadowCameraWorldMatrix.SetTranslation(Vector3(worldCenter));
+ Matrix shadowCameraViewMatrix = shadowCameraWorldMatrix;
+ shadowCameraViewMatrix.Invert();
+
+ Vector3 areaMin = Vector3::ONE * MAXFLOAT, areaMax = Vector3::ONE * -MAXFLOAT;
+ for(auto&& point : points)
+ {
+ Vector4 pointV = shadowCameraViewMatrix * point;
+ areaMin.x = std::min(areaMin.x, pointV.x);
+ areaMin.y = std::min(areaMin.y, pointV.y);
+ areaMin.z = std::min(areaMin.z, pointV.z);
+ areaMax.x = std::max(areaMax.x, pointV.x);
+ areaMax.y = std::max(areaMax.y, pointV.y);
+ areaMax.z = std::max(areaMax.z, pointV.z);
+ }
+
+ Vector2 center = Vector2(areaMax + areaMin) * 0.5;
+ float delta = std::max(std::abs(areaMax.x - areaMin.x), std::abs(areaMax.y - areaMin.y));
+ float delta_2 = delta * 0.5f;
+ Vector2 squareAreaMin = center - Vector2::ONE * delta_2;
+ Vector2 squareAreaMax = center + Vector2::ONE * delta_2;
+ float deltaZ = areaMax.z - areaMin.z;
+
+ float right = -squareAreaMin.x;
+ float left = -squareAreaMax.x;
+ float top = squareAreaMin.y;
+ float bottom = squareAreaMax.y;
+ float near = areaMin.z;
+ float far = areaMax.z;
+
+ float* projMatrix = output.AsFloat();
+
+ projMatrix[0] = -2.0f / delta;
+ projMatrix[1] = 0.0f;
+ projMatrix[2] = 0.0f;
+ projMatrix[3] = 0.0f;
+
+ projMatrix[4] = 0.0f;
+ projMatrix[5] = -2.0f / delta;
+ projMatrix[6] = 0.0f;
+ projMatrix[7] = 0.0f;
+
+ projMatrix[8] = 0.0f;
+ projMatrix[9] = 0.0f;
+ projMatrix[10] = 2.0f / deltaZ;
+ projMatrix[11] = 0.0f;
+
+ projMatrix[12] = -(right + left) / delta;
+ projMatrix[13] = -(top + bottom) / delta;
+ projMatrix[14] = -(near + far) / deltaZ;
+ projMatrix[15] = 1.0f;
+
+ output = output * shadowCameraViewMatrix;
+ });