diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 024e3e9fd..a9c38f69d 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -5225,15 +5225,10 @@ void HWR_BuildSkyDome(void) // precompute to save a bit of division static constexpr float FINEDEGREE = (360.0f/static_cast(FINEANGLES)); -static void HWR_DrawSkyBackground(void) +static void HWR_DrawSkyDome(void) { FTransform dometransform; - if (HWR_IsWireframeMode()) - return; - - GL_SetBlend(PF_Translucent|PF_NoDepthTest|PF_Modulated); - memcpy(&dometransform, &atransform, sizeof(FTransform)); dometransform.x = dometransform.y = dometransform.z = 0.0; @@ -5258,6 +5253,131 @@ static void HWR_DrawSkyBackground(void) GL_RenderSkyDome(&gl_sky); } +// the following is karts old sky code from before the skydome stuff +// this appears to differ a bit from srb2´s old sky code +static void HWR_DrawSkyTexture(void) +{ + FOutVector v[4]; + angle_t angle; + float dimensionmultiply; + float aspectratio; + float angleturn; + + HWR_GetTexture(texturetranslation[skytexture], false); + + aspectratio = (float)vid.width/(float)vid.height; + + //Hurdler: the sky is the only texture who need 4.0f instead of 1.0 + // because it's called just after clearing the screen + // and thus, the near clipping plane is set to 3.99 + // Sryder: Just use the near clipping plane value then + + // 3--2 + // | /| + // |/ | + // 0--1 + v[0].x = v[3].x = -ZCLIP_PLANE-1; + v[1].x = v[2].x = ZCLIP_PLANE+1; + v[0].y = v[1].y = -ZCLIP_PLANE-1; + v[2].y = v[3].y = ZCLIP_PLANE+1; + + v[0].z = v[1].z = v[2].z = v[3].z = ZCLIP_PLANE+1; + + // X + + // NOTE: This doesn't work right with texture widths greater than 1024 + // software doesn't draw any further than 1024 for skies anyway, but this doesn't overlap properly + // The only time this will probably be an issue is when a sky wider than 1024 is used as a sky AND a regular wall texture + + //angle = (viewangle + ANGLE_45); + angle = (viewangle + xtoviewangle[0]); + dimensionmultiply = ((float)textures[texturetranslation[skytexture]]->width/256.0f); + + if (atransform.fliptype == TRANSFORM_MIRROR || + atransform.fliptype == TRANSFORM_MIRRORFLIP) + { + angle = InvAngle(angle); + dimensionmultiply *= -1; + } + + v[0].s = v[3].s = ((float)angle / ((float)(ANGLE_90-1)*dimensionmultiply)); + v[2].s = v[1].s = (-1.0f/dimensionmultiply)+((float) angle / ((float)(ANGLE_90-1)*dimensionmultiply)); + + // Y + angle = aimingangle; + dimensionmultiply = ((float)textures[texturetranslation[skytexture]]->height/(128.0f*aspectratio)); + + if (splitscreen == 1) + { + dimensionmultiply *= 2; + angle *= 2; + } + + // Middle of the sky should always be at angle 0 + // need to keep correct aspect ratio with X + if (atransform.fliptype == TRANSFORM_FLIP || + atransform.fliptype == TRANSFORM_MIRRORFLIP) + { + // During vertical flip the sky should be flipped and it's y movement should also be flipped obviously + v[3].t = v[2].t = -(0.5f-(0.5f/dimensionmultiply)); + v[0].t = v[1].t = (-1.0f/dimensionmultiply)-(0.5f-(0.5f/dimensionmultiply)); + } + else + { + v[3].t = v[2].t = (-1.0f/dimensionmultiply)-(0.5f-(0.5f/dimensionmultiply)); + v[0].t = v[1].t = -(0.5f-(0.5f/dimensionmultiply)); + } + + angleturn = (((float)ANGLE_45-1.0f)*aspectratio)*dimensionmultiply; + + if (cv_glshearing.value) + { + // Doesn't really make sense, but what can I do? + angle_t dy = FixedAngle(FixedMul(360*FRACUNIT, FixedDiv(AIMINGTODY(aimingangle), 900*FRACUNIT))); + v[3].t = v[2].t -= ((float) dy / angleturn); + v[0].t = v[1].t -= ((float) dy / angleturn); + } + else + { + if (angle > ANGLE_180) // Do this because we don't want the sky to suddenly teleport when crossing over 0 to 360 and vice versa + { + angle = InvAngle(angle); + v[3].t = v[2].t += ((float) angle / angleturn); + v[0].t = v[1].t += ((float) angle / angleturn); + } + else + { + v[3].t = v[2].t -= ((float) angle / angleturn); + v[0].t = v[1].t -= ((float) angle / angleturn); + } + } + + // since sky is drawn as a "flat quad" this way, we have to unset any view transformations for it to work + GL_SetTransform(NULL); + if (HWR_UseShader()) + { + GL_SetShader(HWR_GetShaderFromTarget(SHADER_SKY)); // not sure if this is needed? + GL_DrawPolygon(NULL, v, 4, 0); + GL_UnSetShader(); + } + else + { + GL_UnSetShader(); + GL_DrawPolygon(NULL, v, 4, 0); + } +} + +static void HWR_DrawSkyBackground(void) +{ + if (HWR_IsWireframeMode()) + return; + + if (cv_skydome.value) + HWR_DrawSkyDome(); + else + HWR_DrawSkyTexture(); +} + // -----------------+ // HWR_ClearView : clear the viewwindow, with maximum z value. also clears stencil buffer. // -----------------+ diff --git a/src/r_main.cpp b/src/r_main.cpp index 962ccc0a7..c4719e2e5 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -188,6 +188,7 @@ consvar_t cv_flipcammode = {"flipcammode", "Displayplayer", CV_SAVE, flipcammod consvar_t cv_shadow = {"shadow", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_shadowoffs = {"offsetshadows", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_skybox = {"skybox", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_skydome = {"skydome", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_ffloorclip = {"r_ffloorclip", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_spriteclip = {"r_spriteclip", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_softcyancut = {"softwarecyancut", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -1564,6 +1565,7 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_shadow); CV_RegisterVar(&cv_shadowoffs); CV_RegisterVar(&cv_skybox); + CV_RegisterVar(&cv_skydome); CV_RegisterVar(&cv_ffloorclip); CV_RegisterVar(&cv_spriteclip); CV_RegisterVar(&cv_secbright); diff --git a/src/r_main.h b/src/r_main.h index 7c5bc2a1f..2ac254f41 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -220,6 +220,7 @@ extern consvar_t cv_translucency; extern consvar_t cv_drawdist, cv_drawdist_precip, cv_lessprecip; extern consvar_t cv_fov, cv_fovchange; extern consvar_t cv_skybox; +extern consvar_t cv_skydome; extern consvar_t cv_tailspickup; extern consvar_t cv_maxinterpdist; extern consvar_t cv_playerfade; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 17585fef3..b93db91f8 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -791,6 +791,8 @@ static void R_DrawSkyPlane(visplane_t *pl, void(*skycolfunc)(drawcolumndata_t*), drawcolumndata_t dc = {}; angle_t viewang = pl->viewangle; + const boolean skydome = cv_skydome.value != 0; + // Reset column drawer function (note: couldn't we just call colfuncs[BASEDRAWFUNC] directly?) // (that is, unless we'll need to switch drawers in future for some reason) R_SetColumnFunc(BASEDRAWFUNC); @@ -888,8 +890,8 @@ static void R_DrawSkyPlane(visplane_t *pl, void(*skycolfunc)(drawcolumndata_t*), INT32 angle = (viewang + xtoviewangle[x + i])>>ANGLETOSKYSHIFT; angle -= (skytextureoffset >> FRACBITS); - - dc.iscale = FixedMul(skyscale, FINECOSINE(xtoviewangle[x + i]>>ANGLETOFINESHIFT)); + if (skydome) + dc.iscale = FixedMul(skyscale, FINECOSINE(xtoviewangle[x + i]>>ANGLETOFINESHIFT)); dc.x = x + i; dc.source = R_GetColumn(texture, -angle); // get negative of angle for each column to display sky correct way round! --Monster Iestyn 27/01/18 @@ -924,7 +926,8 @@ static void R_DrawSkyPlane(visplane_t *pl, void(*skycolfunc)(drawcolumndata_t*), INT32 angle = (viewang + xtoviewangle[x])>>ANGLETOSKYSHIFT; angle -= (skytextureoffset >> FRACBITS); - dc.iscale = FixedMul(skyscale, FINECOSINE(xtoviewangle[x]>>ANGLETOFINESHIFT)); + if (skydome) + dc.iscale = FixedMul(skyscale, FINECOSINE(xtoviewangle[x]>>ANGLETOFINESHIFT)); dc.x = x; dc.source = R_GetColumn(texturetranslation[skytexture], -angle); // get negative of angle for each column to display sky correct way round! --Monster Iestyn 27/01/18