Kaynağa Gözat

Work on spot light:
- It now faces proper direction
- Fixed flipped faces for the stencil geometry
- Stencil geometry angles now correspond to the angles of the inspector gizmo
- Falloff angle attentuation works

BearishSun 10 yıl önce
ebeveyn
işleme
e2e3207c14

+ 1 - 1
BansheeEngine/Source/BsLight.cpp

@@ -193,7 +193,7 @@ namespace BansheeEngine
 			vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
 
 			UINT32 numVertices = LIGHT_CONE_NUM_SIDES * LIGHT_CONE_NUM_SLICES * 2;
-			UINT32 numIndices = ((LIGHT_CONE_NUM_SIDES * 2) * LIGHT_CONE_NUM_SLICES * 2) * 3;
+			UINT32 numIndices = ((LIGHT_CONE_NUM_SIDES * 2) * (LIGHT_CONE_NUM_SLICES - 1) * 2) * 3;
 
 			MeshDataPtr meshData = bs_shared_ptr_new<MeshData>(numVertices, numIndices, vertexDesc);
 

+ 8 - 5
RenderBeast/Source/BsLightRendering.cpp

@@ -38,21 +38,24 @@ namespace BansheeEngine
 
 		mBuffer.gLightColorAndIntensity.set(colorAndIntensity);
 
+		Radian spotAngle = Math::clamp(light->getSpotAngle() * 0.5f, Degree(1), Degree(90));
+		Radian spotFalloffAngle = Math::clamp(light->getSpotFalloffAngle() * 0.5f, Degree(1), (Degree)spotAngle);
+
 		Vector3 spotAngles;
-		spotAngles.x = light->getSpotAngle().valueRadians();
-		spotAngles.y = cos(spotAngles.x);
-		spotAngles.z = 1.0f / (Math::cos(light->getSpotFalloffAngle()) - spotAngles.y);
+		spotAngles.x = spotAngle.valueRadians();
+		spotAngles.y = Math::cos(spotAngles.x);
+		spotAngles.z = 1.0f / (Math::cos(spotFalloffAngle) - spotAngles.y);
 
 		mBuffer.gLightSpotAngles.set(spotAngles);
 
-		mBuffer.gLightDirection.set(light->getRotation().zAxis());
+		mBuffer.gLightDirection.set(-light->getRotation().zAxis());
 
 		Vector4 lightGeometry;
 		lightGeometry.x = light->getType() == LightType::Spot ? (float)LightCore::LIGHT_CONE_NUM_SIDES : 0;
 		lightGeometry.y = (float)LightCore::LIGHT_CONE_NUM_SLICES;
 		lightGeometry.z = light->getBounds().getRadius();
 
-		float coneRadius = Math::sin(light->getSpotAngle()) * light->getRange();
+		float coneRadius = Math::sin(spotAngle) * light->getRange();
 		lightGeometry.w = coneRadius;
 
 		mBuffer.gLightGeometry.set(lightGeometry);