Skip to content

Commit

Permalink
apply background properties to clubhouse menu
Browse files Browse the repository at this point in the history
  • Loading branch information
fallahn committed Nov 6, 2024
1 parent 679806f commit 86eb57a
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 13 deletions.
18 changes: 13 additions & 5 deletions samples/golf/src/golf/ClubhouseState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,12 @@ void ClubhouseState::loadResources()
static const std::string MapSizeString = "const vec2 MapSize = vec2(" + std::to_string(MapSize.x) + ".0, " + std::to_string(MapSize.y) + ".0); ";
m_resources.shaders.addInclude("MAP_SIZE", MapSizeString.c_str());

m_resources.shaders.loadFromString(ShaderID::Course, CelVertexShader, CelFragmentShader, "#define TEXTURED\n#define RX_SHADOWS\n");
m_resources.shaders.loadFromString(ShaderID::Course, CelVertexShader, CelFragmentShader, "#define BALL_COLOUR\n#define TEXTURED\n#define RX_SHADOWS\n");
auto* shader = &m_resources.shaders.get(ShaderID::Course);
m_scaleBuffer.addShader(*shader);
m_resolutionBuffer.addShader(*shader);
m_materialIDs[MaterialID::Cel] = m_resources.materials.add(*shader);
m_resources.materials.get(m_materialIDs[MaterialID::Cel]).setProperty("u_ballColour", cro::Colour::White);

m_resources.shaders.loadFromString(ShaderID::Leaderboard, CelVertexShader, CelFragmentShader, "#define VERTEX_COLOURED\n#define TEXTURED\n#define RX_SHADOWS\n");
shader = &m_resources.shaders.get(ShaderID::Leaderboard);
Expand All @@ -822,17 +823,18 @@ void ClubhouseState::loadResources()
m_resources.materials.get(m_materialIDs[MaterialID::Trophy]).setProperty("u_reflectMap", cro::CubemapID(m_reflectionMap.getGLHandle()));
}

m_resources.shaders.loadFromString(ShaderID::Billboard, BillboardVertexShader, BillboardFragmentShader);
m_resources.shaders.loadFromString(ShaderID::Billboard, BillboardVertexShader, BillboardFragmentShader, "#define SKY_COLOUR\n");
shader = &m_resources.shaders.get(ShaderID::Billboard);
m_materialIDs[MaterialID::Billboard] = m_resources.materials.add(*shader);
m_scaleBuffer.addShader(*shader);
m_resolutionBuffer.addShader(*shader);
m_windBuffer.addShader(*shader);

m_resources.shaders.loadFromString(ShaderID::CelTexturedSkinned, CelVertexShader, CelFragmentShader, "#define SUBRECT\n#define TEXTURED\n#define SKINNED\n");
m_resources.shaders.loadFromString(ShaderID::CelTexturedSkinned, CelVertexShader, CelFragmentShader, "#define BALL_COLOUR\n#define SUBRECT\n#define TEXTURED\n#define SKINNED\n");
shader = &m_resources.shaders.get(ShaderID::CelTexturedSkinned);
m_resolutionBuffer.addShader(*shader);
m_materialIDs[MaterialID::CelSkinned] = m_resources.materials.add(*shader);
m_resources.materials.get(m_materialIDs[MaterialID::CelSkinned]).setProperty("u_ballColour", cro::Colour::White);

//ball material in table preview
m_resources.shaders.loadFromString(ShaderID::CelTextured, CelVertexShader, CelFragmentShader, "#define REFLECTIONS\n#define TEXTURED\n#define SUBRECT\n");
Expand Down Expand Up @@ -959,8 +961,9 @@ void ClubhouseState::validateTables()

void ClubhouseState::buildScene()
{
m_backgroundScene.setCubemap("assets/golf/images/skybox/mountain_spring/sky.ccm");

//m_backgroundScene.setCubemap("assets/golf/images/skybox/mountain_spring/sky.ccm");
m_backgroundScene.enableSkybox();
m_backgroundScene.setSkyboxColours(SkyBottom, m_sharedData.skyColourBottom, m_sharedData.skyColourTop);

cro::ModelDefinition md(m_resources);

Expand All @@ -987,6 +990,7 @@ void ClubhouseState::buildScene()
md.createModel(entity);

applyMaterial(entity, MaterialID::Cel);
entity.getComponent<cro::Model>().setMaterialProperty(0, "u_ballColour", m_sharedData.sunColour);
}

if (md.loadFromFile("assets/golf/models/phone_box.cmt"))
Expand All @@ -997,6 +1001,7 @@ void ClubhouseState::buildScene()
md.createModel(entity);

