mirror of
https://github.com/RetroDECK/Supermodel.git
synced 2024-11-25 23:25:40 +00:00
Amend the ambient fog logic to be disabled if fog density/start is set to zero. This fixes a regression where the sky stops drawing in lost world.
Rewrite the scroll fog shader slightly. Scroll fog is a 2d layer, it has no depth, or can be considered to be drawn at infinity, therefore is not effected by the viewport light. The scroll attenatuion value also I think attenatutes the scroll fog alpha value. This fixes various effects in emergency call ambulance.
This commit is contained in:
parent
a214c6dae8
commit
c5f9a3ad26
|
@ -207,7 +207,7 @@ void CNew3D::DrawScrollFog()
|
|||
rgba[2] = vp.fogParams[2];
|
||||
rgba[3] = vp.scrollFog;
|
||||
glViewport(vp.x, vp.y, vp.width, vp.height);
|
||||
m_r3dScrollFog.DrawScrollFog(rgba, vp.scrollAtt, vp.fogParams[6], vp.spotFogColor, vp.spotEllipse);
|
||||
m_r3dScrollFog.DrawScrollFog(rgba, vp.scrollAtt, vp.fogParams[6]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -223,22 +223,29 @@ void CNew3D::DrawAmbientFog()
|
|||
// Does this work with scroll fog? Well technically scroll fog already takes into account the fog ambient as it darkens the fog colour
|
||||
|
||||
// Let's pick the lowest fog ambient value
|
||||
// Check for fog density or a fog start value, otherwise the effect seems to be disabled (lost world)
|
||||
|
||||
float fogAmbient = 1.0f;
|
||||
Node* nodePtr = nullptr;
|
||||
|
||||
for (auto& n : m_nodes) {
|
||||
|
||||
// check to see if we have a fog density or fog start
|
||||
if (n.viewport.fogParams[3] <= 0.0f && n.viewport.fogParams[4] <= 0.0f) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (n.viewport.fogParams[6] < fogAmbient) {
|
||||
nodePtr = &n;
|
||||
fogAmbient = n.viewport.fogParams[6];
|
||||
}
|
||||
}
|
||||
|
||||
if (fogAmbient < 1.0f) {
|
||||
if (nodePtr) {
|
||||
auto& vp = nodePtr->viewport;
|
||||
float rgba[] = { 0.0f, 0.0f, 0.0f, 1.0f - fogAmbient };
|
||||
glViewport(vp.x, vp.y, vp.width, vp.height);
|
||||
m_r3dScrollFog.DrawScrollFog(rgba, vp.scrollAtt, vp.fogParams[6], vp.spotFogColor, vp.spotEllipse);
|
||||
m_r3dScrollFog.DrawScrollFog(rgba, 0.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,18 +26,6 @@ static const char *fragmentShaderFog = R"glsl(
|
|||
uniform float fogAttenuation;
|
||||
uniform float fogAmbient;
|
||||
uniform vec4 fogColour;
|
||||
uniform vec3 spotFogColor;
|
||||
uniform vec4 spotEllipse;
|
||||
|
||||
// Spotlight on fog
|
||||
float ellipse;
|
||||
vec2 position, size;
|
||||
vec3 lSpotFogColor;
|
||||
|
||||
// Scroll fog
|
||||
float lfogAttenuation;
|
||||
vec3 lFogColor;
|
||||
vec4 scrollFog;
|
||||
|
||||
// outputs
|
||||
layout(location = 0) out vec4 out0; // opaque
|
||||
|
@ -56,21 +44,10 @@ void WriteOutputs(vec4 colour)
|
|||
void main()
|
||||
{
|
||||
// Scroll fog base color
|
||||
lFogColor = fogColour.rgb * fogAmbient;
|
||||
|
||||
// Spotlight on fog (area)
|
||||
position = spotEllipse.xy;
|
||||
size = spotEllipse.zw;
|
||||
ellipse = length((gl_FragCoord.xy - position) / size);
|
||||
ellipse = ellipse * ellipse; // decay rate = square of distance from center
|
||||
ellipse = 1.0 - ellipse; // invert
|
||||
ellipse = max(0.0, ellipse); // clamp
|
||||
|
||||
// Spotlight on fog (color)
|
||||
lSpotFogColor = mix(spotFogColor * ellipse * fogColour.rgb, vec3(0.0), fogAttenuation);
|
||||
vec3 lFogColor = fogColour.rgb * fogAmbient;
|
||||
|
||||
// Scroll fog density
|
||||
scrollFog = vec4(lFogColor + lSpotFogColor, fogColour.a);
|
||||
vec4 scrollFog = vec4(lFogColor, fogColour.a * (1.0 - fogAttenuation));
|
||||
|
||||
// Final Color
|
||||
WriteOutputs(scrollFog);
|
||||
|
@ -105,7 +82,7 @@ R3DScrollFog::~R3DScrollFog()
|
|||
}
|
||||
}
|
||||
|
||||
void R3DScrollFog::DrawScrollFog(float rgba[4], float attenuation, float ambient, float *spotRGB, float *spotEllipse)
|
||||
void R3DScrollFog::DrawScrollFog(float rgba[4], float attenuation, float ambient)
|
||||
{
|
||||
// some ogl states
|
||||
glDepthMask (GL_FALSE); // disable z writes
|
||||
|
@ -116,8 +93,6 @@ void R3DScrollFog::DrawScrollFog(float rgba[4], float attenuation, float ambient
|
|||
glUniform4fv (m_locFogColour, 1, rgba);
|
||||
glUniform1f (m_locFogAttenuation, attenuation);
|
||||
glUniform1f (m_locFogAmbient, ambient);
|
||||
glUniform3fv (m_locSpotFogColor, 1, spotRGB);
|
||||
glUniform4fv (m_locSpotEllipse, 1, spotEllipse);
|
||||
|
||||
glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
|
@ -135,8 +110,6 @@ void R3DScrollFog::AllocResources()
|
|||
m_locFogColour = glGetUniformLocation(m_shaderProgram, "fogColour");
|
||||
m_locFogAttenuation = glGetUniformLocation(m_shaderProgram, "fogAttenuation");
|
||||
m_locFogAmbient = glGetUniformLocation(m_shaderProgram, "fogAmbient");
|
||||
m_locSpotFogColor = glGetUniformLocation(m_shaderProgram, "spotFogColor");
|
||||
m_locSpotEllipse = glGetUniformLocation(m_shaderProgram, "spotEllipse");
|
||||
}
|
||||
|
||||
void R3DScrollFog::DeallocResources()
|
||||
|
|
|
@ -13,7 +13,7 @@ public:
|
|||
R3DScrollFog(const Util::Config::Node &config);
|
||||
~R3DScrollFog();
|
||||
|
||||
void DrawScrollFog(float rbga[4], float attenuation, float ambient, float *spotRGB, float *spotEllipse);
|
||||
void DrawScrollFog(float rbga[4], float attenuation, float ambient);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -29,8 +29,6 @@ private:
|
|||
GLint m_locFogColour;
|
||||
GLint m_locFogAttenuation;
|
||||
GLint m_locFogAmbient;
|
||||
GLint m_locSpotFogColor;
|
||||
GLint m_locSpotEllipse;
|
||||
|
||||
GLuint m_vao;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue