From ddb0e2e8c8d85ec11cb65bd7a3d8cf8e61b64b1a Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 19 Oct 2014 20:27:09 +0300 Subject: [PATCH] games/digger: Move lights to client side --- extensions/urho3d/safe_classes.lua | 1 + games/digger/main/client_lua/init.lua | 32 ++++++++++++++++++++++++++- games/digger/main/main.cpp | 19 ---------------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/extensions/urho3d/safe_classes.lua b/extensions/urho3d/safe_classes.lua index f538aaf..87a384d 100644 --- a/extensions/urho3d/safe_classes.lua +++ b/extensions/urho3d/safe_classes.lua @@ -284,6 +284,7 @@ function M.define(dst, util) castShadows = util.simple_property("boolean"), shadowBias = util.simple_property("BiasParameters"), shadowCascade = util.simple_property("CascadeParameters"), + color = util.simple_property("Color"), }, }) diff --git a/games/digger/main/client_lua/init.lua b/games/digger/main/client_lua/init.lua index 712bb48..1b80640 100644 --- a/games/digger/main/client_lua/init.lua +++ b/games/digger/main/client_lua/init.lua @@ -26,14 +26,42 @@ local scene = replicate.main_scene magic.input:SetMouseVisible(false) +-- Set up zone (global visual parameters) local zone_node = scene:CreateChild("Zone") local zone = zone_node:CreateComponent("Zone") zone.boundingBox = magic.BoundingBox(-1000, 1000) +--zone.ambientColor = magic.Color(0.15, 0.15, 0.15) zone.ambientColor = magic.Color(0.1, 0.1, 0.1) +--zone.ambientColor = magic.Color(0, 0, 0) zone.fogColor = magic.Color(0.6, 0.7, 0.8) zone.fogStart = 10 zone.fogEnd = FOG_END +-- Add lights +--local node = scene:CreateChild("DirectionalLight") +--node.direction = magic.Vector3(0.0, -1.0, 0.0) +--local light = node:CreateComponent("Light") +--light.lightType = magic.LIGHT_DIRECTIONAL +--light.castShadows = true +--light.brightness = 0.1 +--light.color = magic.Color(1.0, 1.0, 1.0) + +local node = scene:CreateChild("DirectionalLight") +node.direction = magic.Vector3(-0.6, -1.0, 0.8) +local light = node:CreateComponent("Light") +light.lightType = magic.LIGHT_DIRECTIONAL +light.castShadows = true +light.brightness = 0.8 +light.color = magic.Color(1.0, 1.0, 0.95) + +local node = scene:CreateChild("DirectionalLight") +node.direction = magic.Vector3(0.3, -1.0, -0.4) +local light = node:CreateComponent("Light") +light.lightType = magic.LIGHT_DIRECTIONAL +light.castShadows = true +light.brightness = 0.2 +light.color = magic.Color(0.7, 0.7, 1.0) + -- Add a node that the player can use to walk around with local player_node = scene:CreateChild("Player") --player_node.position = magic.Vector3(0, 30, 0) @@ -60,7 +88,7 @@ local camera_node = player_node:CreateChild("Camera") camera_node.position = magic.Vector3(0, 0.411*PLAYER_HEIGHT, 0) --camera_node:Pitch(13.60000) local camera = camera_node:CreateComponent("Camera") -camera.nearClip = 0.2 +camera.nearClip = 0.3 camera.farClip = RENDER_DISTANCE camera.fov = 75 @@ -68,6 +96,8 @@ camera.fov = 75 local viewport = magic.Viewport:new(scene, camera_node:GetComponent("Camera")) magic.renderer:SetViewport(0, viewport) +-- Tell about the camera to the voxel world so it can do stuff based on the +-- camera's position and other properties voxelworld.set_camera(camera_node) -- Add some text diff --git a/games/digger/main/main.cpp b/games/digger/main/main.cpp index fb02911..5c172a2 100644 --- a/games/digger/main/main.cpp +++ b/games/digger/main/main.cpp @@ -201,25 +201,6 @@ struct Module: public interface::Module Context *context = scene->GetContext(); ResourceCache *cache = context->GetSubsystem(); - { - Node *node = scene->CreateChild("DirectionalLight"); - node->SetDirection(Vector3(-0.6f, -1.0f, 0.8f)); - Light *light = node->CreateComponent(); - light->SetLightType(LIGHT_DIRECTIONAL); - light->SetCastShadows(true); - light->SetBrightness(0.8); - light->SetColor(Color(1.0, 1.0, 0.95)); - } - { - Node *node = scene->CreateChild("DirectionalLight"); - node->SetDirection(Vector3(0.3f, -1.0f, -0.4f)); - Light *light = node->CreateComponent(); - light->SetLightType(LIGHT_DIRECTIONAL); - light->SetCastShadows(true); - light->SetBrightness(0.2); - light->SetColor(Color(0.7, 0.7, 1.0)); - } - voxelworld::access(m_server, [&](voxelworld::Interface *ivoxelworld) { interface::VoxelRegistry *voxel_reg =