Remove hardcoded SkyBox sizes and use the infinity sky. No we render

the skybox at the current camera location, so that the skybox appears
indefinitely far away. Refs #3458.

Reviewed By: wraitii
Tested By: elexis, Stan
Differential Revision: https://code.wildfiregames.com/D1683
This was SVN commit r22039.
This commit is contained in:
Vladislav Belov 2019-01-06 21:55:30 +00:00
parent 14a7147540
commit 9376609ee8
3 changed files with 37 additions and 46 deletions

View File

@ -290,16 +290,8 @@ void main()
if (refTex.a < 0.99)
{
// Calculate where we intersect with the skycube.
Ray myRay = Ray(vec3(worldPos.x/4.0,worldPos.y,worldPos.z/4.0),eye);
vec3 start = vec3(-1500.0 + mapSize/2.0,-100.0,-1500.0 + mapSize/2.0);
vec3 end = vec3(1500.0 + mapSize/2.0,500.0,1500.0 + mapSize/2.0);
float tmin = IntersectBox(myRay,start,end);
vec4 newpos = vec4(-worldPos.x/4.0,worldPos.y,-worldPos.z/4.0,1.0) + vec4(eye * tmin,0.0) - vec4(-mapSize/2.0,worldPos.y,-mapSize/2.0,0.0);
newpos *= skyBoxRot;
newpos.y *= 4.0;
// Interpolate between the sky color and nearby objects.
reflColor = mix(textureCube(skyCube, newpos.rgb).rgb, refTex.rgb, refTex.a);
reflColor = mix(textureCube(skyCube, (vec4(eye, 0.0) * skyBoxRot).xyz).rgb, refTex.rgb, refTex.a);
}
// reflMod is used to reduce the intensity of sky reflections, which otherwise are too extreme.

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2018 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -204,7 +204,7 @@ void SkyManager::RenderSky()
if (m_SkySet.empty())
return;
glDepthMask( GL_FALSE );
glDepthMask(GL_FALSE);
pglActiveTextureARB(GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
@ -212,18 +212,16 @@ void SkyManager::RenderSky()
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
// Translate so we are at the center of the map.
ssize_t mapSize = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide();
glTranslatef(mapSize*(TERRAIN_TILE_SIZE/2.0f), m_HorizonHeight, mapSize*(TERRAIN_TILE_SIZE/2.0f) );
// Translate so the sky center is at the camera space origin.
CVector3D cameraPos = g_Renderer.GetViewCamera().GetOrientation().GetTranslation();
glTranslatef(cameraPos.X, cameraPos.Y, cameraPos.Z);
// Rotate so that the "left" face, which contains the brightest part of each
// skymap, is in the direction of the sun from our light environment
glRotatef( 180.0f /*+ 45.0f*/ + RADTODEG(g_Renderer.GetLightEnv().GetRotation()), 0.0f, 1.0f, 0.0f );
glRotatef(180.0f + RADTODEG(g_Renderer.GetLightEnv().GetRotation()), 0.0f, 1.0f, 0.0f);
// Distance to draw the faces at
const float D = 1500.0f; // distance from map center
const float H = 500.0f; // height of the ceiling
const float FH = -100.0f; // height of the "floor"
// Currently we have a hardcoded near plane in the projection matrix.
glScalef(10.0f, 10.0f, 10.0f);
CShaderProgramPtr shader;
CShaderTechniquePtr skytech;
@ -245,40 +243,41 @@ void SkyManager::RenderSky()
glBegin(GL_QUADS);
// GL_TEXTURE_CUBE_MAP_NEGATIVE_X
glTexCoord3f( +1, +1, +1 ); glVertex3f( -D, FH, -D );
glTexCoord3f( +1, +1, -1 ); glVertex3f( -D, FH, +D );
glTexCoord3f( +1, -1, -1 ); glVertex3f( -D, +H, +D );
glTexCoord3f( +1, -1, +1 ); glVertex3f( -D, +H, -D );
glTexCoord3f(+1, +1, +1); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord3f(+1, +1, -1); glVertex3f(-1.0f, -1.0f, +1.0f);
glTexCoord3f(+1, -1, -1); glVertex3f(-1.0f, +1.0f, +1.0f);
glTexCoord3f(+1, -1, +1); glVertex3f(-1.0f, +1.0f, -1.0f);
// GL_TEXTURE_CUBE_MAP_POSITIVE_X
glTexCoord3f( -1, +1, -1 ); glVertex3f( +D, FH, +D );
glTexCoord3f( -1, +1, +1 ); glVertex3f( +D, FH, -D );
glTexCoord3f( -1, -1, +1 ); glVertex3f( +D, +H, -D );
glTexCoord3f( -1, -1, -1 ); glVertex3f( +D, +H, +D );
glTexCoord3f(-1, +1, -1); glVertex3f(+1.0f, -1.0f, +1.0f);
glTexCoord3f(-1, +1, +1); glVertex3f(+1.0f, -1.0f, -1.0f);
glTexCoord3f(-1, -1, +1); glVertex3f(+1.0f, +1.0f, -1.0f);
glTexCoord3f(-1, -1, -1); glVertex3f(+1.0f, +1.0f, +1.0f);
// GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
glTexCoord3f( -1, +1, +1 ); glVertex3f( +D, FH, -D );
glTexCoord3f( -1, +1, -1 ); glVertex3f( +D, FH, +D );
glTexCoord3f( +1, +1, -1 ); glVertex3f( -D, FH, +D );
glTexCoord3f( +1, +1, +1 ); glVertex3f( -D, FH, -D );
glTexCoord3f(-1, +1, +1); glVertex3f(+1.0f, -1.0f, -1.0f);
glTexCoord3f(-1, +1, -1); glVertex3f(+1.0f, -1.0f, +1.0f);
glTexCoord3f(+1, +1, -1); glVertex3f(-1.0f, -1.0f, +1.0f);
glTexCoord3f(+1, +1, +1); glVertex3f(-1.0f, -1.0f, -1.0f);
// GL_TEXTURE_CUBE_MAP_POSITIVE_Y
glTexCoord3f( +1, -1, +1 ); glVertex3f( -D, +H, -D );
glTexCoord3f( +1, -1, -1 ); glVertex3f( -D, +H, +D );
glTexCoord3f( -1, -1, -1 ); glVertex3f( +D, +H, +D );
glTexCoord3f( -1, -1, +1 ); glVertex3f( +D, +H, -D );
glTexCoord3f(+1, -1, +1); glVertex3f(-1.0f, +1.0f, -1.0f);
glTexCoord3f(+1, -1, -1); glVertex3f(-1.0f, +1.0f, +1.0f);
glTexCoord3f(-1, -1, -1); glVertex3f(+1.0f, +1.0f, +1.0f);
glTexCoord3f(-1, -1, +1); glVertex3f(+1.0f, +1.0f, -1.0f);
// GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
glTexCoord3f( -1, +1, +1 ); glVertex3f( +D, FH, -D );
glTexCoord3f( +1, +1, +1 ); glVertex3f( -D, FH, -D );
glTexCoord3f( +1, -1, +1 ); glVertex3f( -D, +H, -D );
glTexCoord3f( -1, -1, +1 ); glVertex3f( +D, +H, -D );
glTexCoord3f(-1, +1, +1); glVertex3f(+1.0f, -1.0f, -1.0f);
glTexCoord3f(+1, +1, +1); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord3f(+1, -1, +1); glVertex3f(-1.0f, +1.0f, -1.0f);
glTexCoord3f(-1, -1, +1); glVertex3f(+1.0f, +1.0f, -1.0f);
// GL_TEXTURE_CUBE_MAP_POSITIVE_Z
glTexCoord3f( +1, +1, -1 ); glVertex3f( -D, FH, +D );
glTexCoord3f( -1, +1, -1 ); glVertex3f( +D, FH, +D );
glTexCoord3f( -1, -1, -1 ); glVertex3f( +D, +H, +D );
glTexCoord3f( +1, -1, -1 ); glVertex3f( -D, +H, +D );
glTexCoord3f(+1, +1, -1); glVertex3f(-1.0f, -1.0f, +1.0f);
glTexCoord3f(-1, +1, -1); glVertex3f(+1.0f, -1.0f, +1.0f);
glTexCoord3f(-1, -1, -1); glVertex3f(+1.0f, +1.0f, +1.0f);
glTexCoord3f(+1, -1, -1); glVertex3f(-1.0f, +1.0f, +1.0f);
glEnd();
if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
@ -294,7 +293,7 @@ void SkyManager::RenderSky()
glPopMatrix();
glDepthMask( GL_TRUE );
glDepthMask(GL_TRUE);
#endif
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2013 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -772,7 +772,7 @@ bool TerrainRenderer::RenderFancyWater(const CShaderDefines& context, int cullGr
// TODO: check that this rotates in the right direction.
CMatrix3D skyBoxRotation;
skyBoxRotation.SetIdentity();
skyBoxRotation.RotateY(M_PI - 0.3f + lightEnv.GetRotation());
skyBoxRotation.RotateY(M_PI + lightEnv.GetRotation());
m->fancyWaterShader->Uniform(str_skyBoxRot, skyBoxRotation);
}
m->fancyWaterShader->Uniform(str_sunDir, lightEnv.GetSunDir());