Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
madame-rachelle committed Jul 10, 2017
2 parents 15d92b3 + ddd1b62 commit e1b4bb1
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 71 deletions.
2 changes: 2 additions & 0 deletions src/gl/renderer/gl_renderer.h
Expand Up @@ -153,6 +153,8 @@ class FGLRenderer

float mSceneClearColor[3];

float mGlobVis = 0.0f;

FGLRenderer(OpenGLFrameBuffer *fb);
~FGLRenderer() ;

Expand Down
1 change: 1 addition & 0 deletions src/gl/renderer/gl_renderstate.cpp
Expand Up @@ -151,6 +151,7 @@ bool FRenderState::ApplyShader()
activeShader->muDesaturation.Set(mDesaturation / 255.f);
activeShader->muFogEnabled.Set(fogset);
activeShader->muPalLightLevels.Set(static_cast<int>(gl_bandedswlight) | (static_cast<int>(gl_fogmode) << 8));
activeShader->muGlobVis.Set(GLRenderer->mGlobVis / 32.0f);
activeShader->muTextureMode.Set(mTextureMode);
activeShader->muCameraPos.Set(mCameraPos.vec);
activeShader->muLightParms.Set(mLightParms);
Expand Down
4 changes: 3 additions & 1 deletion src/gl/scene/gl_scene.cpp
Expand Up @@ -83,7 +83,7 @@ CVAR(Bool, gl_sort_textures, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
EXTERN_CVAR (Bool, cl_capfps)
EXTERN_CVAR (Bool, r_deathcamera)
EXTERN_CVAR (Float, underwater_fade_scalar)

EXTERN_CVAR (Float, r_visibility)

extern bool NoInterpolateView;

Expand Down Expand Up @@ -785,6 +785,8 @@ sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, f
R_SetupFrame (r_viewpoint, r_viewwindow, camera);
SetViewArea();

GLRenderer->mGlobVis = R_GetGlobVis(r_viewwindow, r_visibility);

// We have to scale the pitch to account for the pixel stretching, because the playsim doesn't know about this and treats it as 1:1.
double radPitch = r_viewpoint.Angles.Pitch.Normalized180().Radians();
double angx = cos(radPitch);
Expand Down
1 change: 1 addition & 0 deletions src/gl/shaders/gl_shader.cpp
Expand Up @@ -230,6 +230,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
muDesaturation.Init(hShader, "uDesaturationFactor");
muFogEnabled.Init(hShader, "uFogEnabled");
muPalLightLevels.Init(hShader, "uPalLightLevels");
muGlobVis.Init(hShader, "uGlobVis");
muTextureMode.Init(hShader, "uTextureMode");
muCameraPos.Init(hShader, "uCameraPos");
muLightParms.Init(hShader, "uLightAttr");
Expand Down
1 change: 1 addition & 0 deletions src/gl/shaders/gl_shader.h
Expand Up @@ -260,6 +260,7 @@ class FShader
FBufferedUniform1f muDesaturation;
FBufferedUniform1i muFogEnabled;
FBufferedUniform1i muPalLightLevels;
FBufferedUniform1f muGlobVis;
FBufferedUniform1i muTextureMode;
FBufferedUniform4f muCameraPos;
FBufferedUniform4f muLightParms;
Expand Down
2 changes: 2 additions & 0 deletions src/polyrenderer/poly_renderer.cpp
Expand Up @@ -40,6 +40,7 @@

EXTERN_CVAR(Bool, r_shadercolormaps)
EXTERN_CVAR(Int, screenblocks)
EXTERN_CVAR(Float, r_visibility)
void InitGLRMapinfoData();

/////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -122,6 +123,7 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines)
if (APART(R_OldBlend)) NormalLight.Maps = realcolormaps.Maps;
else NormalLight.Maps = realcolormaps.Maps + NUMCOLORMAPS * 256 * R_OldBlend;

Light.SetVisibility(Viewwindow, r_visibility);

PolyCameraLight::Instance()->SetCamera(Viewpoint, RenderTarget, actor);
//Viewport->SetupFreelook();
Expand Down
10 changes: 5 additions & 5 deletions src/polyrenderer/scene/poly_light.cpp
Expand Up @@ -27,6 +27,11 @@
#include "poly_light.h"
#include "polyrenderer/poly_renderer.h"

void PolyLightVisibility::SetVisibility(FViewWindow &viewwindow, float vis)
{
GlobVis = R_GetGlobVis(viewwindow, vis);
}

fixed_t PolyLightVisibility::LightLevelToShade(int lightlevel, bool foggy)
{
bool nolightfade = !foggy && ((level.flags3 & LEVEL3_NOLIGHTFADE));
Expand All @@ -42,8 +47,3 @@ fixed_t PolyLightVisibility::LightLevelToShade(int lightlevel, bool foggy)
return (NUMCOLORMAPS * 2 * FRACUNIT) - ((lightlevel + 12) * (FRACUNIT*NUMCOLORMAPS / 128));
}
}

