Skip to content

Commit 3ab8cd9

Browse files
author
Ravbug
committed
Merge branch 'master' of https://github.com/RavEngine/Samples
2 parents 0365b46 + 2f7e2ea commit 3ab8cd9

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

Samples/Rendering/main.cpp

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ using namespace std;
2424

2525
// Metal bug on x86 macOS prevents transparency from working
2626
#define ENABLE_TRANSPARENTS !(__APPLE__ && __x86_64__)
27+
#define ENABLE_OPAQUES 1
28+
#define ENABLE_PARTICLES 1
2729

2830
struct RenderingApp : public RavEngine::App {
2931
void OnStartup(int argc, char** argv) final;
@@ -205,19 +207,9 @@ struct Level : public RavEngine::World {
205207
Ref<StarMatMaterialInstance> starMaterialInstance;
206208
ComponentHandle<ParticleEmitter> smokeParticle;
207209

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;
214212
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
221213
auto asteroidMeshCol = New<MeshCollectionStatic>(std::initializer_list<MeshCollectionStatic::Entry>{
222214
{
223215
.mesh = MeshAsset::Manager::Get("asteroid_lod0"),
@@ -232,6 +224,17 @@ struct Level : public RavEngine::World {
232224
.minDistance = 60,
233225
},
234226
});
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
235238
for (int i = 0; i < 100; i++) {
236239
auto asteroid = Instantiate<GameObject>();
237240
asteroid.EmplaceComponent<StaticMesh>(asteroidMeshCol, floorMat);
@@ -240,7 +243,6 @@ struct Level : public RavEngine::World {
240243
}
241244

242245
// baked lighting demo
243-
constexpr static renderlayer_t bakedLayer = 0b01;
244246
{
245247
auto bakedMat = RavEngine::New<PBRMaterialBakedInstance>(Material::Manager::Get<PBRMaterialBaked>());
246248
auto lightmapTex = Texture::Manager::Get("bakedshadow.png");
@@ -269,6 +271,7 @@ struct Level : public RavEngine::World {
269271
shinyObject.EmplaceComponent<StaticMesh>(MeshCollectionStaticManager::Get("sphere"), shinyMat);
270272
shinyObject.GetTransform().SetWorldPosition({ -2, 2, 12});
271273
}
274+
#endif
272275

273276
// wine glasses
274277
#if ENABLE_TRANSPARENTS
@@ -343,13 +346,15 @@ struct Level : public RavEngine::World {
343346
};
344347

345348
auto smokeUpdateMat = New<ParticleUpdateMaterialInstance>(New<SmokeParticleUpdateMaterial>());
346-
349+
#if ENABLE_PARTICLES
350+
#if ENABLE_OPAQUES
347351
auto& smokeEmitter = smokeParticleEntity.EmplaceComponent<ParticleEmitter>(8192, sizeof(ParticleRenderData), smokeUpdateMat, smokeRenderMat); // number of particles we want
348352
//smokeEmitter.mode = ParticleEmitter::Mode::Burst;
349353
smokeEmitter.Play();
350354
smokeParticle = { smokeParticleEntity };
351355
smokeEmitter.SetEmissionRate(1000);
352356
smokeParticleEntity.EmplaceComponent<FlameTag>();
357+
#endif
353358
#if ENABLE_TRANSPARENTS
354359
auto fireParticleEntity = Instantiate<GameObject>();
355360
auto fireParticleRenderMat = New<FireParticleMaterial>();
@@ -378,18 +383,20 @@ struct Level : public RavEngine::World {
378383
asteroidEmitterEntity.GetTransform().LocalTranslateDelta({0,2,0});
379384
emitter.Play();
380385
emitter.SetEmissionRate(50);
386+
#endif
381387
#endif
382388

383389
SetupInputs();
384-
390+
#if ENABLE_PARTICLES
385391
constexpr auto MoveParticleSystem = [](const ParticleEmitter& emitter, const FlameTag& ft, Transform& t) {
386392
auto time = GetApp()->GetCurrentTime();
387393
t.SetLocalPosition({ std::sin(time) * 5, 0, 0 });
388394
};
389-
EmplaceSystem<decltype(MoveParticleSystem)>();
395+
EmplaceSystem<decltype(MoveParticleSystem)>();
396+
#endif
390397

391398
// create the scene
392-
399+
#if ENABLE_OPAQUES
393400
auto helmetObj = Instantiate<GameObject>();
394401
auto helmetMesh = New<MeshCollectionStatic>(MeshAsset::Manager::Get("helmet"));
395402
auto helmetMat = New<PBRMaterialInstance>(Material::Manager::Get<PBRMaterial>(),1);
@@ -429,6 +436,7 @@ struct Level : public RavEngine::World {
429436
renderTextureMatInst->SetAlbedoTexture(renderTexture->GetTexture());
430437
quadEntity.EmplaceComponent<StaticMesh>(MeshCollectionStaticManager::Get("quad"),renderTextureMatInst);
431438
quadEntity.GetTransform().SetWorldPosition({10,10,0}).SetWorldRotation(vector3{deg_to_rad(90),0,0}).SetLocalScale(5);
439+
#endif
432440
}
433441

434442

@@ -527,11 +535,15 @@ struct Level : public RavEngine::World {
527535

528536
void PreTick(float scale) final {
529537
fsScale = scale;
538+
#if ENABLE_OPAQUES
530539
starMaterialInstance->pushConstantData.applicationTime = GetApp()->GetCurrentTime();
540+
#endif
531541
}
532542

533543
void PostTick(float tickrateScale) final {
534-
camRoot.GetTransform().LocalTranslateDelta(velvec);
544+
if (glm::length(velvec) > 0.01){
545+
camRoot.GetTransform().LocalTranslateDelta(velvec);
546+
}
535547
velvec *= 0.9;
536548

537549
auto now = GetApp()->GetCurrentTime();

0 commit comments

Comments
 (0)