Skip to content

Commit

Permalink
render noise on flight cam when out of bounds
Browse files Browse the repository at this point in the history
hide putting icons when displaying flight cam
  • Loading branch information
fallahn committed Sep 15, 2023
1 parent 234a53b commit fc6a17d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
4 changes: 2 additions & 2 deletions samples/golf/buildnumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifndef BUILD_NUMBER_H_
#define BUILD_NUMBER_H_

#define BUILDNUMBER 1763
#define BUILDNUMBER_STR "1763"
#define BUILDNUMBER 1769
#define BUILDNUMBER_STR "1769"

#endif /* BUILD_NUMBER_H_ */
48 changes: 31 additions & 17 deletions samples/golf/src/golf/GolfState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,9 @@ void GolfState::loadAssets()

//minimap - green overhead
m_resources.shaders.loadFromString(ShaderID::Minimap, MinimapVertex, MinimapFragment);
shader = &m_resources.shaders.get(ShaderID::Minimap);
m_scaleBuffer.addShader(*shader);
m_windBuffer.addShader(*shader);

//minimap - course view
m_resources.shaders.loadFromString(ShaderID::MinimapView, MinimapViewVertex, MinimapViewFragment);
Expand Down Expand Up @@ -5120,29 +5123,40 @@ void GolfState::spawnBall(const ActorInfo& info)
return;
}

if (m_currentPlayer.terrain == TerrainID::Green)
if (m_miniGreenEnt.getComponent<cro::Sprite>().getTexture() &&
m_miniGreenEnt.getComponent<cro::Sprite>().getTexture()->getGLHandle() ==
m_flightTexture.getTexture().getGLHandle())
{
//hide
e.getComponent<cro::Drawable2D>().setFacing(cro::Drawable2D::Facing::Back);
}
else
{
auto pos = ballEnt.getComponent<cro::Transform>().getWorldPosition();
auto iconPos = m_greenCam.getComponent<cro::Camera>().coordsToPixel(pos, m_greenBuffer.getSize());
e.getComponent<cro::Drawable2D>().setFacing(cro::Drawable2D::Facing::Front);
if (m_currentPlayer.terrain == TerrainID::Green)
{
auto pos = ballEnt.getComponent<cro::Transform>().getWorldPosition();
auto iconPos = m_greenCam.getComponent<cro::Camera>().coordsToPixel(pos, m_greenBuffer.getSize());

const glm::vec2 Centre = glm::vec2(m_greenBuffer.getSize() / 2u);
const glm::vec2 Centre = glm::vec2(m_greenBuffer.getSize() / 2u);

iconPos -= Centre;
iconPos *= std::min(1.f, Centre.x / glm::length(iconPos));
iconPos += Centre;
iconPos -= Centre;
iconPos *= std::min(1.f, Centre.x / glm::length(iconPos));
iconPos += Centre;

auto terrain = ballEnt.getComponent<ClientCollider>().terrain;
float scale = terrain == TerrainID::Green ? m_viewScale.x / m_miniGreenEnt.getComponent<cro::Transform>().getScale().x : 0.f;
auto terrain = ballEnt.getComponent<ClientCollider>().terrain;
float scale = terrain == TerrainID::Green ? m_viewScale.x / m_miniGreenEnt.getComponent<cro::Transform>().getScale().x : 0.f;

e.getComponent<cro::Transform>().setScale(glm::vec2(scale));
e.getComponent<cro::Transform>().setScale(glm::vec2(scale));

e.getComponent<cro::Transform>().setPosition(glm::vec3(iconPos, static_cast<float>(depthOffset) / 100.f));

const auto activePlayer = ((m_currentPlayer.client * ConstVal::MaxPlayers) + m_currentPlayer.player) + 1;
if (m_inputParser.getActive()
&& activePlayer == depthOffset)
{
m_miniGreenIndicatorEnt.getComponent<cro::Transform>().setPosition(glm::vec3(iconPos, 0.05f));
e.getComponent<cro::Transform>().setPosition(glm::vec3(iconPos, static_cast<float>(depthOffset) / 100.f));

const auto activePlayer = ((m_currentPlayer.client * ConstVal::MaxPlayers) + m_currentPlayer.player) + 1;
if (m_inputParser.getActive()
&& activePlayer == depthOffset)
{
m_miniGreenIndicatorEnt.getComponent<cro::Transform>().setPosition(glm::vec3(iconPos, 0.05f));
}
}
}
};
Expand Down
13 changes: 12 additions & 1 deletion samples/golf/src/golf/MinimapShader.inl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ static const std::string MinimapVertex = R"(

//minimap as in top down view of green
static const std::string MinimapFragment = R"(
uniform sampler2D u_texture;
#include WIND_BUFFER
#include SCALE_BUFFER
VARYING_IN LOW vec4 v_colour;
VARYING_IN MED vec2 v_texCoord;
OUTPUT
Expand All @@ -66,15 +70,22 @@ static const std::string MinimapFragment = R"(
const float res = 100.0;
const float scale = 2.0;
float rand(vec2 position)
{
return fract(sin(dot(position, vec2(12.9898, 4.1414)) + u_windData.w) * 43758.5453);
}
void main()
{
vec2 pos = (round(floor(v_texCoord * res) * scale) / scale) / res;
vec2 dir = pos - vec2(0.5);
float length2 = dot(dir,dir);
FRAG_OUT = TEXTURE(u_texture, v_texCoord) * v_colour;
vec3 noise = vec3(rand(floor((v_texCoord * textureSize(u_texture, 0)) / u_pixelScale)));
FRAG_OUT = TEXTURE(u_texture, v_texCoord);// * v_colour;
FRAG_OUT.rgb = mix(noise, FRAG_OUT.rgb, v_colour.r);
FRAG_OUT = mix(FRAG_OUT, borderColour, step(borderPos, length2));
FRAG_OUT.a *= 1.0 - step(stepPos, length2);
})";
Expand Down

0 comments on commit fc6a17d

Please sign in to comment.