double PolyLightVisibility::FocalTangent()
{
return PolyRenderer::Instance()->Viewwindow.FocalTangent;
}
15 changes: 8 additions & 7 deletions src/polyrenderer/scene/poly_light.h
Expand Up @@ -24,16 +24,20 @@

#include "swrenderer/scene/r_light.h"

struct FViewWindow;

// Keep using the software renderer's camera light class, for now.
// The DFrameBuffer abstraction relies on this being globally shared
typedef swrenderer::CameraLight PolyCameraLight;

class PolyLightVisibility
{
public:
double WallGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0 : WallVisibility / FocalTangent(); }
double SpriteGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0 : WallVisibility / FocalTangent(); }
double ParticleGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0 : WallVisibility * 0.5 / FocalTangent(); }
void SetVisibility(FViewWindow &viewwindow, float vis);

double WallGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0 : GlobVis; }
double SpriteGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0 : GlobVis; }
double ParticleGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0 : GlobVis * 0.5; }

// The vis value to pass into the GETPALOOKUP or LIGHTSCALE macros
double WallVis(double screenZ, bool foggy) const { return WallGlobVis(foggy) / screenZ; }
Expand All @@ -43,9 +47,6 @@ class PolyLightVisibility
static fixed_t LightLevelToShade(int lightlevel, bool foggy);

private:
static double FocalTangent();

// 1706 is the value for walls on 1080p 16:9 displays.
double WallVisibility = 1706.0;
double GlobVis = 0.0f;
bool NoLightFade = false;
};
3 changes: 0 additions & 3 deletions src/r_renderer.h
Expand Up @@ -54,9 +54,6 @@ struct FRenderer
virtual void CleanLevelData() {}
virtual bool RequireGLNodes() { return false; }

virtual double GetVisibility() { return 8.f; }
virtual void SetVisibility(double vis) { }

};


Expand Down
71 changes: 71 additions & 0 deletions src/r_utility.cpp
Expand Up @@ -278,6 +278,77 @@ void R_ExecuteSetViewSize (FRenderViewpoint &viewpoint, FViewWindow &viewwindow)
viewwindowy = (viewwidth == screen->GetWidth()) ? 0 : (StatusBar->GetTopOfStatusbar() - viewheight) >> 1;
}

//==========================================================================
//
// r_visibility
//
// Controls how quickly light ramps across a 1/z range.
//
//==========================================================================

double R_ClampVisibility(double vis)
{
// Allow negative visibilities, just for novelty's sake
return clamp(vis, -204.7, 204.7); // (205 and larger do not work in 5:4 aspect ratio)
}

CUSTOM_CVAR(Float, r_visibility, 8.0f, CVAR_NOINITCALL)
{
if (netgame && self != 8.0f)
{
Printf("Visibility cannot be changed in net games.\n");
self = 8.0f;
}
else
{
float clampValue = (float)R_ClampVisibility(self);
if (self != clampValue)
self = clampValue;
}
}

//==========================================================================
//
// R_GetGlobVis
//
// Calculates the global visibility constant used by the software renderer
//
//==========================================================================

