|
@@ -182,7 +182,7 @@ void InitScene()
|
|
|
StaticModel@ object = objectNode.CreateComponent("StaticModel");
|
|
StaticModel@ object = objectNode.CreateComponent("StaticModel");
|
|
|
object.model = cache.GetResource("Model", "Models/Mushroom.mdl");
|
|
object.model = cache.GetResource("Model", "Models/Mushroom.mdl");
|
|
|
object.material = cache.GetResource("Material", "Materials/Mushroom.xml");
|
|
object.material = cache.GetResource("Material", "Materials/Mushroom.xml");
|
|
|
- object.castShadows = true;
|
|
|
|
|
|
|
+ object.castShadows = CheckInLight(object);
|
|
|
|
|
|
|
|
CollisionShape@ shape = objectNode.CreateComponent("CollisionShape");
|
|
CollisionShape@ shape = objectNode.CreateComponent("CollisionShape");
|
|
|
shape.SetTriangleMesh(cache.GetResource("Model", "Models/Mushroom.mdl"), 0);
|
|
shape.SetTriangleMesh(cache.GetResource("Model", "Models/Mushroom.mdl"), 0);
|
|
@@ -199,7 +199,7 @@ void InitScene()
|
|
|
AnimatedModel@ object = objectNode.CreateComponent("AnimatedModel");
|
|
AnimatedModel@ object = objectNode.CreateComponent("AnimatedModel");
|
|
|
object.model = cache.GetResource("Model", "Models/Jack.mdl");
|
|
object.model = cache.GetResource("Model", "Models/Jack.mdl");
|
|
|
object.material = cache.GetResource("Material", "Materials/Jack.xml");
|
|
object.material = cache.GetResource("Material", "Materials/Jack.xml");
|
|
|
- object.castShadows = true;
|
|
|
|
|
|
|
+ object.castShadows = CheckInLight(object);
|
|
|
|
|
|
|
|
AnimationController@ ctrl = objectNode.CreateComponent("AnimationController");
|
|
AnimationController@ ctrl = objectNode.CreateComponent("AnimationController");
|
|
|
ctrl.Play("Models/Jack_Walk.ani", 0, true, 0.0f);
|
|
ctrl.Play("Models/Jack_Walk.ani", 0, true, 0.0f);
|
|
@@ -218,6 +218,25 @@ void InitScene()
|
|
|
renderer.viewports[0] = Viewport(testScene, camera);
|
|
renderer.viewports[0] = Viewport(testScene, camera);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+bool CheckInLight(Drawable@ drawable)
|
|
|
|
|
+{
|
|
|
|
|
+ // Check for occluders blocking the directional light to this drawable, using a simple raycast test
|
|
|
|
|
+ Node@ lightNode = testScene.GetChild("GlobalLight", true);
|
|
|
|
|
+ Ray reverseLightRay(drawable.node.position, -lightNode.direction);
|
|
|
|
|
+ Array<RayQueryResult> result = testScene.octree.Raycast(reverseLightRay, RAY_TRIANGLE, 250.0, DRAWABLE_GEOMETRY);
|
|
|
|
|
+
|
|
|
|
|
+ for (uint i = 0; i < result.length; ++i)
|
|
|
|
|
+ {
|
|
|
|
|
+ Drawable@ otherDrawable = result[i].drawable;
|
|
|
|
|
+ if (otherDrawable is drawable)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ if (otherDrawable.castShadows && otherDrawable.occluder)
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void HandleUpdate(StringHash eventType, VariantMap& eventData)
|
|
void HandleUpdate(StringHash eventType, VariantMap& eventData)
|
|
|
{
|
|
{
|
|
|
float timeStep = eventData["TimeStep"].GetFloat();
|
|
float timeStep = eventData["TimeStep"].GetFloat();
|