Skip to content

Commit

Permalink
set up projection map for lighting
Browse files Browse the repository at this point in the history
  • Loading branch information
fallahn committed Nov 13, 2024
1 parent 87dd330 commit c34fad0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
21 changes: 16 additions & 5 deletions samples/golf/src/golf/MenuState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,7 @@ void MenuState::loadAssets()
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 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::Course, CelVertexShader, CelFragmentShader, "#define MENU_PROJ\n#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");
m_resources.shaders.loadFromString(ShaderID::Hair, CelVertexShader, CelFragmentShader, "#define USER_COLOUR\n");
Expand Down Expand Up @@ -1660,11 +1660,16 @@ void MenuState::loadAssets()
m_resources.materials.get(m_materialIDs[MaterialID::CelTexturedMasked]).setProperty("u_reflectMap", cro::CubemapID(m_reflectionMap));


auto proj = glm::ortho(-20.f, 20.f, -14.f, 0.f, 0.1f, 10.f);
auto view = glm::translate(glm::mat4(1.f), glm::vec3(0.f, 2.f, 0.f));
view *= glm::toMat4(glm::rotate(cro::Transform::QUAT_IDENTITY, -cro::Util::Const::PI / 2.f, cro::Transform::X_AXIS));
proj *= view;

shader = &m_resources.shaders.get(ShaderID::Course);
m_scaleBuffer.addShader(*shader);
m_resolutionBuffer.addShader(*shader);
m_materialIDs[MaterialID::Ground] = m_resources.materials.add(*shader);

m_resources.materials.get(m_materialIDs[MaterialID::Ground]).setProperty("u_menuViewProjectionMatrix", proj);

cro::Image defaultMask;
defaultMask.create(2, 2, cro::Colour::Black);
Expand Down Expand Up @@ -2426,11 +2431,11 @@ void MenuState::createScene()
MenuState::PropFileData MenuState::getPropPath() const
{
PropFileData ret;
/*ret.timeOfDay = TimeOfDay::Night;
ret.propFilePath = "somer.bgd";
ret.timeOfDay = TimeOfDay::Night;
ret.propFilePath = "midori.bgd";

m_sharedData.menuSky = Skies[ret.timeOfDay];
return ret;*/
return ret;

const auto mon = cro::SysTime::now().months();
const auto day = cro::SysTime::now().days();
Expand Down Expand Up @@ -2658,6 +2663,12 @@ void MenuState::createRopes(std::int32_t timeOfDay, const std::vector<glm::vec3>
md.createModel(entity);
entity.getComponent<cro::Model>().setMaterial(0, lightMaterial);
entity.getComponent<cro::Model>().setMaterialProperty(0, "u_ballColour", LightColours[cro::Util::Random::value(0u, LightColours.size() - 1)]);

if (timeOfDay != TimeOfDay::Night)
{
entity.addComponent<cro::ShadowCaster>();
entity.getComponent<cro::Model>().setShadowMaterial(0, m_resources.materials.get(shadowMatID));
}
}
}
createRopeMesh(polePos[i], rope);
Expand Down
24 changes: 23 additions & 1 deletion samples/golf/src/golf/shaders/CelShader.inl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ inline const std::string CelVertexShader = R"(
VARYING_OUT vec4 v_targetProjection;
#endif
#if defined (MENU_PROJ)
//TODO make this a constant
uniform mat4 u_menuViewProjectionMatrix;
VARYING_OUT vec4 v_menuProjection;
#endif
//dirX, strength, dirZ, elapsedTime
#include WIND_BUFFER
Expand Down Expand Up @@ -242,6 +248,9 @@ inline const std::string CelVertexShader = R"(
#if defined(MULTI_TARGET)
v_targetProjection = u_targetViewProjectionMatrix * u_worldMatrix * a_position;
#endif
#if defined (MENU_PROJ)
v_menuProjection = u_menuViewProjectionMatrix * u_worldMatrix * a_position;
#endif
#if defined(TERRAIN_CLIP)
gl_ClipDistance[1] = dot(worldPosition, vec4(vec3(0.0, 1.0, 0.0), WaterLevel - 0.001));
#endif
Expand Down Expand Up @@ -339,7 +348,10 @@ inline const std::string CelFragmentShader = R"(
#if defined(MULTI_TARGET)
VARYING_IN vec4 v_targetProjection;
#endif
#if defined(MENU_PROJ)
VARYING_IN vec4 v_menuProjection;
#endif
#define USE_MRT
#include OUTPUT_LOCATION
Expand Down Expand Up @@ -704,6 +716,16 @@ inline const std::string CelFragmentShader = R"(
NORM_OUT.a = 1.0 - (0.9 * targetAmount);
FRAG_OUT.rgb = mix(FRAG_OUT.rgb, targetColour + FRAG_OUT.rgb, targetAmount);
#endif
#if defined(MENU_PROJ)
vec2 projUV = v_menuProjection.xy/v_menuProjection.w;
projUV = projUV * 0.5 + 0.5;
FRAG_OUT.r *= step(0.001, projUV.x);
FRAG_OUT.r *= 1.0 - step(0.999, projUV.x);
FRAG_OUT.r *= step(0.001, projUV.y);
//FRAG_OUT.r *= 1.0 - step(0.999, projUV.y);
#endif
//FRAG_OUT += vec4(1.0, 0.0, 0.0, 1.0);
})";

0 comments on commit c34fad0

Please sign in to comment.