double R_GetGlobVis(const FViewWindow &viewwindow, double vis)
{
vis = R_ClampVisibility(vis);

double virtwidth = screen->GetWidth();
double virtheight = screen->GetHeight();

if (AspectTallerThanWide(viewwindow.WidescreenRatio))
{
virtheight = (virtheight * AspectMultiplier(viewwindow.WidescreenRatio)) / 48;
}
else
{
virtwidth = (virtwidth * AspectMultiplier(viewwindow.WidescreenRatio)) / 48;
}

double YaspectMul = 320.0 * virtheight / (200.0 * virtwidth);
double InvZtoScale = YaspectMul * viewwindow.centerx;

double wallVisibility = vis;

// Prevent overflow on walls
double maxVisForWall = (InvZtoScale * (screen->GetWidth() * r_Yaspect) / (viewwidth * screen->GetHeight() * viewwindow.FocalTangent));
maxVisForWall = 32767.0 / maxVisForWall;
if (vis < 0 && vis < -maxVisForWall)
wallVisibility = -maxVisForWall;
else if (vis > 0 && vis > maxVisForWall)
wallVisibility = maxVisForWall;

wallVisibility = InvZtoScale * screen->GetWidth() * AspectBaseHeight(viewwindow.WidescreenRatio) / (viewwidth * screen->GetHeight() * 3) * (wallVisibility * viewwindow.FocalTangent);

return wallVisibility / viewwindow.FocalTangent;
}

//==========================================================================
//
// CVAR screenblocks
Expand Down
2 changes: 2 additions & 0 deletions src/r_utility.h
Expand Up @@ -122,6 +122,8 @@ void R_ExecuteSetViewSize (FRenderViewpoint &viewpoint, FViewWindow &viewwindow)
void R_SetViewSize (int blocks);
void R_SetWindow (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, int windowSize, int fullWidth, int fullHeight, int stHeight, bool renderingToCanvas = false);

double R_GetGlobVis(const FViewWindow &viewwindow, double vis);
double R_ClampVisibility(double vis);

extern void R_FreePastViewers ();
extern void R_ClearPastViewer (AActor *actor);
Expand Down
18 changes: 6 additions & 12 deletions src/sound/musicformats/music_libsndfile.cpp
Expand Up @@ -339,18 +339,12 @@ bool SndFileSong::Read(SoundStream *stream, void *vbuff, int ilen, void *userdat
if (currentpos + framestoread > song->Loop_End)
{
size_t endblock = (song->Loop_End - currentpos) * song->Channels * 2;
size_t endlen = song->Decoder->read(buff, 0 == endblock ? len : endblock);
if (endlen != 0)
{
buff = buff + endlen;
len -= endlen;
song->Decoder->seek(song->Loop_Start, false, true);
}
else
{
song->CritSec.Leave();
return false;
}
size_t endlen = song->Decoder->read(buff, endblock);

// Even if zero bytes was read give it a chance to start from the beginning
buff = buff + endlen;
len -= endlen;
song->Decoder->seek(song->Loop_Start, false, true);
}
while (len > 0)
{
Expand Down
11 changes: 0 additions & 11 deletions src/swrenderer/r_swrenderer.cpp
Expand Up @@ -378,14 +378,3 @@ void FSoftwareRenderer::PreprocessLevel()
void FSoftwareRenderer::CleanLevelData()
{
}

double FSoftwareRenderer::GetVisibility()
{
return mScene.MainThread()->Light->GetVisibility();
}

void FSoftwareRenderer::SetVisibility(double vis)
{
mScene.MainThread()->Light->SetVisibility(mScene.MainThread()->Viewport.get(), vis);
}

3 changes: 0 additions & 3 deletions src/swrenderer/r_swrenderer.h
Expand Up @@ -35,9 +35,6 @@ struct FSoftwareRenderer : public FRenderer
void PreprocessLevel() override;
void CleanLevelData() override;

double GetVisibility() override;
void SetVisibility(double vis) override;

private:
void PrecacheTexture(FTexture *tex, int cache);

Expand Down
22 changes: 1 addition & 21 deletions src/swrenderer/scene/r_light.cpp
Expand Up @@ -104,8 +104,7 @@ namespace swrenderer
// Changes how rapidly things get dark with distance
void LightVisibility::SetVisibility(RenderViewport *viewport, double vis)
{
// Allow negative visibilities, just for novelty's sake
vis = clamp(vis, -204.7, 204.7); // (205 and larger do not work in 5:4 aspect ratio)
vis = R_ClampVisibility(vis);

CurrentVisibility = vis;

Expand Down Expand Up @@ -167,25 +166,6 @@ namespace swrenderer
}
}

// Controls how quickly light ramps across a 1/z range. Set this, and it
// sets all the r_*Visibility variables (except r_SkyVisibilily, which is
// currently unused).
CCMD(r_visibility)
{
if (argv.argc() < 2)
{
Printf("Visibility is %g\n", Renderer->GetVisibility());
}
else if (!netgame)
{
Renderer->SetVisibility(atof(argv[1]));
}
else
{
Printf("Visibility cannot be changed in net games.\n");
}
}

/////////////////////////////////////////////////////////////////////////

void ColormapLight::SetColormap(double visibility, int shade, FDynamicColormap *basecolormap, bool fullbright, bool invertColormap, bool fadeToBlack)
Expand Down
4 changes: 3 additions & 1 deletion src/swrenderer/viewport/r_viewport.cpp
Expand Up @@ -46,6 +46,8 @@

CVAR(String, r_viewsize, "", CVAR_NOSET)

EXTERN_CVAR(Float, r_visibility);

namespace swrenderer
{
RenderViewport::RenderViewport()
Expand Down Expand Up @@ -109,7 +111,7 @@ namespace swrenderer
InitTextureMapping();

// Reset r_*Visibility vars
thread->Light->SetVisibility(this, thread->Light->GetVisibility());
thread->Light->SetVisibility(this, r_visibility);

SetupBuffer();
}
Expand Down
6 changes: 6 additions & 0 deletions src/win32/hardware.cpp
Expand Up @@ -56,6 +56,7 @@ EXTERN_CVAR (Bool, vid_forceddraw)

CVAR(Int, win_x, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Int, win_y, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, win_maximized, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)

extern HWND Window;

Expand Down Expand Up @@ -382,6 +383,8 @@ void I_SaveWindowedPos ()
win_x = wrect.left;
win_y = wrect.top;
}