applyMaterial(entity, MaterialID::Cel);
entity.getComponent<cro::Model>().setMaterialProperty(0, "u_ballColour", m_sharedData.sunColour);
}

if (md.loadFromFile("assets/golf/models/trophies/cabinet.cmt"))
Expand Down Expand Up @@ -1283,6 +1288,7 @@ void ClubhouseState::buildScene()
billboardMat.setProperty("u_noiseTexture", noiseTex);

entity.getComponent<cro::Model>().setMaterial(0, billboardMat);
entity.getComponent<cro::Model>().setMaterialProperty(0, "u_skyColour", m_sharedData.sunColour);

if (entity.hasComponent<cro::BillboardCollection>())
{
Expand Down Expand Up @@ -1342,6 +1348,7 @@ void ClubhouseState::buildScene()
}
applyMaterialData(passengerDef, material);
passengers[i].getComponent<cro::Model>().setMaterial(0, material);
passengers[i].getComponent<cro::Model>().setMaterialProperty(0, "u_ballColour", m_sharedData.sunColour);
}
}

Expand All @@ -1354,6 +1361,7 @@ void ClubhouseState::buildScene()
entity.addComponent<GolfCart>();
md.createModel(entity);
applyMaterial(entity, MaterialID::Cel);
entity.getComponent<cro::Model>().setMaterialProperty(0, "u_ballColour", m_sharedData.sunColour);

entity.addComponent<cro::AudioEmitter>() = m_menuSounds.getEmitter("cart");
entity.getComponent<cro::AudioEmitter>().play();
Expand Down
74 changes: 66 additions & 8 deletions samples/golf/src/golf/MenuState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,11 @@ void MenuState::handleMessage(const cro::Message& msg)
}
}
}
else if (data.type == SystemEvent::ShadowQualityChanged)
{
auto& cam = m_backgroundScene.getActiveCamera().getComponent<cro::Camera>();
cam.resizeCallback(cam);
}
}
#ifdef USE_GNS
else if (msg.id == Social::MessageID::UGCMessage)
Expand Down Expand Up @@ -1578,8 +1583,6 @@ void MenuState::addSystems()

