Commit 3fd5e7def35780ff817953f7699b1112a9ded459
1 parent
d9f0323e
Shadow Mapping sample
Change-Id: I04963704002e914b4730e69e805ddb057bd012ae Signed-off-by: seungho baek <sbsh.baek@samsung.com>
Showing
1 changed file
with
108 additions
and
30 deletions
examples/scene3d-light/scene3d-light-example.cpp
| ... | ... | @@ -28,6 +28,8 @@ using Dali::Toolkit::TextLabel; |
| 28 | 28 | const std::string imagedir = DEMO_IMAGE_DIR; |
| 29 | 29 | const std::string uri_diffuse_texture(imagedir + "papermill_E_diffuse-64.ktx"); |
| 30 | 30 | const std::string uri_specular_texture(imagedir + "papermill_pmrem.ktx"); |
| 31 | +const std::string uri_diffuse_texture2(imagedir + "Studio/Irradiance.ktx"); | |
| 32 | +const std::string uri_specular_texture2(imagedir + "Studio/Radiance.ktx"); | |
| 31 | 33 | |
| 32 | 34 | // This example shows how to create and display Hello World! using a simple TextActor |
| 33 | 35 | // |
| ... | ... | @@ -56,14 +58,13 @@ public: |
| 56 | 58 | sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT); |
| 57 | 59 | sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT); |
| 58 | 60 | sceneView.SetBackgroundColor(Color::BEIGE); |
| 59 | - sceneView.SetProperty(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE, 0.5f); | |
| 60 | - sceneView.SetProperty(Dali::CameraActor::Property::FAR_PLANE_DISTANCE, 0.5f); | |
| 61 | + sceneView.UseFramebuffer(true); | |
| 61 | 62 | |
| 62 | 63 | light1 = Scene3D::Light::New(); |
| 63 | 64 | light1.SetProperty(Dali::Actor::Property::COLOR, Color::BROWN); |
| 64 | - light1.SetProperty(Dali::Actor::Property::POSITION, Vector3(-2.0f, -2.0f, 0.0f)); | |
| 65 | + light1.SetProperty(Dali::Actor::Property::POSITION, Vector3(-2.0f, -0.5f, 0.0f)); | |
| 65 | 66 | Dali::DevelActor::LookAt(light1, Vector3(0.0f, 0.0f, 0.0f)); |
| 66 | - Dali::Animation animation = Dali::Animation::New(3); | |
| 67 | + mAnimation = Dali::Animation::New(5); | |
| 67 | 68 | Dali::KeyFrames keyFrames = Dali::KeyFrames::New(); |
| 68 | 69 | keyFrames.Add(0.0f, Quaternion(Radian(Degree(0.0f)), Vector3::YAXIS)); |
| 69 | 70 | keyFrames.Add(0.25f, Quaternion(Radian(Degree(90.0f)), Vector3::YAXIS)); |
| ... | ... | @@ -77,19 +78,24 @@ public: |
| 77 | 78 | dummyActor.Add(light1); |
| 78 | 79 | sceneView.Add(dummyActor); |
| 79 | 80 | |
| 80 | - animation.AnimateBetween(Dali::Property(dummyActor, Dali::Actor::Property::ORIENTATION), keyFrames); | |
| 81 | - animation.Play(); | |
| 82 | - animation.SetLooping(true); | |
| 81 | + mAnimation.AnimateBetween(Dali::Property(dummyActor, Dali::Actor::Property::ORIENTATION), keyFrames); | |
| 82 | + mAnimation.Play(); | |
| 83 | + mAnimation.SetLooping(true); | |
| 84 | + light1.Enable(true); | |
| 85 | + light1.EnableShadow(true); | |
| 86 | + light1.EnableShadowSoftFiltering(true); | |
| 83 | 87 | |
| 84 | 88 | light2 = Scene3D::Light::New(); |
| 85 | - light2.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE); | |
| 86 | - Dali::DevelActor::LookAt(light2, Vector3(1.0f, 1.0f, -1.0f)); | |
| 89 | + light2.SetProperty(Dali::Actor::Property::COLOR, Color::WHITE * 0.4); | |
| 90 | + light2.SetProperty(Dali::Actor::Property::POSITION, Vector3(-1.0f, 0.0f, 1.1f)); | |
| 91 | + Dali::DevelActor::LookAt(light2, Vector3(0.0, 0.0, 0.0f)); | |
| 92 | + light2.EnableShadow(true); | |
| 87 | 93 | sceneView.Add(light2); |
| 88 | 94 | |
| 89 | 95 | light3 = Scene3D::Light::New(); |
| 90 | - light3.SetProperty(Dali::Actor::Property::COLOR, Color::WHITE * 0.4); | |
| 91 | - light3.SetProperty(Dali::Actor::Property::POSITION, Vector3(-1.0f, 0.0f, 1.1f)); | |
| 92 | - Dali::DevelActor::LookAt(light3, Vector3(0.0, 0.0, 0.0f)); | |
| 96 | + light3.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE); | |
| 97 | + light3.SetProperty(Dali::Actor::Property::POSITION, Vector3(-2.0, 0.0, -0.6)); | |
| 98 | + Dali::DevelActor::LookAt(light3, Vector3(0.0f, 0.0f, 0.0f)); | |
| 93 | 99 | sceneView.Add(light3); |
| 94 | 100 | |
| 95 | 101 | light4 = Scene3D::Light::New(); |
| ... | ... | @@ -104,21 +110,22 @@ public: |
| 104 | 110 | Dali::DevelActor::LookAt(light5, Vector3(0.0, 0.0, 0.0f)); |
| 105 | 111 | sceneView.Add(light5); |
| 106 | 112 | |
| 107 | - light6 = Scene3D::Light::New(); | |
| 108 | - light6.SetProperty(Dali::Actor::Property::COLOR, Color::CYAN); | |
| 109 | - light6.SetProperty(Dali::Actor::Property::POSITION, Vector3(-1.0f, -1.2f, 1.1f)); | |
| 110 | - Dali::DevelActor::LookAt(light6, Vector3(0.0, 0.0, 0.0f)); | |
| 111 | - sceneView.Add(light6); | |
| 112 | - | |
| 113 | 113 | CameraActor camera = sceneView.GetSelectedCamera(); |
| 114 | - camera.SetProperty(Dali::Actor::Property::POSITION, Vector3(-1.0f, 0.0f, 1.1f)); | |
| 114 | + camera.SetProperty(Dali::Actor::Property::POSITION, Vector3(1.5f, 0.0f, 1.5f)); | |
| 115 | 115 | Dali::DevelActor::LookAt(camera, Vector3(0.0, 0.0, 0.0f)); |
| 116 | + camera.SetProperty(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE, 1.0f); | |
| 117 | + camera.SetProperty(Dali::CameraActor::Property::FAR_PLANE_DISTANCE, 4.0f); | |
| 116 | 118 | |
| 117 | 119 | Scene3D::Model model = Scene3D::Model::New(std::string(DEMO_MODEL_DIR) + "DamagedHelmet.gltf"); |
| 118 | - model.SetProperty(Dali::Actor::Property::POSITION, Vector3(0.0f, 0.0f, 0.0f)); | |
| 120 | + model.SetProperty(Dali::Actor::Property::POSITION, Vector3(-0.5f, 0.0f, 0.0f)); | |
| 119 | 121 | model.SetProperty(Dali::Actor::Property::SIZE, Vector3::ONE); |
| 120 | 122 | sceneView.Add(model); |
| 121 | 123 | |
| 124 | + Scene3D::Model model2 = Scene3D::Model::New(std::string(DEMO_MODEL_DIR) + "microphone.gltf"); | |
| 125 | + model2.SetProperty(Dali::Actor::Property::POSITION, Vector3(0.2f, 0.0f, 0.0f)); | |
| 126 | + model2.SetProperty(Dali::Actor::Property::SIZE, Vector3::ONE); | |
| 127 | + sceneView.Add(model2); | |
| 128 | + | |
| 122 | 129 | window.Add(sceneView); |
| 123 | 130 | |
| 124 | 131 | // Respond to a touch anywhere on the window |
| ... | ... | @@ -151,48 +158,118 @@ public: |
| 151 | 158 | sceneView.SetImageBasedLightSource("", "", 1.0f); |
| 152 | 159 | light1.Enable(true); |
| 153 | 160 | light2.Enable(true); |
| 154 | - light6.Enable(false); // to reset state of lights | |
| 155 | - light6.Enable(true); | |
| 156 | 161 | light3.Enable(true); |
| 162 | + light4.Enable(true); | |
| 163 | + light5.Enable(true); | |
| 164 | + light1.EnableShadow(true); | |
| 165 | + light2.EnableShadow(false); | |
| 166 | + mAnimation.Play(); | |
| 157 | 167 | } |
| 158 | 168 | if(event.GetKeyName() == "1") |
| 159 | 169 | { |
| 160 | - sceneView.SetImageBasedLightSource(uri_diffuse_texture, uri_specular_texture, 0.6f); | |
| 161 | - light1.Enable(false); | |
| 162 | - light2.Enable(false); | |
| 170 | + sceneView.SetImageBasedLightSource(uri_diffuse_texture2, uri_specular_texture2, 0.6f); | |
| 171 | + light1.Enable(true); | |
| 172 | + light2.Enable(true); | |
| 173 | + light3.Enable(true); | |
| 174 | + light4.Enable(true); | |
| 175 | + light5.Enable(true); | |
| 176 | + light1.EnableShadow(true); | |
| 177 | + light2.EnableShadow(false); | |
| 178 | + mAnimation.Play(); | |
| 163 | 179 | } |
| 164 | 180 | else if(event.GetKeyName() == "2") |
| 165 | 181 | { |
| 166 | - sceneView.SetImageBasedLightSource(uri_diffuse_texture, uri_specular_texture, 0.6f); | |
| 182 | + sceneView.SetImageBasedLightSource(uri_diffuse_texture2, uri_specular_texture2, 0.6f); | |
| 167 | 183 | light1.Enable(true); |
| 168 | 184 | light2.Enable(true); |
| 185 | + light3.Enable(true); | |
| 186 | + light4.Enable(true); | |
| 187 | + light5.Enable(true); | |
| 188 | + light1.EnableShadow(false); | |
| 189 | + light2.EnableShadow(true); | |
| 190 | + mAnimation.Play(); | |
| 169 | 191 | } |
| 170 | 192 | else if(event.GetKeyName() == "3") |
| 171 | 193 | { |
| 172 | - sceneView.SetImageBasedLightSource(uri_diffuse_texture, uri_specular_texture, 0.3f); | |
| 194 | + sceneView.SetImageBasedLightSource(uri_diffuse_texture, uri_specular_texture, 0.6f); | |
| 173 | 195 | light1.Enable(true); |
| 174 | 196 | light2.Enable(true); |
| 197 | + light3.Enable(true); | |
| 198 | + light4.Enable(true); | |
| 199 | + light5.Enable(true); | |
| 200 | + light1.EnableShadow(true); | |
| 201 | + light2.EnableShadow(false); | |
| 202 | + mAnimation.Play(); | |
| 175 | 203 | } |
| 176 | 204 | else if(event.GetKeyName() == "4") |
| 177 | 205 | { |
| 178 | - sceneView.SetImageBasedLightSource(uri_diffuse_texture, uri_specular_texture, 0.1f); | |
| 206 | + sceneView.SetImageBasedLightSource(uri_diffuse_texture, uri_specular_texture, 0.3f); | |
| 179 | 207 | light1.Enable(true); |
| 180 | 208 | light2.Enable(true); |
| 209 | + light3.Enable(true); | |
| 210 | + light4.Enable(true); | |
| 211 | + light5.Enable(true); | |
| 212 | + light1.EnableShadow(true); | |
| 213 | + light2.EnableShadow(false); | |
| 214 | + mAnimation.Play(); | |
| 181 | 215 | } |
| 182 | 216 | else if(event.GetKeyName() == "5") |
| 183 | 217 | { |
| 184 | - sceneView.SetImageBasedLightSource(uri_diffuse_texture, uri_specular_texture, 0.0f); | |
| 218 | + sceneView.SetImageBasedLightSource(uri_diffuse_texture, uri_specular_texture, 0.1f); | |
| 185 | 219 | light1.Enable(true); |
| 220 | + light2.Enable(true); | |
| 221 | + light3.Enable(true); | |
| 222 | + light4.Enable(true); | |
| 223 | + light5.Enable(true); | |
| 224 | + light1.EnableShadow(true); | |
| 225 | + light2.EnableShadow(false); | |
| 226 | + mAnimation.Play(); | |
| 186 | 227 | } |
| 187 | 228 | else if(event.GetKeyName() == "6") |
| 188 | 229 | { |
| 189 | 230 | sceneView.SetImageBasedLightSource(uri_diffuse_texture, uri_specular_texture, 0.0f); |
| 190 | - light1.Enable(false); | |
| 231 | + light1.Enable(true); | |
| 232 | + light2.Enable(true); | |
| 233 | + light3.Enable(true); | |
| 234 | + light4.Enable(true); | |
| 235 | + light5.Enable(true); | |
| 236 | + light1.EnableShadow(true); | |
| 237 | + light2.EnableShadow(false); | |
| 238 | + mAnimation.Play(); | |
| 239 | + } | |
| 240 | + else if(event.GetKeyName() == "7") | |
| 241 | + { | |
| 242 | + sceneView.SetImageBasedLightSource(uri_diffuse_texture, uri_specular_texture, 0.6f); | |
| 243 | + light1.Enable(true); | |
| 244 | + light2.Enable(true); | |
| 245 | + light3.Enable(true); | |
| 246 | + light4.Enable(true); | |
| 247 | + light5.Enable(true); | |
| 248 | + light2.EnableShadow(false); | |
| 249 | + light1.EnableShadow(!light1.IsShadowEnabled()); | |
| 250 | + mAnimation.Play(); | |
| 251 | + } | |
| 252 | + else if(event.GetKeyName() == "8") | |
| 253 | + { | |
| 254 | + light1.EnableShadowSoftFiltering(!light1.IsShadowSoftFilteringEnabled()); | |
| 255 | + light2.EnableShadowSoftFiltering(!light2.IsShadowSoftFilteringEnabled()); | |
| 256 | + } | |
| 257 | + else if(event.GetKeyName() == "9") | |
| 258 | + { | |
| 259 | + progress += 0.05; | |
| 260 | + if(progress >= 1.0) | |
| 261 | + { | |
| 262 | + progress = 0.0f; | |
| 263 | + } | |
| 264 | + mAnimation.Play(); | |
| 265 | + mAnimation.SetCurrentProgress(progress); | |
| 266 | + mAnimation.Pause(); | |
| 191 | 267 | } |
| 192 | 268 | } |
| 193 | 269 | } |
| 194 | 270 | |
| 195 | 271 | private: |
| 272 | + float progress{0.0f}; | |
| 196 | 273 | Application& mApplication; |
| 197 | 274 | Scene3D::Light light1; |
| 198 | 275 | Scene3D::Light light2; |
| ... | ... | @@ -201,6 +278,7 @@ private: |
| 201 | 278 | Scene3D::Light light5; |
| 202 | 279 | Scene3D::Light light6; |
| 203 | 280 | Scene3D::SceneView sceneView; |
| 281 | + Dali::Animation mAnimation; | |
| 204 | 282 | }; |
| 205 | 283 | |
| 206 | 284 | int DALI_EXPORT_API main(int argc, char** argv) | ... | ... |