win_maximized = IsZoomed(Window) == TRUE;
}
}

Expand Down Expand Up @@ -409,6 +412,9 @@ void I_RestoreWindowedPos ()
KeepWindowOnScreen (winx, winy, winw, winh, scrwidth, scrheight);
}
MoveWindow (Window, winx, winy, winw, winh, TRUE);

if (win_maximized && !Args->CheckParm("-0"))
ShowWindow(Window, SW_MAXIMIZE);
}

extern int NewWidth, NewHeight, NewBits, DisplayBits;
Expand Down
8 changes: 1 addition & 7 deletions wadsrc/static/shaders/glsl/main.fp
Expand Up @@ -103,12 +103,6 @@ vec4 getTexel(vec2 st)
//===========================================================================
float R_DoomLightingEquation(float light)
{
// globVis = WallVisibility / r_viewwindow.FocalTangent / 32.0
//
// WallVisibility is calculated in LightVisibility::SetVisibility
// 1706 is the default value for WallVisibility on 1080p 16:9 displays.
float globVis = 1706.0 / 1.3333333333333333 / 32.0;

// L is the integer light level used in the game
float L = light * 255.0;

Expand All @@ -124,7 +118,7 @@ float R_DoomLightingEquation(float light)
}

// The zdoom light equation
float vis = min(globVis / z, 24.0 / 32.0);
float vis = min(uGlobVis / z, 24.0 / 32.0);
float shade = 2.0 - (L + 12.0) / 128.0;
float lightscale;
if ((uPalLightLevels & 0xff) != 0)
Expand Down
1 change: 1 addition & 0 deletions wadsrc/static/shaders/glsl/shaderdefs.i
Expand Up @@ -43,6 +43,7 @@ uniform vec4 uLightAttr;
#define uLightDist uLightAttr.r
uniform int uFogEnabled;
uniform int uPalLightLevels;
uniform float uGlobVis; // uGlobVis = R_GetGlobVis(r_visibility) / 32.0

// dynamic lights
uniform int uLightIndex;
Expand Down

0 comments on commit e1b4bb1

Please sign in to comment.