void MenuState::loadAssets()
{
//m_backgroundScene.setCubemap("assets/golf/images/skybox/spring/sky.ccm");
//m_backgroundScene.setSkyboxColours(cro::Colour(0.2f, 0.31f, 0.612f, 1.f), cro::Colour(1.f, 0.973f, 0.882f, 1.f), cro::Colour(0.723f, 0.847f, 0.792f, 1.f));
if (m_reflectionMap.loadFromFile("assets/golf/images/skybox/billiards/trophy.ccm"))
{
m_reflectionMap.generateMipMaps();
Expand All @@ -1600,8 +1603,8 @@ void MenuState::loadAssets()

m_resources.shaders.loadFromString(ShaderID::Cel, CelVertexShader, CelFragmentShader, "#define VERTEX_COLOURED\n" + wobble);
m_resources.shaders.loadFromString(ShaderID::Ball, CelVertexShader, CelFragmentShader, "#define VERTEX_COLOURED\n#define BALL_COLOUR\n"/* + wobble*/); //this breaks rendering thumbs
m_resources.shaders.loadFromString(ShaderID::CelTextured, CelVertexShader, CelFragmentShader, "#define TEXTURED\n" + wobble);
m_resources.shaders.loadFromString(ShaderID::CelTexturedMasked, CelVertexShader, CelFragmentShader, "#define TEXTURED\n#define MASK_MAP\n" + wobble);
m_resources.shaders.loadFromString(ShaderID::CelTextured, CelVertexShader, CelFragmentShader, "#define RX_SHADOWS\n#define TEXTURED\n" + wobble);
m_resources.shaders.loadFromString(ShaderID::CelTexturedMasked, CelVertexShader, CelFragmentShader, "#define RX_SHADOWS\n#define TEXTURED\n#define MASK_MAP\n" + wobble);
m_resources.shaders.loadFromString(ShaderID::Course, CelVertexShader, CelFragmentShader, "#define TEXTURED\n#define RX_SHADOWS\n" + wobble);
m_resources.shaders.loadFromString(ShaderID::CelTexturedSkinned, CelVertexShader, CelFragmentShader, "#define SUBRECT\n#define TEXTURED\n#define SKINNED\n#define MASK_MAP\n");
//m_resources.shaders.loadFromString(ShaderID::CelTexturedSkinnedMasked, CelVertexShader, CelFragmentShader, "#define SUBRECT\n#define TEXTURED\n#define SKINNED\n#define MASK_MAP\n");
Expand Down Expand Up @@ -1775,7 +1778,7 @@ void MenuState::createScene()
cro::ModelDefinition md(m_resources);

//this might be loaded from the prop, if not we use this
glm::vec3 sunPos(-0.505335f, 0.62932f, 0.590418f);
glm::vec3 sunPos = glm::vec3(-0.505335f, 0.62932f, 0.590418f);
cro::Colour sunColour = cro::Colour::White;

cro::Colour skyTop = cro::Colour(0.723f, 0.847f, 0.792f, 1.f);
Expand All @@ -1785,7 +1788,56 @@ void MenuState::createScene()
m_backgroundScene.enableSkybox();

//load random / seasonal props
std::string propFilePath = "01.bgd"; //TODO select this based on some event/season or just at random
std::string propFilePath;

const bool spooky = cro::SysTime::now().months() == 10
&& cro::SysTime::now().days() > 22;

if (spooky)
{
propFilePath = "spooky.bgd";
}
else
{
const auto hour = cro::SysTime::now().hours();
switch (hour)
{
default:
case 21:
case 22:
case 23:
case 0:
case 1:
case 2:
case 3:
case 4:
propFilePath = "00.bgd";
break;
case 5:
propFilePath = "01.bgd";
break;
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
propFilePath = "02.bgd";
break;
case 20:
propFilePath = "03.bgd";
break;
}
}

cro::ConfigFile propFile;
if (propFile.loadFromFile("assets/golf/menu/" + propFilePath))
{
Expand Down Expand Up @@ -1888,7 +1940,11 @@ void MenuState::createScene()
auto sunEnt = m_backgroundScene.getSunlight();
sunEnt.getComponent<cro::Transform>().setLocalTransform(glm::inverse(glm::lookAt(sunPos, glm::vec3(0.f), cro::Transform::Y_AXIS)));
sunEnt.getComponent<cro::Sunlight>().setColour(sunColour);
m_sharedData.sunColour = sunColour;
m_sharedData.skyColourTop = skyTop;
m_sharedData.skyColourBottom = skyBottom;

//#define BUNS
#ifdef BUNS
registerWindow([&]()
{
Expand Down Expand Up @@ -2247,8 +2303,7 @@ void MenuState::createScene()

//music
auto entity = m_backgroundScene.createEntity();
if (cro::SysTime::now().months() == 10
&& cro::SysTime::now().days() > 22)
if (spooky)
{
entity.addComponent<cro::AudioEmitter>() = m_menuSounds.getEmitter("spooky_music");
}
Expand Down Expand Up @@ -2285,6 +2340,9 @@ void MenuState::createScene()
&& m_sharedData.multisamples != 0
&& !m_sharedData.pixelScale;

const auto res = m_sharedData.hqShadows ? 4096 : 2048;
cam.shadowMapBuffer.create(res, res);

cam.setPerspective(m_sharedData.fov * cro::Util::Const::degToRad, texSize.x / texSize.y, 0.1f, 600.f);
cam.viewport = { 0.f, 0.f, 1.f, 1.f };
};
Expand Down
5 changes: 5 additions & 0 deletions samples/golf/src/golf/SharedStateData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ enum class GameMode
struct SharedCourseData;
struct SharedStateData final
{
//used to set background colour in main menu and clubhouse
cro::Colour sunColour = cro::Colour::White;
cro::Colour skyColourTop = cro::Colour::White;
cro::Colour skyColourBottom = cro::Colour::White;

cro::Playlist playlist;

bool showCredits = false;
Expand Down
9 changes: 9 additions & 0 deletions samples/golf/src/golf/shaders/BillboardShader.inl
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ inline const std::string BillboardFragmentShader = R"(
uniform sampler2D u_diffuseMap;
uniform vec4 u_lightColour;
#if defined (SKY_COLOUR)
uniform vec4 u_skyColour = vec4(1.0);
#endif
#include SCALE_BUFFER
VARYING_IN LOW vec4 v_colour;
Expand All @@ -216,6 +220,11 @@ inline const std::string BillboardFragmentShader = R"(
FRAG_OUT *= TEXTURE(u_diffuseMap, v_texCoord0);
FRAG_OUT *= getLightColour();
#if defined(SKY_COLOUR)
FRAG_OUT *= u_skyColour;
#endif
//this probably undoes any usefulness of mipmapping
//FRAG_OUT.a = textureLod(u_diffuseMap, v_texCoord0, 0.0).a;
Expand Down

0 comments on commit 86eb57a

Please sign in to comment.