|
|
@@ -3,113 +3,79 @@
|
|
|
#include "BsGpuParams.h"
|
|
|
#include "BsLight.h"
|
|
|
|
|
|
+
|
|
|
namespace BansheeEngine
|
|
|
{
|
|
|
- /**
|
|
|
- * Manipulates PerLight parameter buffer used in various shaders.
|
|
|
- */
|
|
|
- class PerLightParamBuffer
|
|
|
+ void PerLightParams::setParameters(const LightCore* light)
|
|
|
{
|
|
|
- public:
|
|
|
- // TODO - Doc
|
|
|
- void initialize()
|
|
|
+ // Note: I could just copy the data directly to the parameter buffer if I ensured the parameter
|
|
|
+ // layout matches
|
|
|
+
|
|
|
+ Vector4 positionAndType = (Vector4)light->getPosition();
|
|
|
+
|
|
|
+ switch (light->getType())
|
|
|
{
|
|
|
- // TODO - This is never called
|
|
|
- // TODO - Create the buffer (think of an automated way of doing it, creating the desc and retrieving the params.
|
|
|
-
|
|
|
- mParams->getParam("gLightPositionAndType", mParamLightPositionAndType);
|
|
|
- mParams->getParam("gLightColorAndIntensity", mParamLightColorAndIntensity);
|
|
|
- mParams->getParam("gLightSpotAngles", mParamLightSpotAngles);
|
|
|
- mParams->getParam("gLightDirection", mParamLightDirection);
|
|
|
- mParams->getParam("gLightGeometry", mParamLightGeometry);
|
|
|
+ case LightType::Directional:
|
|
|
+ positionAndType.w = 0;
|
|
|
+ break;
|
|
|
+ case LightType::Point:
|
|
|
+ positionAndType.w = 0.3f;
|
|
|
+ break;
|
|
|
+ case LightType::Spot:
|
|
|
+ positionAndType.w = 0.8f;
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
- // TODO - Doc
|
|
|
- void setParameters(const LightCore* light)
|
|
|
- {
|
|
|
- // Note: I could just copy the data directly to the parameter buffer if I ensured the parameter
|
|
|
- // layout matches
|
|
|
-
|
|
|
- Vector4 positionAndType = (Vector4)light->getPosition();
|
|
|
-
|
|
|
- switch (light->getType())
|
|
|
- {
|
|
|
- case LightType::Directional:
|
|
|
- positionAndType.w = 0;
|
|
|
- break;
|
|
|
- case LightType::Point:
|
|
|
- positionAndType.w = 0.3f;
|
|
|
- break;
|
|
|
- case LightType::Spot:
|
|
|
- positionAndType.w = 0.8f;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- mParamLightPositionAndType.set(positionAndType);
|
|
|
+ mBuffer.gLightPositionAndType.set(positionAndType);
|
|
|
|
|
|
- Vector4 colorAndIntensity;
|
|
|
- colorAndIntensity.x = light->getColor().r;
|
|
|
- colorAndIntensity.y = light->getColor().g;
|
|
|
- colorAndIntensity.z = light->getColor().b;
|
|
|
- colorAndIntensity.w = light->getIntensity();
|
|
|
-
|
|
|
- mParamLightColorAndIntensity.set(colorAndIntensity);
|
|
|
-
|
|
|
- Vector2 spotAngles;
|
|
|
- spotAngles.x = light->getSpotFalloffAngle().valueDegrees();
|
|
|
- spotAngles.y = light->getSpotAngle().valueDegrees();
|
|
|
-
|
|
|
- mParamLightSpotAngles.set(spotAngles);
|
|
|
+ Vector4 colorAndIntensity;
|
|
|
+ colorAndIntensity.x = light->getColor().r;
|
|
|
+ colorAndIntensity.y = light->getColor().g;
|
|
|
+ colorAndIntensity.z = light->getColor().b;
|
|
|
+ colorAndIntensity.w = light->getIntensity();
|
|
|
|
|
|
- mParamLightDirection.set(light->getRotation().zAxis());
|
|
|
+ mBuffer.gLightColorAndIntensity.set(colorAndIntensity);
|
|
|
|
|
|
- Vector4 lightGeometry;
|
|
|
- lightGeometry.x = 20; // Cone geometry sides
|
|
|
- lightGeometry.y = 10; // Cone geometry slices
|
|
|
- lightGeometry.z = light->getBounds().getRadius();
|
|
|
+ Vector2 spotAngles;
|
|
|
+ spotAngles.x = light->getSpotFalloffAngle().valueDegrees();
|
|
|
+ spotAngles.y = light->getSpotAngle().valueDegrees();
|
|
|
|
|
|
- lightGeometry.w = light->getSpotAngle().valueDegrees();
|
|
|
+ mBuffer.gLightSpotAngles.set(spotAngles);
|
|
|
|
|
|
- mParamLightGeometry.set(lightGeometry);
|
|
|
- }
|
|
|
-
|
|
|
- // TODO - Doc
|
|
|
- SPtr<GpuParamBlockBufferCore> getBuffer()
|
|
|
- {
|
|
|
- return mParams->getParamBlockBuffer(0);
|
|
|
- }
|
|
|
+ mBuffer.gLightDirection.set(light->getRotation().zAxis());
|
|
|
|
|
|
- static PerLightParamBuffer instance;
|
|
|
+ Vector4 lightGeometry;
|
|
|
+ lightGeometry.x = 20; // Cone geometry sides
|
|
|
+ lightGeometry.y = 10; // Cone geometry slices
|
|
|
+ lightGeometry.z = light->getBounds().getRadius();
|
|
|
|
|
|
- private:
|
|
|
- SPtr<GpuParamsCore> mParams;
|
|
|
+ lightGeometry.w = light->getSpotAngle().valueDegrees();
|
|
|
|
|
|
- GpuParamVec4Core mParamLightPositionAndType;
|
|
|
- GpuParamVec4Core mParamLightColorAndIntensity;
|
|
|
- GpuParamVec2Core mParamLightSpotAngles;
|
|
|
- GpuParamVec3Core mParamLightDirection;
|
|
|
- GpuParamVec4Core mParamLightGeometry;
|
|
|
- };
|
|
|
-
|
|
|
- PerLightParamBuffer PerLightParamBuffer::instance;
|
|
|
+ mBuffer.gLightGeometry.set(lightGeometry);
|
|
|
+ }
|
|
|
|
|
|
+ const SPtr<GpuParamBlockBufferCore>& PerLightParams::getBuffer() const
|
|
|
+ {
|
|
|
+ return mBuffer.getBuffer();
|
|
|
+ }
|
|
|
+
|
|
|
void DirectionalLightMat::setParameters(const LightCore* light)
|
|
|
{
|
|
|
- PerLightParamBuffer::instance.setParameters(light);
|
|
|
+ mParams.setParameters(light);
|
|
|
}
|
|
|
|
|
|
void DirectionalLightMat::initialize()
|
|
|
{
|
|
|
- mMaterial->setParamBlockBuffer("PerLight", PerLightParamBuffer::instance.getBuffer());
|
|
|
+ mMaterial->setParamBlockBuffer("PerLight", mParams.getBuffer());
|
|
|
}
|
|
|
|
|
|
void PointLightMat::setParameters(const LightCore* light)
|
|
|
{
|
|
|
- PerLightParamBuffer::instance.setParameters(light);
|
|
|
+ mParams.setParameters(light);
|
|
|
}
|
|
|
|
|
|
void PointLightMat::initialize()
|
|
|
{
|
|
|
- mMaterial->setParamBlockBuffer("PerLight", PerLightParamBuffer::instance.getBuffer());
|
|
|
+ mMaterial->setParamBlockBuffer("PerLight", mParams.getBuffer());
|
|
|
}
|
|
|
}
|