@@ -24,6 +24,8 @@ using namespace std;
24
24
25
25
// Metal bug on x86 macOS prevents transparency from working
26
26
#define ENABLE_TRANSPARENTS !(__APPLE__ && __x86_64__)
27
+ #define ENABLE_OPAQUES 1
28
+ #define ENABLE_PARTICLES 1
27
29
28
30
struct RenderingApp : public RavEngine ::App {
29
31
void OnStartup (int argc, char ** argv) final ;
@@ -205,19 +207,9 @@ struct Level : public RavEngine::World {
205
207
Ref<StarMatMaterialInstance> starMaterialInstance;
206
208
ComponentHandle<ParticleEmitter> smokeParticle;
207
209
208
- Level () {
209
-
210
- constexpr static float floorSize = 20 ;
211
- auto floor = Instantiate<GameObject>();
212
- floor .GetTransform ().SetLocalScale (vector3 (floorSize, 1 , floorSize));
213
-
210
+ Level () {
211
+ constexpr static renderlayer_t bakedLayer = 0b01 ;
214
212
auto floorMesh = New<MeshCollectionStatic>(MeshAsset::Manager::Get (" quad" ));
215
- auto floorMat = RavEngine::New<PBRMaterialInstance>(Material::Manager::Get<PBRMaterial>(),2 );
216
- floorMat->SetAlbedoColor ({ 0.5 ,0.5 ,0.5 ,1 });
217
- floor .EmplaceComponent <StaticMesh>(floorMesh, floorMat);
218
-
219
-
220
- // asteroids
221
213
auto asteroidMeshCol = New<MeshCollectionStatic>(std::initializer_list<MeshCollectionStatic::Entry>{
222
214
{
223
215
.mesh = MeshAsset::Manager::Get (" asteroid_lod0" ),
@@ -232,6 +224,17 @@ struct Level : public RavEngine::World {
232
224
.minDistance = 60 ,
233
225
},
234
226
});
227
+ #if ENABLE_OPAQUES
228
+ constexpr static float floorSize = 20 ;
229
+ auto floor = Instantiate<GameObject>();
230
+ floor .GetTransform ().SetLocalScale (vector3 (floorSize, 1 , floorSize));
231
+
232
+ auto floorMat = RavEngine::New<PBRMaterialInstance>(Material::Manager::Get<PBRMaterial>(),2 );
233
+ floorMat->SetAlbedoColor ({ 0.5 ,0.5 ,0.5 ,1 });
234
+ floor .EmplaceComponent <StaticMesh>(floorMesh, floorMat);
235
+
236
+
237
+ // asteroids
235
238
for (int i = 0 ; i < 100 ; i++) {
236
239
auto asteroid = Instantiate<GameObject>();
237
240
asteroid.EmplaceComponent <StaticMesh>(asteroidMeshCol, floorMat);
@@ -240,7 +243,6 @@ struct Level : public RavEngine::World {
240
243
}
241
244
242
245
// baked lighting demo
243
- constexpr static renderlayer_t bakedLayer = 0b01 ;
244
246
{
245
247
auto bakedMat = RavEngine::New<PBRMaterialBakedInstance>(Material::Manager::Get<PBRMaterialBaked>());
246
248
auto lightmapTex = Texture::Manager::Get (" bakedshadow.png" );
@@ -269,6 +271,7 @@ struct Level : public RavEngine::World {
269
271
shinyObject.EmplaceComponent <StaticMesh>(MeshCollectionStaticManager::Get (" sphere" ), shinyMat);
270
272
shinyObject.GetTransform ().SetWorldPosition ({ -2 , 2 , 12 });
271
273
}
274
+ #endif
272
275
273
276
// wine glasses
274
277
#if ENABLE_TRANSPARENTS
@@ -343,13 +346,15 @@ struct Level : public RavEngine::World {
343
346
};
344
347
345
348
auto smokeUpdateMat = New<ParticleUpdateMaterialInstance>(New<SmokeParticleUpdateMaterial>());
346
-
349
+ #if ENABLE_PARTICLES
350
+ #if ENABLE_OPAQUES
347
351
auto & smokeEmitter = smokeParticleEntity.EmplaceComponent <ParticleEmitter>(8192 , sizeof (ParticleRenderData), smokeUpdateMat, smokeRenderMat); // number of particles we want
348
352
// smokeEmitter.mode = ParticleEmitter::Mode::Burst;
349
353
smokeEmitter.Play ();
350
354
smokeParticle = { smokeParticleEntity };
351
355
smokeEmitter.SetEmissionRate (1000 );
352
356
smokeParticleEntity.EmplaceComponent <FlameTag>();
357
+ #endif
353
358
#if ENABLE_TRANSPARENTS
354
359
auto fireParticleEntity = Instantiate<GameObject>();
355
360
auto fireParticleRenderMat = New<FireParticleMaterial>();
@@ -378,18 +383,20 @@ struct Level : public RavEngine::World {
378
383
asteroidEmitterEntity.GetTransform ().LocalTranslateDelta ({0 ,2 ,0 });
379
384
emitter.Play ();
380
385
emitter.SetEmissionRate (50 );
386
+ #endif
381
387
#endif
382
388
383
389
SetupInputs ();
384
-
390
+ # if ENABLE_PARTICLES
385
391
constexpr auto MoveParticleSystem = [](const ParticleEmitter& emitter, const FlameTag& ft, Transform& t) {
386
392
auto time = GetApp ()->GetCurrentTime ();
387
393
t.SetLocalPosition ({ std::sin (time ) * 5 , 0 , 0 });
388
394
};
389
- EmplaceSystem<decltype (MoveParticleSystem)>();
395
+ EmplaceSystem<decltype (MoveParticleSystem)>();
396
+ #endif
390
397
391
398
// create the scene
392
-
399
+ # if ENABLE_OPAQUES
393
400
auto helmetObj = Instantiate<GameObject>();
394
401
auto helmetMesh = New<MeshCollectionStatic>(MeshAsset::Manager::Get (" helmet" ));
395
402
auto helmetMat = New<PBRMaterialInstance>(Material::Manager::Get<PBRMaterial>(),1 );
@@ -429,6 +436,7 @@ struct Level : public RavEngine::World {
429
436
renderTextureMatInst->SetAlbedoTexture (renderTexture->GetTexture ());
430
437
quadEntity.EmplaceComponent <StaticMesh>(MeshCollectionStaticManager::Get (" quad" ),renderTextureMatInst);
431
438
quadEntity.GetTransform ().SetWorldPosition ({10 ,10 ,0 }).SetWorldRotation (vector3{deg_to_rad (90 ),0 ,0 }).SetLocalScale (5 );
439
+ #endif
432
440
}
433
441
434
442
@@ -527,11 +535,15 @@ struct Level : public RavEngine::World {
527
535
528
536
void PreTick (float scale) final {
529
537
fsScale = scale;
538
+ #if ENABLE_OPAQUES
530
539
starMaterialInstance->pushConstantData .applicationTime = GetApp ()->GetCurrentTime ();
540
+ #endif
531
541
}
532
542
533
543
void PostTick (float tickrateScale) final {
534
- camRoot.GetTransform ().LocalTranslateDelta (velvec);
544
+ if (glm::length (velvec) > 0.01 ){
545
+ camRoot.GetTransform ().LocalTranslateDelta (velvec);
546
+ }
535
547
velvec *= 0.9 ;
536
548
537
549
auto now = GetApp ()->GetCurrentTime ();
0 commit comments