Fix skydome VB generation to cover entire range of phi (give sky pants).

Add shader code to fade out clouds to simulate old look at altitude.
meow-7.2.2
Graham Linden 2019-03-21 10:39:14 -07:00
parent edf8ba6e5f
commit 7423a86a1b
6 changed files with 31 additions and 9 deletions

View File

@ -51,6 +51,7 @@ VARYING vec2 vary_texcoord0;
VARYING vec2 vary_texcoord1;
VARYING vec2 vary_texcoord2;
VARYING vec2 vary_texcoord3;
VARYING float altitude_blend_factor;
/// Soft clips the light with a gamma correction
vec3 scaleSoftClip(vec3 light);
@ -102,10 +103,8 @@ void main()
alpha1 = 1. - alpha1 * alpha1;
alpha1 = 1. - alpha1 * alpha1;
if (alpha1 < 0.001f)
{
discard;
}
alpha1 *= altitude_blend_factor;
alpha1 = clamp(alpha1, 0.0, 1.0);
// Compute alpha2, for self shadowing effect
// (1 - alpha2) will later be used as percentage of incoming sunlight
@ -119,6 +118,7 @@ void main()
// Combine
vec4 color;
color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient);
color.rgb= max(vec3(0), color.rgb);
color *= 2.;
/// Gamma correct for WL (soft clip effect).

View File

@ -41,6 +41,7 @@ VARYING vec2 vary_texcoord0;
VARYING vec2 vary_texcoord1;
VARYING vec2 vary_texcoord2;
VARYING vec2 vary_texcoord3;
VARYING float altitude_blend_factor;
// Inputs
uniform vec3 camPosLocal;
@ -77,12 +78,15 @@ void main()
// Get relative position
vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0);
altitude_blend_factor = (P.y > -4096.0) ? 1.0 : 1.0 - clamp(abs(P.y) / max_y, 0.0, 1.0);
// Set altitude
if (P.y > 0.)
{
P *= (max_y / P.y);
}
else
if (P.y <= 0.0)
{
P *= (-32000. / P.y);
}
@ -122,7 +126,6 @@ void main()
// compiler gets confused.
temp1 = exp(-temp1 * temp2.z);
// Compute haze glow
temp2.x = dot(Pn, lightnorm.xyz);
temp2.x = 1. - temp2.x;

View File

@ -52,6 +52,7 @@ VARYING vec2 vary_texcoord0;
VARYING vec2 vary_texcoord1;
VARYING vec2 vary_texcoord2;
VARYING vec2 vary_texcoord3;
VARYING float altitude_blend_factor;
/// Soft clips the light with a gamma correction
vec3 scaleSoftClip(vec3 light);
@ -103,6 +104,8 @@ void main()
alpha1 = 1. - alpha1 * alpha1;
alpha1 = 1. - alpha1 * alpha1;
alpha1 *= altitude_blend_factor;
if (alpha1 < 0.001f)
{
discard;

View File

@ -40,6 +40,7 @@ VARYING vec2 vary_texcoord0;
VARYING vec2 vary_texcoord1;
VARYING vec2 vary_texcoord2;
VARYING vec2 vary_texcoord3;
VARYING float altitude_blend_factor;
// Inputs
uniform vec3 camPosLocal;
@ -76,6 +77,9 @@ void main()
// Get relative position
vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0);
// fade clouds beyond a certain point so the bottom of the sky dome doesn't look silly at high altitude
altitude_blend_factor = (P.y > -4096.0) ? 1.0 : 1.0 - clamp(abs(P.y) / max_y, 0.0, 1.0);
// Set altitude
if (P.y > 0.)
{
@ -86,6 +90,7 @@ void main()
P *= (-32000. / P.y);
}
// Can normalize then
vec3 Pn = normalize(P);
float Plen = length(P);

View File

@ -111,7 +111,7 @@ inline F32 LLVOWLSky::calcPhi(U32 i)
t = t*t;
t = 1.f - t;
return F_PI_BY_TWO * t;
return F_PI * t;
}
void LLVOWLSky::resetVertexBuffers()
@ -248,8 +248,11 @@ BOOL LLVOWLSky::updateGeometry(LLDrawable * drawable)
LL_ERRS() << "Failed updating WindLight sky geometry." << LL_ENDL;
}
U32 vertex_count = 0;
U32 index_count = 0;
// fill it
buildStripsBuffer(begin_stack, end_stack, vertices, texCoords, indices);
buildStripsBuffer(begin_stack, end_stack, vertex_count, index_count, vertices, texCoords, indices);
// and unlock the buffer
segment->flush();
@ -360,7 +363,10 @@ void LLVOWLSky::initStars()
}
}
void LLVOWLSky::buildStripsBuffer(U32 begin_stack, U32 end_stack,
void LLVOWLSky::buildStripsBuffer(U32 begin_stack,
U32 end_stack,
U32& vertex_count,
U32& index_count,
LLStrider<LLVector3> & vertices,
LLStrider<LLVector2> & texCoords,
LLStrider<U16> & indices)
@ -380,7 +386,7 @@ void LLVOWLSky::buildStripsBuffer(U32 begin_stack, U32 end_stack,
llassert(end_stack <= num_stacks);
// stacks are iterated one-indexed since phi(0) was handled by the fan above
for(i = begin_stack + 1; i <= end_stack+1; ++i)
for(i = begin_stack; i <= end_stack; ++i)
{
phi0 = calcPhi(i);
@ -434,6 +440,9 @@ void LLVOWLSky::buildStripsBuffer(U32 begin_stack, U32 end_stack,
*indices++ = i * num_slices + k ;
count_indices++ ;
}
vertex_count = count_verts;
index_count = count_indices;
}
void LLVOWLSky::updateStarColors()

View File

@ -66,6 +66,8 @@ private:
// begin_stack is the first stack to be included, end_stack is the first
// stack not to be included.
static void buildStripsBuffer(U32 begin_stack, U32 end_stack,
U32& vertex_count,
U32& index_count,
LLStrider<LLVector3> & vertices,
LLStrider<LLVector2> & texCoords,
LLStrider<U16> & indices);