Merge viewer-eep

master
Ansariel 2019-03-31 10:59:37 +02:00
commit cc577bfa39
44 changed files with 964 additions and 768 deletions

View File

@ -485,6 +485,9 @@ Geenz Spad
STORM-1900
STORM-1905
NORSPEC-229
BUG-226611
BUG-226617
BUG-226618
Gene Frostbite
GeneJ Composer
Geneko Nemeth

View File

@ -859,11 +859,15 @@ LLSettingsDay::CycleTrack_t::value_type LLSettingsDay::getSettingsNearKeyframe(c
if (startframe < 0.0f)
startframe = 1.0f + startframe;
CycleTrack_t::iterator it = get_wrapping_atafter(const_cast<CycleTrack_t &>(mDayTracks[track]), startframe);
LLSettingsDay::CycleTrack_t collection = const_cast<CycleTrack_t &>(mDayTracks[track]);
CycleTrack_t::iterator it = get_wrapping_atafter(collection, startframe);
F32 dist = get_wrapping_distance(startframe, (*it).first);
if (dist <= (fudge * 2.0f))
CycleTrack_t::iterator next_it = std::next(it);
if ((dist <= DEFAULT_MULTISLIDER_INCREMENT) && next_it != collection.end())
return (*next_it);
else if (dist <= (fudge * 2.0f))
return (*it);
return CycleTrack_t::value_type(TrackPosition(INVALID_TRACKPOS), LLSettingsBase::ptr_t());

View File

@ -1281,7 +1281,7 @@ void LLSettingsSky::calculateLightSettings() const
// and vary_sunlight will work properly with moon light
F32 lighty = lightnorm[1];
if(fabs(lighty) > 0.001f)
if(lighty > 0.001f)
{
lighty = 1.f / lighty;
}
@ -1295,8 +1295,15 @@ void LLSettingsSky::calculateLightSettings() const
mSunDiffuse = gammaCorrect(componentMult(sunlight, light_transmittance));
mSunAmbient = gammaCorrect(componentMult(tmpAmbient, light_transmittance) * 0.5);
mMoonDiffuse = gammaCorrect(componentMult(LLColor3::white, light_transmittance) * 0.5f);
mMoonAmbient = gammaCorrect(componentMult(LLColor3::white, light_transmittance) * 0.25f);
F32 moon_brightness = getMoonBrightness();
LLColor3 moonlight_a(0.66, 0.66, 0.66);
LLColor3 moonlight_b(0.66, 0.66, 1.0);
LLColor3 moonlight = lerp(moonlight_b, moonlight_a, moon_brightness);
mMoonDiffuse = gammaCorrect(componentMult(moonlight, light_transmittance) * moon_brightness * 0.25f);
mMoonAmbient = gammaCorrect(componentMult(moonlight_b, light_transmittance) * 0.0125f);
mTotalAmbient = mSunAmbient;
}

View File

@ -537,6 +537,26 @@ inline void ll_remove_outliers(std::vector<VEC_TYPE>& data, F32 k)
}
}
// This converts from a non-linear sRGB floating point value (0..1) to a linear value.
// Useful for gamma correction and such. Note: any values passed through this should not be serialized. You should also ideally cache the output of this.
inline float sRGBtoLinear(const float val) {
if (val < 0.0031308f) {
return val * 12.92f;
}
else {
return 1.055f * pow(val, 1.0f / 2.4f) - 0.055f;
}
}
inline float linearTosRGB(const float val) {
if (val < 0.04045f) {
return val / 12.92f;
}
else {
return pow((val + 0.055f) / 1.055f, 2.4f);
}
}
// Include simd math header
#include "llsimdmath.h"

View File

@ -477,5 +477,13 @@ inline LLColor3 lerp(const LLColor3 &a, const LLColor3 &b, F32 u)
a.mV[VZ] + (b.mV[VZ] - a.mV[VZ]) * u);
}
inline const LLColor3 srgbColor3(const LLColor3 &a) {
LLColor3 srgbColor;
srgbColor.mV[0] = linearTosRGB(a.mV[0]);
srgbColor.mV[1] = linearTosRGB(a.mV[1]);
srgbColor.mV[2] = linearTosRGB(a.mV[2]);
return srgbColor;
}
#endif

View File

@ -659,5 +659,16 @@ void LLColor4::clamp()
}
}
inline const LLColor4 srgbColor4(const LLColor4 &a) {
LLColor4 srgbColor;
srgbColor.mV[0] = linearTosRGB(a.mV[0]);
srgbColor.mV[1] = linearTosRGB(a.mV[1]);
srgbColor.mV[2] = linearTosRGB(a.mV[2]);
srgbColor.mV[3] = a.mV[3];
return srgbColor;
}
#endif

View File

@ -534,6 +534,18 @@ inline F32 LLVector4::normVec(void)
return (mag);
}
// Because apparently some parts of the viewer use this for color info.
inline const LLVector4 srgbVector4(const LLVector4 &a) {
LLVector4 srgbColor;
srgbColor.mV[0] = linearTosRGB(a.mV[0]);
srgbColor.mV[1] = linearTosRGB(a.mV[1]);
srgbColor.mV[2] = linearTosRGB(a.mV[2]);
srgbColor.mV[3] = a.mV[3];
return srgbColor;
}
#endif

View File

@ -141,6 +141,7 @@ class LLLightParams : public LLNetworkData
{
protected:
LLColor4 mColor; // alpha = intensity
LLColor4 mSRGBColor; // Only used in deferred (for now?)
F32 mRadius;
F32 mFalloff;
F32 mCutoff;
@ -157,13 +158,14 @@ public:
operator LLSD() const { return asLLSD(); }
bool fromLLSD(LLSD& sd);
void setColor(const LLColor4& color) { mColor = color; mColor.clamp(); }
void setColor(const LLColor4& color) { mColor = color; mColor.clamp(); mSRGBColor = srgbColor4(mColor); }
void setRadius(F32 radius) { mRadius = llclamp(radius, LIGHT_MIN_RADIUS, LIGHT_MAX_RADIUS); }
void setFalloff(F32 falloff) { mFalloff = llclamp(falloff, LIGHT_MIN_FALLOFF, LIGHT_MAX_FALLOFF); }
void setCutoff(F32 cutoff) { mCutoff = llclamp(cutoff, LIGHT_MIN_CUTOFF, LIGHT_MAX_CUTOFF); }
LLColor4 getColor() const { return mColor; }
LLColor4 getColor() const { return mColor; }
LLColor4 getSRGBColor() const { return mSRGBColor; }
F32 getRadius() const { return mRadius; }
F32 getFalloff() const { return mFalloff; }
F32 getCutoff() const { return mCutoff; }

View File

@ -43,20 +43,13 @@
const F32 epsilon = 1e-7f;
const U16 RESOLUTION = 64;
#if LL_DARWIN
// mipmap generation on cubemap textures seems to be broken on the Mac for at least some cards.
// Since the cubemap is small (64x64 per face) and doesn't have any fine detail, turning off mipmaps is a usable workaround.
const BOOL use_cube_mipmaps = FALSE;
#else
const BOOL use_cube_mipmaps = FALSE; //current build works best without cube mipmaps
#endif
bool LLCubeMap::sUseCubeMaps = true;
LLCubeMap::LLCubeMap()
LLCubeMap::LLCubeMap(bool init_as_srgb)
: mTextureStage(0),
mTextureCoordStage(0),
mMatrixStage(0)
mMatrixStage(0),
mIssRGB(init_as_srgb)
{
mTargets[0] = GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB;
mTargets[1] = GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB;
@ -82,12 +75,15 @@ void LLCubeMap::initGL()
U32 texname = 0;
LLImageGL::generateTextures(1, &texname);
for (int i = 0; i < 6; i++)
{
mImages[i] = new LLImageGL(64, 64, 4, (use_cube_mipmaps? TRUE : FALSE));
mImages[i] = new LLImageGL(RESOLUTION, RESOLUTION, 4, FALSE);
if (mIssRGB) {
mImages[i]->setExplicitFormat(GL_SRGB8_ALPHA8, GL_RGBA);
}
mImages[i]->setTarget(mTargets[i], LLTexUnit::TT_CUBE_MAP);
mRawImages[i] = new LLImageRaw(64, 64, 4);
mRawImages[i] = new LLImageRaw(RESOLUTION, RESOLUTION, 4);
mImages[i]->createGLTexture(0, mRawImages[i], texname);
gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_CUBE_MAP, texname);
@ -154,7 +150,7 @@ void LLCubeMap::initGLData()
{
for (int i = 0; i < 6; i++)
{
mImages[i]->setSubImage(mRawImages[i], 0, 0, 64, 64);
mImages[i]->setSubImage(mRawImages[i], 0, 0, RESOLUTION, RESOLUTION);
}
}
@ -484,7 +480,7 @@ void LLCubeMap::paintIn(LLVector3 dir[4], const LLColor4U& col)
td[offset + cc] = U8((td[offset + cc] + col.mV[cc]) * 0.5);
}
}
mImages[side]->setSubImage(mRawImages[side], 0, 0, 64, 64);
mImages[side]->setSubImage(mRawImages[side], 0, 0, RESOLUTION, RESOLUTION);
}
}

View File

@ -36,8 +36,9 @@ class LLVector3;
// Environment map hack!
class LLCubeMap : public LLRefCount
{
bool mIssRGB;
public:
LLCubeMap();
LLCubeMap(bool init_as_srgb);
void init(const std::vector<LLPointer<LLImageRaw> >& rawimages);
void initGL();
void initRawData(const std::vector<LLPointer<LLImageRaw> >& rawimages);

View File

@ -189,34 +189,47 @@ void LLImageGL::cleanupClass()
//static
S32 LLImageGL::dataFormatBits(S32 dataformat)
{
switch (dataformat)
{
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: return 4;
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: return 8;
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: return 8;
case GL_LUMINANCE: return 8;
case GL_ALPHA: return 8;
case GL_COLOR_INDEX: return 8;
case GL_LUMINANCE_ALPHA: return 16;
case GL_RGB: return 24;
case GL_RGB8: return 24;
case GL_RGBA: return 32;
case GL_BGRA: return 32; // Used for QuickTime media textures on the Mac
default:
LL_ERRS() << "LLImageGL::Unknown format: " << dataformat << LL_ENDL;
return 0;
}
switch (dataformat)
{
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: return 4;
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: return 4;
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: return 8;
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: return 8;
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: return 8;
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: return 8;
case GL_LUMINANCE: return 8;
case GL_ALPHA: return 8;
case GL_COLOR_INDEX: return 8;
case GL_LUMINANCE_ALPHA: return 16;
case GL_RGB: return 24;
case GL_SRGB: return 24;
case GL_RGB8: return 24;
case GL_RGBA: return 32;
case GL_SRGB_ALPHA: return 32;
case GL_BGRA: return 32; // Used for QuickTime media textures on the Mac
default:
LL_ERRS() << "LLImageGL::Unknown format: " << dataformat << LL_ENDL;
return 0;
}
}
//static
S32 LLImageGL::dataFormatBytes(S32 dataformat, S32 width, S32 height)
{
if (dataformat >= GL_COMPRESSED_RGB_S3TC_DXT1_EXT &&
dataformat <= GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
{
if (width < 4) width = 4;
if (height < 4) height = 4;
}
switch (dataformat)
{
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
if (width < 4) width = 4;
if (height < 4) height = 4;
break;
default:
break;
}
S32 bytes ((width*height*dataFormatBits(dataformat)+7)>>3);
S32 aligned = (bytes+3)&~3;
return aligned;
@ -228,14 +241,19 @@ S32 LLImageGL::dataFormatComponents(S32 dataformat)
switch (dataformat)
{
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: return 3;
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: return 3;
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: return 4;
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: return 4;
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: return 4;
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: return 4;
case GL_LUMINANCE: return 1;
case GL_ALPHA: return 1;
case GL_COLOR_INDEX: return 1;
case GL_LUMINANCE_ALPHA: return 2;
case GL_RGB: return 3;
case GL_SRGB: return 3;
case GL_RGBA: return 4;
case GL_SRGB_ALPHA: return 4;
case GL_BGRA: return 4; // Used for QuickTime media textures on the Mac
default:
LL_ERRS() << "LLImageGL::Unknown format: " << dataformat << LL_ENDL;
@ -658,10 +676,20 @@ BOOL LLImageGL::setImage(const U8* data_in, BOOL data_hasmips)
{
LL_RECORD_BLOCK_TIME(FTM_SET_IMAGE);
bool is_compressed = false;
if (mFormatPrimary >= GL_COMPRESSED_RGBA_S3TC_DXT1_EXT && mFormatPrimary <= GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
{
is_compressed = true;
}
switch (mFormatPrimary)
{
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
is_compressed = true;
break;
default:
break;
}
@ -1235,10 +1263,18 @@ void LLImageGL::setManualImage(U32 target, S32 miplevel, S32 intformat, S32 widt
case GL_RGB8:
intformat = GL_COMPRESSED_RGB;
break;
case GL_SRGB:
case GL_SRGB8:
intformat = GL_COMPRESSED_SRGB;
break;
case GL_RGBA:
case GL_RGBA8:
intformat = GL_COMPRESSED_RGBA;
break;
case GL_SRGB_ALPHA:
case GL_SRGB8_ALPHA8:
intformat = GL_COMPRESSED_SRGB_ALPHA;
break;
case GL_LUMINANCE:
case GL_LUMINANCE8:
intformat = GL_COMPRESSED_LUMINANCE;
@ -1796,28 +1832,30 @@ void LLImageGL::calcAlphaChannelOffsetAndStride()
}
mAlphaStride = -1 ;
switch (mFormatPrimary)
{
case GL_LUMINANCE:
case GL_ALPHA:
mAlphaStride = 1;
break;
case GL_LUMINANCE_ALPHA:
mAlphaStride = 2;
break;
case GL_RGB:
mNeedsAlphaAndPickMask = FALSE ;
mIsMask = FALSE;
return ; //no alpha channel.
case GL_RGBA:
mAlphaStride = 4;
break;
case GL_BGRA_EXT:
mAlphaStride = 4;
break;
default:
break;
}
switch (mFormatPrimary)
{
case GL_LUMINANCE:
case GL_ALPHA:
mAlphaStride = 1;
break;
case GL_LUMINANCE_ALPHA:
mAlphaStride = 2;
break;
case GL_RGB:
case GL_SRGB:
mNeedsAlphaAndPickMask = FALSE;
mIsMask = FALSE;
return; //no alpha channel.
case GL_RGBA:
case GL_SRGB_ALPHA:
mAlphaStride = 4;
break;
case GL_BGRA_EXT:
mAlphaStride = 4;
break;
default:
break;
}
mAlphaOffset = -1 ;
if (mFormatType == GL_UNSIGNED_BYTE)
@ -2000,12 +2038,13 @@ void LLImageGL::updatePickMask(S32 width, S32 height, const U8* data_in)
freePickMask();
if (mFormatType != GL_UNSIGNED_BYTE ||
mFormatPrimary != GL_RGBA)
{
//cannot generate a pick mask for this texture
return;
}
if (mFormatType != GL_UNSIGNED_BYTE ||
mFormatPrimary != GL_RGBA ||
mFormatPrimary != GL_SRGB_ALPHA)
{
//cannot generate a pick mask for this texture
return;
}
#ifdef SHOW_ASSERT
const U32 pickSize = createPickMask(width, height);

View File

@ -853,9 +853,12 @@ LLLightState::LLLightState(S32 index)
if (mIndex == 0)
{
mDiffuse.set(1,1,1,1);
mDiffuseB.set(0,0,0,0);
mSpecular.set(1,1,1,1);
}
mSunIsPrimary = true;
mAmbient.set(0,0,0,1);
mPosition.set(0,0,1,0);
mSpotDirection.set(0,0,-1);
@ -907,6 +910,15 @@ void LLLightState::setDiffuseB(const LLColor4& diffuse)
}
}
void LLLightState::setSunPrimary(bool v)
{
if (mSunIsPrimary != v)
{
++gGL.mLightHash;
mSunIsPrimary = v;
}
}
void LLLightState::setAmbient(const LLColor4& ambient)
{
if (mAmbient != ambient)
@ -1192,7 +1204,8 @@ void LLRender::syncLightState()
LLVector3 direction[8];
LLVector4 attenuation[8];
LLVector3 diffuse[8];
LLVector3 diffuseB[8];
LLVector3 diffuse_b[8];
bool sun_primary[8];
for (U32 i = 0; i < 8; i++)
{
@ -1202,7 +1215,8 @@ void LLRender::syncLightState()
direction[i] = light->mSpotDirection;
attenuation[i].set(light->mLinearAtten, light->mQuadraticAtten, light->mSpecular.mV[2], light->mSpecular.mV[3]);
diffuse[i].set(light->mDiffuse.mV);
diffuseB[i].set(light->mDiffuseB.mV);
diffuse_b[i].set(light->mDiffuseB.mV);
sun_primary[i] = light->mSunIsPrimary;
}
shader->uniform4fv(LLShaderMgr::LIGHT_POSITION, 8, position[0].mV);
@ -1210,6 +1224,8 @@ void LLRender::syncLightState()
shader->uniform4fv(LLShaderMgr::LIGHT_ATTENUATION, 8, attenuation[0].mV);
shader->uniform3fv(LLShaderMgr::LIGHT_DIFFUSE, 8, diffuse[0].mV);
shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, mAmbientLightColor.mV);
shader->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_primary[0] ? 1 : 0);
shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, diffuse_b[0].mV);
}
}

View File

@ -249,6 +249,7 @@ public:
void setSpotExponent(const F32& exponent);
void setSpotCutoff(const F32& cutoff);
void setSpotDirection(const LLVector3& direction);
void setSunPrimary(bool v);
protected:
friend class LLRender;
@ -257,6 +258,7 @@ protected:
bool mEnabled;
LLColor4 mDiffuse;
LLColor4 mDiffuseB;
bool mSunIsPrimary;
LLColor4 mAmbient;
LLColor4 mSpecular;
LLVector4 mPosition;

View File

@ -96,6 +96,8 @@ LLLineEditor::Params::Params()
ignore_tab("ignore_tab", true),
is_password("is_password", false),
cursor_color("cursor_color"),
use_bg_color("use_bg_color", false),
bg_color("bg_color"),
text_color("text_color"),
text_readonly_color("text_readonly_color"),
text_tentative_color("text_tentative_color"),
@ -150,10 +152,12 @@ LLLineEditor::LLLineEditor(const LLLineEditor::Params& p)
mBgImageDisabled( p.background_image_disabled ),
mBgImageFocused( p.background_image_focused ),
mShowImageFocused( p.bg_image_always_focused ),
mUseBgColor(p.use_bg_color),
mHaveHistory(FALSE),
mReplaceNewlinesWithSpaces( TRUE ),
mLabel(p.label),
mCursorColor(p.cursor_color()),
mBgColor(p.bg_color()),
mFgColor(p.text_color()),
mReadOnlyFgColor(p.text_readonly_color()),
mTentativeFgColor(p.text_tentative_color()),
@ -1777,37 +1781,42 @@ void LLLineEditor::doDelete()
void LLLineEditor::drawBackground()
{
bool has_focus = hasFocus();
LLUIImage* image;
if ( mReadOnly )
F32 alpha = getCurrentTransparency();
if (mUseBgColor)
{
image = mBgImageDisabled;
}
else if ( has_focus || mShowImageFocused)
{
image = mBgImageFocused;
gl_rect_2d(getLocalRect(), mBgColor % alpha, TRUE);
}
else
{
image = mBgImage;
}
bool has_focus = hasFocus();
LLUIImage* image;
if (mReadOnly)
{
image = mBgImageDisabled;
}
else if (has_focus || mShowImageFocused)
{
image = mBgImageFocused;
}
else
{
image = mBgImage;
}
if (!image) return;
F32 alpha = getCurrentTransparency();
// optionally draw programmatic border
if (has_focus)
{
LLColor4 tmp_color = gFocusMgr.getFocusColor();
if (!image) return;
// optionally draw programmatic border
if (has_focus)
{
LLColor4 tmp_color = gFocusMgr.getFocusColor();
tmp_color.setAlpha(alpha);
image->drawBorder(0, 0, getRect().getWidth(), getRect().getHeight(),
tmp_color,
gFocusMgr.getFocusFlashWidth());
}
LLColor4 tmp_color = UI_VERTEX_COLOR;
tmp_color.setAlpha(alpha);
image->drawBorder(0, 0, getRect().getWidth(), getRect().getHeight(),
tmp_color,
gFocusMgr.getFocusFlashWidth());
image->draw(getLocalRect(), tmp_color);
}
LLColor4 tmp_color = UI_VERTEX_COLOR;
tmp_color.setAlpha(alpha);
image->draw(getLocalRect(), tmp_color);
}
void LLLineEditor::draw()

View File

@ -91,10 +91,12 @@ public:
commit_on_focus_lost,
ignore_tab,
bg_image_always_focused,
is_password;
is_password,
use_bg_color;
// colors
Optional<LLUIColor> cursor_color,
bg_color,
text_color,
text_readonly_color,
text_tentative_color,
@ -382,6 +384,7 @@ protected:
LLTimer mTripleClickTimer;
LLUIColor mCursorColor;
LLUIColor mBgColor;
LLUIColor mFgColor;
LLUIColor mReadOnlyFgColor;
LLUIColor mTentativeFgColor;
@ -402,6 +405,8 @@ protected:
BOOL mShowImageFocused;
bool mUseBgColor;
LLWString mPreeditWString;
LLWString mPreeditOverwrittenWString;
std::vector<S32> mPreeditPositions;

View File

@ -11291,7 +11291,7 @@ Change of this parameter will affect the layout of buttons in notification toast
<key>Type</key>
<string>Boolean</string>
<key>Value</key>
<integer>0</integer>
<integer>1</integer>
</map>
<key>RenderAnisotropic</key>
<map>

View File

@ -100,12 +100,14 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec
vec3 norm = normalize(n);
da = max(0.0, dot(norm, lv));
//da = min(da, shadow);
da = clamp(da, 0.0, 1.0);
//distance attenuation
float dist = d/la;
float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0);
dist_atten *= dist_atten;
dist_atten *= 2.0f;
// spotlight coefficient.
float spot = max(dot(-ln, lv), is_pointlight);
@ -113,12 +115,16 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec
// to match spotLight (but not multiSpotLight) *sigh*
float lit = max(da * dist_atten,0.0);
// the shadowmap is wrong for alpha objects
// since we only have 2 maps but N spots
//col = lit * light_col * diffuse * shadow;
col = lit * light_col * diffuse;
float amb_da = ambiance;
amb_da += (da*0.5) * (1.0 - shadow) * ambiance;
amb_da += (da*da*0.5 + 0.5) * (1.0 - shadow) * ambiance;
amb_da *= dist_atten;
amb_da += (da*0.5) * ambiance;
amb_da += (da*da*0.5 + 0.25) * ambiance;
amb_da = min(amb_da, 1.0f - lit);
col.rgb += amb_da * light_col * diffuse;
@ -189,6 +195,7 @@ void main()
vec3 light_dir = (sun_up_factor == 1) ? sun_dir: moon_dir;
float da = dot(norm.xyz, light_dir.xyz);
da = clamp(da, 0.0, 1.0);
da = pow(da, 1.0 / 1.3);
vec4 color = vec4(0,0,0,0);

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

@ -104,23 +104,28 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe
float dist = d/la;
float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0);
dist_atten *= dist_atten;
dist_atten *= 2.0f;
// spotlight coefficient.
float spot = max(dot(-ln, lv), is_pointlight);
da *= spot*spot; // GL_SPOT_EXPONENT=2
//angular attenuation
da = dot(n, lv);
//da = min(da, shadow);
da *= clamp(da, 0.0, 1.0);
float lit = max(da * dist_atten, 0.0);
// shadowmap is wrong for alpha-blended objs
// since we created shadowmaps for 2 but render N
//col = light_col*lit*diffuse*shadow;
col = light_col*lit*diffuse;
float amb_da = ambiance;
amb_da += (da*0.5) * (1.0 - shadow) * ambiance;
amb_da += (da*da*0.5 + 0.5) * (1.0 - shadow) * ambiance;
amb_da *= dist_atten;
amb_da += (da*0.5) * ambiance;
amb_da += (da*da*0.5 + 0.25) * ambiance;
amb_da = min(amb_da, 1.0f - lit);
col.rgb += amb_da * light_col * diffuse;
@ -142,6 +147,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe
{
float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da);
vec3 speccol = lit*scol*light_col.rgb*spec.rgb;
speccol = max(speccol, vec3(0));
col += speccol;
float cur_glare = max(speccol.r, speccol.g);

View File

@ -52,7 +52,7 @@ void main()
// mix factor which blends when sunlight is brighter
// and shows true moon color at night
vec3 luma_weights = vec3(0.2, 0.3, 0.2);
vec3 luma_weights = vec3(0.3, 0.5, 0.3);
float mix = 1.0 - dot(normalize(sunlight_color.rgb), luma_weights);

View File

@ -29,12 +29,17 @@ ATTRIBUTE vec3 position;
uniform vec2 screen_res;
void setAtmosAttenuation(vec3 c);
void setAdditiveColor(vec3 c);
VARYING vec2 vary_fragcoord;
void main()
{
//transform vertex
vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
gl_Position = pos;
vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;
//transform vertex
vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
gl_Position = pos;
// appease OSX GLSL compiler/linker by touching all the varyings we said we would
setAtmosAttenuation(vec3(1));
setAdditiveColor(vec3(0));
vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;
}

View File

@ -28,7 +28,7 @@
float calcDirectionalLight(vec3 n, vec3 l)
{
float a = max(dot(n,l),0.0);
float a = max(dot(n,normalize(l)),0.0);
return a;
}
@ -52,7 +52,7 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa
da *= spot*spot; // GL_SPOT_EXPONENT=2
//angular attenuation
da *= calcDirectionalLight(n, -lv);
da *= calcDirectionalLight(n, lv);
return da;
}

View File

@ -38,12 +38,10 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight)
col.a = color.a;
col.rgb = light_diffuse[1].rgb * calcDirectionalLight(norm, light_position[1].xyz);
col.rgb += light_diffuse[0].rgb * calcDirectionalLight(norm, light_position[0].xyz);
col.rgb = scaleDownLight(col.rgb);
col.rgb += atmosAmbient(baseLight.rgb);
col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz));
col.rgb = min(col.rgb*color.rgb, 1.0);
return col;
}

View File

@ -52,7 +52,7 @@ void main()
// mix factor which blends when sunlight is brighter
// and shows true moon color at night
vec3 luma_weights = vec3(0.2, 0.3, 0.2);
vec3 luma_weights = vec3(0.3, 0.5, 0.3);
float mix = 1.0f - dot(normalize(sunlight_color.rgb), luma_weights);
vec3 exp = vec3(1.0 - mix * moon_brightness) * 2.0 - 1.0;

View File

@ -77,225 +77,223 @@ vec3 getNorm(vec2 pos_screen);
vec4 correctWithGamma(vec4 col)
{
return vec4(srgb_to_linear(col.rgb), col.a);
return vec4(srgb_to_linear(col.rgb), col.a);
}
vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)
{
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret = correctWithGamma(ret);
vec2 dist = vec2(0.5) - abs(tc-vec2(0.5));
float det = min(lod/(proj_lod*0.5), 1.0);
float d = min(dist.x, dist.y);
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret = correctWithGamma(ret);
vec2 dist = vec2(0.5) - abs(tc-vec2(0.5));
float det = min(lod/(proj_lod*0.5), 1.0);
float d = min(dist.x, dist.y);
d *= min(1, d * (proj_lod - lod));
float edge = 0.25*det;
ret *= clamp(d/edge, 0.0, 1.0);
return ret;
float edge = 0.25*det;
ret *= clamp(d/edge, 0.0, 1.0);
return ret;
}
vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod)
{
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret = correctWithGamma(ret);
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret = correctWithGamma(ret);
vec2 dist = vec2(0.5) - abs(tc-vec2(0.5));
float det = min(lod/(proj_lod*0.5), 1.0);
float d = min(dist.x, dist.y);
float edge = 0.25*det;
ret *= clamp(d/edge, 0.0, 1.0);
return ret;
vec2 dist = vec2(0.5) - abs(tc-vec2(0.5));
float det = min(lod/(proj_lod*0.5), 1.0);
float d = min(dist.x, dist.y);
float edge = 0.25*det;
ret *= clamp(d/edge, 0.0, 1.0);
return ret;
}
vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod)
{
vec4 ret = texture2DLod(projectionMap, tc, lod);
vec4 ret = texture2DLod(projectionMap, tc, lod);
vec2 dist = tc-vec2(0.5);
float d = dot(dist,dist);
ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0);
return ret;
vec2 dist = tc-vec2(0.5);
float d = dot(dist,dist);
ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0);
return ret;
}
vec4 getPosition(vec2 pos_screen);
void main()
{
vec4 frag = vary_fragcoord;
frag.xyz /= frag.w;
frag.xyz = frag.xyz*0.5+0.5;
frag.xy *= screen_res;
vec3 pos = getPosition(frag.xy).xyz;
vec3 lv = center.xyz-pos.xyz;
float dist = length(lv);
dist /= size;
if (dist > 1.0)
{
discard;
}
float shadow = 1.0;
if (proj_shadow_idx >= 0)
{
vec4 shd = texture2DRect(lightMap, frag.xy);
float sh[2];
sh[0] = shd.b;
sh[1] = shd.a;
shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0);
}
vec3 norm = texture2DRect(normalMap, frag.xy).xyz;
float envIntensity = norm.z;
vec4 frag = vary_fragcoord;
frag.xyz /= frag.w;
frag.xyz = frag.xyz*0.5+0.5;
frag.xy *= screen_res;
vec3 pos = getPosition(frag.xy).xyz;
vec3 lv = center.xyz-pos.xyz;
float dist = length(lv);
norm = getNorm(frag.xy);
norm = normalize(norm);
float l_dist = -dot(lv, proj_n);
vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0));
if (proj_tc.z < 0.0)
{
discard;
}
proj_tc.xyz /= proj_tc.w;
float fa = falloff+1.0;
float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0);
dist_atten *= dist_atten;
dist_atten *= 2.0;
if (dist_atten <= 0.0)
{
discard;
}
lv = proj_origin-pos.xyz;
lv = normalize(lv);
float da = dot(norm, lv);
if (dist >= size)
{
discard;
}
dist /= size;
vec3 col = vec3(0,0,0);
vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb;
vec4 spec = texture2DRect(specularRect, frag.xy);
float shadow = 1.0;
if (proj_shadow_idx >= 0)
{
vec4 shd = texture2DRect(lightMap, frag.xy);
shadow = (proj_shadow_idx==0)?shd.b:shd.a;
shadow += shadow_fade;
shadow = clamp(shadow, 0.0, 1.0);
}
vec3 norm = texture2DRect(normalMap, frag.xy).xyz;
float envIntensity = norm.z;
vec3 dlit = vec3(0, 0, 0);
norm = getNorm(frag.xy);
norm = normalize(norm);
float l_dist = -dot(lv, proj_n);
vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0));
if (proj_tc.z < 0.0)
{
discard;
}
proj_tc.xyz /= proj_tc.w;
float fa = falloff+1.0;
float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0);
dist_atten *= dist_atten;
dist_atten *= 2.0;
if (dist_atten <= 0.0)
{
discard;
}
lv = proj_origin-pos.xyz;
lv = normalize(lv);
float da = dot(norm, lv);
float noise = texture2D(noiseMap, frag.xy/128.0).b;
if (proj_tc.z > 0.0 &&
proj_tc.x < 1.0 &&
proj_tc.y < 1.0 &&
proj_tc.x > 0.0 &&
proj_tc.y > 0.0)
{
float amb_da = proj_ambiance;
float lit = 0.0;
vec3 col = vec3(0,0,0);
vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb;
vec4 spec = texture2DRect(specularRect, frag.xy);
if (da > 0.0)
{
lit = da * dist_atten * noise;
vec3 dlit = vec3(0, 0, 0);
float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0);
float lod = diff * proj_lod;
vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod);
dlit = color.rgb * plcol.rgb * plcol.a;
col = dlit*lit*diff_tex*shadow;
amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance;
}
//float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0);
vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod);
amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance;
amb_da *= dist_atten * noise;
amb_da = min(amb_da, 1.0-lit);
col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a;
}
float noise = texture2D(noiseMap, frag.xy/128.0).b;
if (proj_tc.z > 0.0 &&
proj_tc.x < 1.0 &&
proj_tc.y < 1.0 &&
proj_tc.x > 0.0 &&
proj_tc.y > 0.0)
{
float amb_da = proj_ambiance;
float lit = 0.0;
if (spec.a > 0.0)
{
vec3 npos = -normalize(pos);
dlit *= min(da*6.0, 1.0) * dist_atten;
if (da > 0.0)
{
lit = da * dist_atten * noise;
//vec3 ref = dot(pos+lv, norm);
vec3 h = normalize(lv+npos);
float nh = dot(norm, h);
float nv = dot(norm, npos);
float vh = dot(npos, h);
float sa = nh;
float fres = pow(1 - dot(h, npos), 5)*0.4+0.5;
float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0);
float lod = diff * proj_lod;
vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod);
dlit = color.rgb * plcol.rgb * plcol.a;
col = dlit*lit*diff_tex*shadow;
amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance;
}
//float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0);
vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod);
amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance;
amb_da *= dist_atten * noise;
amb_da = min(amb_da, 1.0-lit);
col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a;
}
float gtdenom = 2 * nh;
float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh));
if (nh > 0.0)
{
float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da);
col += dlit*scol*spec.rgb*shadow;
//col += spec.rgb;
}
}
if (spec.a > 0.0)
{
vec3 npos = -normalize(pos);
dlit *= min(da*6.0, 1.0) * dist_atten;
if (envIntensity > 0.0)
{
vec3 ref = reflect(normalize(pos), norm);
//project from point pos in direction ref to plane proj_p, proj_n
vec3 pdelta = proj_p-pos;
float ds = dot(ref, proj_n);
if (ds < 0.0)
{
vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds;
vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0));
//vec3 ref = dot(pos+lv, norm);
vec3 h = normalize(lv+npos);
float nh = dot(norm, h);
float nv = dot(norm, npos);
float vh = dot(npos, h);
float sa = nh;
float fres = pow(1 - dot(h, npos), 5)*0.4+0.5;
if (stc.z > 0.0)
{
float gtdenom = 2 * nh;
float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh));
if (nh > 0.0)
{
float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da);
vec3 speccol = dlit*scol*spec.rgb*shadow;
speccol = max(speccol, vec3(0));
col += speccol;
}
}
if (envIntensity > 0.0)
{
vec3 ref = reflect(normalize(pos), norm);
//project from point pos in direction ref to plane proj_p, proj_n
vec3 pdelta = proj_p-pos;
float ds = dot(ref, proj_n);
if (ds < 0.0)
{
vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds;
vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0));
if (stc.z > 0.0)
{
stc /= stc.w;
if (stc.x < 1.0 &&
stc.y < 1.0 &&
stc.x > 0.0 &&
stc.y > 0.0)
{
col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity;
}
}
}
}
if (stc.x < 1.0 &&
stc.y < 1.0 &&
stc.x > 0.0 &&
stc.y > 0.0)
{
col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity;
}
}
}
}
//not sure why, but this line prevents MATBUG-194
col = max(col, vec3(0.0));
//not sure why, but this line prevents MATBUG-194
col = max(col, vec3(0.0));
frag_color.rgb = col;
frag_color.a = 0.0;
frag_color.rgb = col;
frag_color.a = 0.0;
}

View File

@ -143,21 +143,21 @@ void main()
vec3 pos = getPosition(frag.xy).xyz;
vec3 lv = trans_center.xyz-pos.xyz;
float dist = length(lv);
if (dist >= size)
{
discard;
}
dist /= size;
if (dist > 1.0)
{
discard;
}
float shadow = 1.0;
if (proj_shadow_idx >= 0)
{
vec4 shd = texture2DRect(lightMap, frag.xy);
float sh[2];
sh[0] = shd.b;
sh[1] = shd.a;
shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0);
shadow = (proj_shadow_idx == 0) ? shd.b : shd.a;
shadow += shadow_fade;
shadow = clamp(shadow, 0.0, 1.0);
}
vec3 norm = texture2DRect(normalMap, frag.xy).xyz;
@ -226,9 +226,7 @@ void main()
vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod);
amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance;
amb_da *= dist_atten * noise;
amb_da = min(amb_da, 1.0-lit);
col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a;
@ -254,8 +252,9 @@ void main()
if (nh > 0.0)
{
float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da);
col += dlit*scol*spec.rgb*shadow;
//col += spec.rgb;
vec3 speccol = dlit*scol*spec.rgb*shadow;
speccol = max(speccol, vec3(0));
col += speccol;
}
}

View File

@ -49,7 +49,7 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight)
// Add windlight lights
col.rgb += atmosAmbient(baseLight.rgb);
col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz));
col.rgb += light_diffuse[0].rgb * calcDirectionalLight(norm, light_position[0].xyz));
col.rgb = min(col.rgb*color.rgb, 1.0);

View File

@ -46,6 +46,7 @@ uniform mat3 ssao_effect_mat;
uniform int no_atmo;
uniform float sun_moon_glow_factor;
vec3 srgb_to_linear(vec3 c);
vec3 scaleSoftClipFrag(vec3 light);
vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten)
@ -151,7 +152,7 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit,
+ tmpAmbient));
//brightness of surface both sunlight and ambient
sunlit = vec3(sunlight * .5);
sunlit = srgb_to_linear(sunlight.rgb);
amblit = vec3(tmpAmbient * .25);
additive = normalize(additive);
additive *= vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5;

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

@ -77,59 +77,59 @@ vec3 getNorm(vec2 pos_screen);
vec4 correctWithGamma(vec4 col)
{
return vec4(srgb_to_linear(col.rgb), col.a);
return vec4(srgb_to_linear(col.rgb), col.a);
}
vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)
{
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret.rgb = srgb_to_linear(ret.rgb);
vec2 dist = vec2(0.5) - abs(tc-vec2(0.5));
float det = min(lod/(proj_lod*0.5), 1.0);
float d = min(dist.x, dist.y);
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret.rgb = srgb_to_linear(ret.rgb);
vec2 dist = vec2(0.5) - abs(tc-vec2(0.5));
float det = min(lod/(proj_lod*0.5), 1.0);
float d = min(dist.x, dist.y);
d *= min(1, d * (proj_lod - lod));
float edge = 0.25*det;
ret *= clamp(d/edge, 0.0, 1.0);
return ret;
float edge = 0.25*det;
ret *= clamp(d/edge, 0.0, 1.0);
return ret;
}
vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod)
{
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret = correctWithGamma(ret);
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret = correctWithGamma(ret);
vec2 dist = vec2(0.5) - abs(tc-vec2(0.5));
float det = min(lod/(proj_lod*0.5), 1.0);
float d = min(dist.x, dist.y);
float edge = 0.25*det;
ret *= clamp(d/edge, 0.0, 1.0);
return ret;
vec2 dist = vec2(0.5) - abs(tc-vec2(0.5));
float det = min(lod/(proj_lod*0.5), 1.0);
float d = min(dist.x, dist.y);
float edge = 0.25*det;
ret *= clamp(d/edge, 0.0, 1.0);
return ret;
}
vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod)
{
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret = correctWithGamma(ret);
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret = correctWithGamma(ret);
vec2 dist = tc-vec2(0.5);
float d = dot(dist,dist);
ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0);
return ret;
vec2 dist = tc-vec2(0.5);
float d = dot(dist,dist);
ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0);
return ret;
}
@ -137,167 +137,166 @@ vec4 getPosition(vec2 pos_screen);
void main()
{
vec4 frag = vary_fragcoord;
frag.xyz /= frag.w;
frag.xyz = frag.xyz*0.5+0.5;
frag.xy *= screen_res;
vec3 pos = getPosition(frag.xy).xyz;
vec3 lv = center.xyz-pos.xyz;
float dist = length(lv);
dist /= size;
if (dist > 1.0)
{
discard;
}
float shadow = 1.0;
if (proj_shadow_idx >= 0)
{
vec4 shd = texture2DRect(lightMap, frag.xy);
float sh[2];
sh[0] = shd.b;
sh[1] = shd.a;
shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0);
}
vec3 norm = texture2DRect(normalMap, frag.xy).xyz;
float envIntensity = norm.z;
vec4 frag = vary_fragcoord;
frag.xyz /= frag.w;
frag.xyz = frag.xyz*0.5+0.5;
frag.xy *= screen_res;
vec3 pos = getPosition(frag.xy).xyz;
vec3 lv = center.xyz-pos.xyz;
float dist = length(lv);
dist /= size;
if (dist > 1.0)
{
discard;
}
float shadow = 1.0;
if (proj_shadow_idx >= 0)
{
vec4 shd = texture2DRect(lightMap, frag.xy);
shadow = (proj_shadow_idx == 0) ? shd.b : shd.a;
shadow += shadow_fade;
shadow = clamp(shadow, 0.0, 1.0);
}
vec3 norm = texture2DRect(normalMap, frag.xy).xyz;
float envIntensity = norm.z;
norm = getNorm(frag.xy);
norm = normalize(norm);
float l_dist = -dot(lv, proj_n);
vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0));
if (proj_tc.z < 0.0)
{
discard;
}
proj_tc.xyz /= proj_tc.w;
float fa = falloff+1.0;
float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0);
dist_atten *= dist_atten;
dist_atten *= 2.0;
if (dist_atten <= 0.0)
{
discard;
}
lv = proj_origin-pos.xyz;
lv = normalize(lv);
float da = dot(norm, lv);
norm = getNorm(frag.xy);
norm = normalize(norm);
float l_dist = -dot(lv, proj_n);
vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0));
if (proj_tc.z < 0.0)
{
discard;
}
proj_tc.xyz /= proj_tc.w;
float fa = (falloff*0.5)+1.0;
float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0);
dist_atten *= dist_atten;
dist_atten *= 2.0;
if (dist_atten <= 0.0)
{
discard;
}
lv = proj_origin-pos.xyz;
lv = normalize(lv);
float da = dot(norm, lv);
vec3 col = vec3(0,0,0);
vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb;
vec4 spec = texture2DRect(specularRect, frag.xy);
vec3 col = vec3(0,0,0);
vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb;
vec4 spec = texture2DRect(specularRect, frag.xy);
vec3 dlit = vec3(0, 0, 0);
vec3 dlit = vec3(0, 0, 0);
float noise = texture2D(noiseMap, frag.xy/128.0).b;
if (proj_tc.z > 0.0 &&
proj_tc.x < 1.0 &&
proj_tc.y < 1.0 &&
proj_tc.x > 0.0 &&
proj_tc.y > 0.0)
{
float amb_da = proj_ambiance;
float lit = 0.0;
float noise = texture2D(noiseMap, frag.xy/128.0).b;
if (proj_tc.z > 0.0 &&
proj_tc.x < 1.0 &&
proj_tc.y < 1.0 &&
proj_tc.x > 0.0 &&
proj_tc.y > 0.0)
{
float amb_da = proj_ambiance;
float lit = 0.0;
if (da > 0.0)
{
lit = da * dist_atten * noise;
if (da > 0.0)
{
lit = da * dist_atten * noise;
float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0);
float lod = diff * proj_lod;
vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod);
dlit = color.rgb * plcol.rgb * plcol.a;
col = dlit*lit*diff_tex*shadow;
amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance;
}
//float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0);
vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod);
amb_da += (da*da*0.5+0.5)*proj_ambiance;
amb_da *= dist_atten * noise;
amb_da = min(amb_da, 1.0-lit);
col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a;
}
float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0);
float lod = diff * proj_lod;
vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod);
dlit = color.rgb * plcol.rgb * plcol.a;
col = dlit*lit*diff_tex*shadow;
amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance;
}
//float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0);
vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod);
amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance;
amb_da *= dist_atten * noise;
amb_da = min(amb_da, 1.0-lit);
col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a;
}
if (spec.a > 0.0)
{
vec3 npos = -normalize(pos);
dlit *= min(da*6.0, 1.0) * dist_atten;
if (spec.a > 0.0)
{
vec3 npos = -normalize(pos);
dlit *= min(da*6.0, 1.0) * dist_atten;
//vec3 ref = dot(pos+lv, norm);
vec3 h = normalize(lv+npos);
float nh = dot(norm, h);
float nv = dot(norm, npos);
float vh = dot(npos, h);
float sa = nh;
float fres = pow(1 - dot(h, npos), 5)*0.4+0.5;
//vec3 ref = dot(pos+lv, norm);
vec3 h = normalize(lv+npos);
float nh = dot(norm, h);
float nv = dot(norm, npos);
float vh = dot(npos, h);
float sa = nh;
float fres = pow(1 - dot(h, npos), 5)*0.4+0.5;
float gtdenom = 2 * nh;
float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh));
if (nh > 0.0)
{
float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da);
col += dlit*scol*spec.rgb*shadow;
//col += spec.rgb;
}
}
float gtdenom = 2 * nh;
float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh));
if (nh > 0.0)
{
float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da);
col += dlit*scol*spec.rgb*shadow;
//col += spec.rgb;
}
}
if (envIntensity > 0.0)
{
vec3 ref = reflect(normalize(pos), norm);
//project from point pos in direction ref to plane proj_p, proj_n
vec3 pdelta = proj_p-pos;
float ds = dot(ref, proj_n);
if (ds < 0.0)
{
vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds;
vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0));
if (envIntensity > 0.0)
{
vec3 ref = reflect(normalize(pos), norm);
//project from point pos in direction ref to plane proj_p, proj_n
vec3 pdelta = proj_p-pos;
float ds = dot(ref, proj_n);
if (ds < 0.0)
{
vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds;
vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0));
if (stc.z > 0.0)
{
if (stc.z > 0.0)
{
stc /= stc.w;
if (stc.x < 1.0 &&
stc.y < 1.0 &&
stc.x > 0.0 &&
stc.y > 0.0)
{
col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity;
}
}
}
}
if (stc.x < 1.0 &&
stc.y < 1.0 &&
stc.x > 0.0 &&
stc.y > 0.0)
{
col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity;
}
}
}
}
//not sure why, but this line prevents MATBUG-194
col = max(col, vec3(0.0));
//not sure why, but this line prevents MATBUG-194
col = max(col, vec3(0.0));
frag_color.rgb = col;
frag_color.a = 0.0;
frag_color.rgb = col;
frag_color.a = 0.0;
}

View File

@ -77,59 +77,59 @@ vec3 linear_to_srgb(vec3 cl);
vec4 correctWithGamma(vec4 col)
{
return vec4(srgb_to_linear(col.rgb), col.a);
return vec4(srgb_to_linear(col.rgb), col.a);
}
vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)
{
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret.rgb = srgb_to_linear(ret.rgb);
vec2 dist = vec2(0.5) - abs(tc-vec2(0.5));
float det = min(lod/(proj_lod*0.5), 1.0);
float d = min(dist.x, dist.y);
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret.rgb = srgb_to_linear(ret.rgb);
vec2 dist = vec2(0.5) - abs(tc-vec2(0.5));
float det = min(lod/(proj_lod*0.5), 1.0);
float d = min(dist.x, dist.y);
d *= min(1, d * (proj_lod - lod));
float edge = 0.25*det;
ret *= clamp(d/edge, 0.0, 1.0);
return ret;
float edge = 0.25*det;
ret *= clamp(d/edge, 0.0, 1.0);
return ret;
}
vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod)
{
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret = correctWithGamma(ret);
vec2 dist = vec2(0.5) - abs(tc-vec2(0.5));
float det = min(lod/(proj_lod*0.5), 1.0);
float d = min(dist.x, dist.y);
float edge = 0.25*det;
ret *= clamp(d/edge, 0.0, 1.0);
return ret;
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret = correctWithGamma(ret);
vec2 dist = vec2(0.5) - abs(tc-vec2(0.5));
float det = min(lod/(proj_lod*0.5), 1.0);
float d = min(dist.x, dist.y);
float edge = 0.25*det;
ret *= clamp(d/edge, 0.0, 1.0);
return ret;
}
vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod)
{
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret = correctWithGamma(ret);
vec2 dist = tc-vec2(0.5);
float d = dot(dist,dist);
ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0);
return ret;
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret = correctWithGamma(ret);
vec2 dist = tc-vec2(0.5);
float d = dot(dist,dist);
ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0);
return ret;
}
@ -137,166 +137,162 @@ vec4 getPosition(vec2 pos_screen);
void main()
{
vec4 frag = vary_fragcoord;
frag.xyz /= frag.w;
frag.xyz = frag.xyz*0.5+0.5;
frag.xy *= screen_res;
vec3 pos = getPosition(frag.xy).xyz;
vec3 lv = trans_center.xyz-pos.xyz;
float dist = length(lv);
dist /= size;
if (dist > 1.0)
{
discard;
}
float shadow = 1.0;
if (proj_shadow_idx >= 0)
{
vec4 shd = texture2DRect(lightMap, frag.xy);
float sh[2];
sh[0] = shd.b;
sh[1] = shd.a;
shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0);
}
vec3 norm = texture2DRect(normalMap, frag.xy).xyz;
float envIntensity = norm.z;
norm = getNorm(frag.xy);
norm = normalize(norm);
float l_dist = -dot(lv, proj_n);
vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0));
if (proj_tc.z < 0.0)
{
discard;
}
proj_tc.xyz /= proj_tc.w;
float fa = falloff + 1.0;
float dist_atten = min(1.0 - (dist - 1.0 * (1.0 - fa)) / fa, 1.0);
dist_atten *= dist_atten;
dist_atten *= 2.0;
vec4 frag = vary_fragcoord;
frag.xyz /= frag.w;
frag.xyz = frag.xyz*0.5+0.5;
frag.xy *= screen_res;
vec3 pos = getPosition(frag.xy).xyz;
vec3 lv = trans_center.xyz-pos.xyz;
float dist = length(lv);
dist /= size;
if (dist > 1.0)
{
discard;
}
float shadow = 1.0;
if (proj_shadow_idx >= 0)
{
vec4 shd = texture2DRect(lightMap, frag.xy);
shadow = (proj_shadow_idx == 0) ? shd.b : shd.a;
shadow += shadow_fade;
shadow = clamp(shadow, 0.0, 1.0);
}
vec3 norm = texture2DRect(normalMap, frag.xy).xyz;
float envIntensity = norm.z;
norm = getNorm(frag.xy);
norm = normalize(norm);
float l_dist = -dot(lv, proj_n);
vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0));
if (proj_tc.z < 0.0)
{
discard;
}
proj_tc.xyz /= proj_tc.w;
float fa = (falloff*0.5) + 1.0;
float dist_atten = min(1.0 - (dist - 1.0 * (1.0 - fa)) / fa, 1.0);
dist_atten *= dist_atten;
dist_atten *= 2.0;
if (dist_atten <= 0.0)
{
discard;
}
lv = proj_origin-pos.xyz;
lv = normalize(lv);
float da = dot(norm, lv);
vec3 col = vec3(0,0,0);
vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb;
vec4 spec = texture2DRect(specularRect, frag.xy);
if (dist_atten <= 0.0)
{
discard;
}
lv = proj_origin-pos.xyz;
lv = normalize(lv);
float da = dot(norm, lv);
vec3 col = vec3(0,0,0);
vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb;
vec4 spec = texture2DRect(specularRect, frag.xy);
vec3 dlit = vec3(0, 0, 0);
vec3 dlit = vec3(0, 0, 0);
float noise = texture2D(noiseMap, frag.xy/128.0).b;
if (proj_tc.z > 0.0 &&
proj_tc.x < 1.0 &&
proj_tc.y < 1.0 &&
proj_tc.x > 0.0 &&
proj_tc.y > 0.0)
{
float amb_da = proj_ambiance;
float lit = 0.0;
if (da > 0.0)
{
lit = da * dist_atten * noise;
float noise = texture2D(noiseMap, frag.xy/128.0).b;
if (proj_tc.z > 0.0 &&
proj_tc.x < 1.0 &&
proj_tc.y < 1.0 &&
proj_tc.x > 0.0 &&
proj_tc.y > 0.0)
{
float amb_da = proj_ambiance;
float lit = 0.0;
if (da > 0.0)
{
lit = da * dist_atten * noise;
float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0);
float lod = diff * proj_lod;
vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod);
dlit = color.rgb * plcol.rgb * plcol.a;
col = dlit*lit*diff_tex*shadow;
amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance;
}
//float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0);
vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod);
amb_da += (da*da*0.5+0.5)*proj_ambiance;
amb_da *= dist_atten * noise;
amb_da = min(amb_da, 1.0-lit);
col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a;
}
float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0);
float lod = diff * proj_lod;
vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod);
dlit = color.rgb * plcol.rgb * plcol.a;
col = dlit*lit*diff_tex*shadow;
amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance;
}
//float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0);
vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod);
amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance;
amb_da *= dist_atten * noise;
amb_da = min(amb_da, 1.0-lit);
col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a;
}
if (spec.a > 0.0)
{
dlit *= min(da*6.0, 1.0) * dist_atten;
vec3 npos = -normalize(pos);
if (spec.a > 0.0)
{
dlit *= min(da*6.0, 1.0) * dist_atten;
vec3 npos = -normalize(pos);
//vec3 ref = dot(pos+lv, norm);
vec3 h = normalize(lv+npos);
float nh = dot(norm, h);
float nv = dot(norm, npos);
float vh = dot(npos, h);
float sa = nh;
float fres = pow(1 - dot(h, npos), 5)*0.4+0.5;
//vec3 ref = dot(pos+lv, norm);
vec3 h = normalize(lv+npos);
float nh = dot(norm, h);
float nv = dot(norm, npos);
float vh = dot(npos, h);
float sa = nh;
float fres = pow(1 - dot(h, npos), 5)*0.4+0.5;
float gtdenom = 2 * nh;
float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh));
if (nh > 0.0)
{
float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da);
col += dlit*scol*spec.rgb*shadow;
//col += spec.rgb;
}
}
float gtdenom = 2 * nh;
float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh));
if (nh > 0.0)
{
float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da);
col += dlit*scol*spec.rgb*shadow;
//col += spec.rgb;
}
}
if (envIntensity > 0.0)
{
vec3 ref = reflect(normalize(pos), norm);
//project from point pos in direction ref to plane proj_p, proj_n
vec3 pdelta = proj_p-pos;
float ds = dot(ref, proj_n);
if (ds < 0.0)
{
vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds;
vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0));
if (envIntensity > 0.0)
{
vec3 ref = reflect(normalize(pos), norm);
//project from point pos in direction ref to plane proj_p, proj_n
vec3 pdelta = proj_p-pos;
float ds = dot(ref, proj_n);
if (ds < 0.0)
{
vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds;
vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0));
if (stc.z > 0.0)
{
stc /= stc.w;
if (stc.x < 1.0 &&
stc.y < 1.0 &&
stc.x > 0.0 &&
stc.y > 0.0)
{
col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity;
}
}
}
}
//not sure why, but this line prevents MATBUG-194
col = max(col, vec3(0.0));
if (stc.z > 0.0)
{
stc /= stc.w;
if (stc.x < 1.0 &&
stc.y < 1.0 &&
stc.x > 0.0 &&
stc.y > 0.0)
{
col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity;
}
}
}
}
//not sure why, but this line prevents MATBUG-194
col = max(col, vec3(0.0));
frag_color.rgb = col;
frag_color.a = 0.0;
frag_color.rgb = col;
frag_color.a = 0.0;
}

View File

@ -29,6 +29,8 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa
vec3 atmosAmbient(vec3 light);
vec3 atmosAffectDirectionalLight(float lightIntensity);
vec3 scaleDownLight(vec3 light);
vec3 scaleUpLight(vec3 light);
uniform vec4 light_position[8];
uniform vec3 light_direction[8];
@ -37,25 +39,30 @@ uniform vec3 light_diffuse[8];
vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight)
{
vec4 col = vec4(0.0, 0.0, 0.0, color.a);
// Collect normal lights (need to be divided by two, as we later multiply by 2)
// Collect normal lights
col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z);
col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z);
col.rgb += light_diffuse[4].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[4], light_direction[4], light_attenuation[4].x, light_attenuation[4].z);
col.rgb += light_diffuse[5].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[5], light_direction[5], light_attenuation[5].x, light_attenuation[5].z);
col.rgb += light_diffuse[6].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[6], light_direction[6], light_attenuation[6].x, light_attenuation[6].z);
col.rgb += light_diffuse[7].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[7], light_direction[7], light_attenuation[7].x, light_attenuation[7].z);
col.rgb += light_diffuse[1].rgb*calcDirectionalLight(norm, light_position[1].xyz);
vec4 col = vec4(0.0, 0.0, 0.0, color.a);
// Collect normal lights (need to be divided by two, as we later multiply by 2)
// Collect normal lights
col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z);
col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z);
col.rgb += light_diffuse[4].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[4], light_direction[4], light_attenuation[4].x, light_attenuation[4].z);
col.rgb += light_diffuse[5].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[5], light_direction[5], light_attenuation[5].x, light_attenuation[5].z);
col.rgb += light_diffuse[6].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[6], light_direction[6], light_attenuation[6].x, light_attenuation[6].z);
col.rgb += light_diffuse[7].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[7], light_direction[7], light_attenuation[7].x, light_attenuation[7].z);
col.rgb += light_diffuse[1].rgb*calcDirectionalLight(norm, light_position[1].xyz);
// Add windlight lights
col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz));
col.rgb += atmosAmbient(baseLight.rgb);
col.rgb = min(col.rgb*color.rgb, 1.0);
return col;
// Add windlight lights
float l = calcDirectionalLight(norm, light_position[0].xyz);
// using light_diffuse[0] instead of WL func as it is set to the same value for these shaders anyway
// when lights are sync'd
col.rgb += l * light_diffuse[0].rgb;
col.rgb = scaleDownLight(col.rgb);
col.rgb += atmosAmbient(baseLight.rgb);
col.rgb = min(col.rgb*color.rgb, 1.0);
return col;
}

View File

@ -553,9 +553,8 @@ void LLDrawPoolWLSky::renderHeavenlyBodies()
F32 moon_brightness = (float)psky->getMoonBrightness();
moon_shader->uniform1f(LLShaderMgr::MOON_BRIGHTNESS, moon_brightness);
moon_shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, gSky.mVOSkyp->getMoon().getColor().mV);
moon_shader->uniform1f(LLShaderMgr::MOON_BRIGHTNESS, moon_brightness);
moon_shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, gSky.mVOSkyp->getMoon().getColor().mV);
moon_shader->uniform4fv(LLShaderMgr::DIFFUSE_COLOR, 1, color.mV);
moon_shader->uniform1f(LLShaderMgr::BLEND_FACTOR, blend_factor);

View File

@ -191,6 +191,8 @@ BOOL LLPanelEnvironmentInfo::postBuild()
{
drop_target->setPanel(this, alt_sliders[idx]);
}
// set initial values to prevent [ALTITUDE] from displaying
updateAltLabel(alt_prefixes[idx], idx + 2, idx * 1000);
}
getChild<LLSettingsDropTarget>("sdt_" + alt_prefixes[3])->setPanel(this, alt_prefixes[3]);
getChild<LLSettingsDropTarget>("sdt_" + alt_prefixes[4])->setPanel(this, alt_prefixes[4]);
@ -686,30 +688,36 @@ void LLPanelEnvironmentInfo::readjustAltLabels()
void LLPanelEnvironmentInfo::onSldDayLengthChanged(F32 value)
{
F32Hours daylength(value);
if (mCurrentEnvironment)
{
F32Hours daylength(value);
mCurrentEnvironment->mDayLength = daylength;
setDirtyFlag(DIRTY_FLAG_DAYLENGTH);
mCurrentEnvironment->mDayLength = daylength;
setDirtyFlag(DIRTY_FLAG_DAYLENGTH);
udpateApparentTimeOfDay();
udpateApparentTimeOfDay();
}
}
void LLPanelEnvironmentInfo::onSldDayOffsetChanged(F32 value)
{
F32Hours dayoffset(value);
if (mCurrentEnvironment)
{
F32Hours dayoffset(value);
if (dayoffset.value() <= 0.0f)
dayoffset += F32Hours(24.0);
if (dayoffset.value() <= 0.0f)
dayoffset += F32Hours(24.0);
mCurrentEnvironment->mDayOffset = dayoffset;
setDirtyFlag(DIRTY_FLAG_DAYOFFSET);
mCurrentEnvironment->mDayOffset = dayoffset;
setDirtyFlag(DIRTY_FLAG_DAYOFFSET);
udpateApparentTimeOfDay();
udpateApparentTimeOfDay();
}
}
void LLPanelEnvironmentInfo::onDayLenOffsetMouseUp()
{
if (getDirtyFlag() & (DIRTY_FLAG_DAYLENGTH | DIRTY_FLAG_DAYOFFSET))
if (mCurrentEnvironment && (getDirtyFlag() & (DIRTY_FLAG_DAYLENGTH | DIRTY_FLAG_DAYOFFSET)))
{
clearDirtyFlag(DIRTY_FLAG_DAYOFFSET);
clearDirtyFlag(DIRTY_FLAG_DAYLENGTH);

View File

@ -207,6 +207,12 @@ void LLSkyTex::create(const F32 brightness)
void LLSkyTex::createGLImage(S32 which)
{
if (LLPipeline::RenderDeferred) {
mTexture[which]->setExplicitFormat(GL_SRGB8_ALPHA8, GL_RGBA);
}
else {
mTexture[which]->setExplicitFormat(GL_RGBA8, GL_RGBA);
}
mTexture[which]->createGLTexture(0, mImageRaw[which], 0, TRUE, LLGLTexture::LOCAL);
mTexture[which]->setAddressMode(LLTexUnit::TAM_CLAMP);
}
@ -613,8 +619,10 @@ void LLVOSky::initCubeMap()
}
else if (gSavedSettings.getBOOL("RenderWater") && gGLManager.mHasCubeMap && LLCubeMap::sUseCubeMaps)
{
mCubeMap = new LLCubeMap();
mCubeMap->init(images);
bool wantsRGB = LLPipeline::RenderDeferred;
mCubeMap = new LLCubeMap(wantsRGB);
mCubeMap->init(images);
}
gGL.getTexUnit(0)->disable();
}

View File

@ -3431,6 +3431,19 @@ LLColor3 LLVOVolume::getLightColor() const
}
}
LLColor3 LLVOVolume::getLightSRGBColor() const
{
const LLLightParams *param_block = (const LLLightParams *)getParameterEntry(LLNetworkData::PARAMS_LIGHT);
if (param_block)
{
return LLColor3(param_block->getSRGBColor()) * param_block->getSRGBColor().mV[3];
}
else
{
return LLColor3(1, 1, 1);
}
}
LLUUID LLVOVolume::getLightTextureID() const
{
if (getParameterEntryInUse(LLNetworkData::PARAMS_LIGHT_IMAGE))
@ -3467,18 +3480,16 @@ F32 LLVOVolume::getSpotLightPriority() const
void LLVOVolume::updateSpotLightPriority()
{
F32 r = getLightRadius();
LLVector3 pos = mDrawable->getPositionAgent();
LLVector3 at(0,0,-1);
at *= getRenderRotation();
F32 r = getLightRadius()*0.5f;
pos += at * r;
at = LLViewerCamera::getInstance()->getAtAxis();
pos -= at * r;
mSpotLightPriority = gPipeline.calcPixelArea(pos, LLVector3(r,r,r), *LLViewerCamera::getInstance());
if (mLightTexture.notNull())

View File

@ -254,6 +254,7 @@ public:
BOOL getIsLight() const;
LLColor3 getLightBaseColor() const; // not scaled by intensity
LLColor3 getLightColor() const; // scaled by intensity
LLColor3 getLightSRGBColor() const; // Used to get the (cached) light color in sRGB color space. Also scaled by intensity.
LLUUID getLightTextureID() const;
bool isLightSpotlight() const;
LLVector3 getSpotLightParams() const;

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()
@ -255,8 +255,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();
@ -367,7 +370,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)
@ -387,7 +393,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);
@ -441,6 +447,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);

View File

@ -6382,6 +6382,7 @@ void LLPipeline::setupHWLights(LLDrawPool* pool)
LLLightState* light = gGL.getLight(0);
light->setPosition(light_dir);
light->setSunPrimary(sun_up);
light->setDiffuse(mSunDiffuse);
light->setDiffuseB(mMoonDiffuse);
light->setAmbient(LLColor4::black);
@ -6503,7 +6504,7 @@ void LLPipeline::setupHWLights(LLDrawPool* pool)
{
mHWLightColors[cur_light] = LLColor4::black;
LLLightState* light = gGL.getLight(cur_light);
light->setSunPrimary(true);
light->setDiffuse(LLColor4::black);
light->setAmbient(LLColor4::black);
light->setSpecular(LLColor4::black);
@ -8896,7 +8897,7 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target)
const F32* c = center.getF32ptr();
F32 s = volume->getLightRadius()*1.5f;
LLColor3 col = volume->getLightColor();
LLColor3 col = volume->getLightSRGBColor();
if (col.magVecSquared() < 0.001f)
{
@ -8933,10 +8934,6 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target)
continue;
}
/*col.mV[0] = powf(col.mV[0], 2.2f);
col.mV[1] = powf(col.mV[1], 2.2f);
col.mV[2] = powf(col.mV[2], 2.2f);*/
LL_RECORD_BLOCK_TIME(FTM_LOCAL_LIGHTS);
gDeferredLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c);
gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s);
@ -8992,10 +8989,7 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target)
setupSpotLight(gDeferredSpotLightProgram, drawablep);
LLColor3 col = volume->getLightColor();
/*col.mV[0] = powf(col.mV[0], 2.2f);
col.mV[1] = powf(col.mV[1], 2.2f);
col.mV[2] = powf(col.mV[2], 2.2f);*/
LLColor3 col = volume->getLightSRGBColor();
gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c);
gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s);
@ -9041,12 +9035,7 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target)
col[count] = light_colors.front();
light_colors.pop_front();
/*col[count].mV[0] = powf(col[count].mV[0], 2.2f);
col[count].mV[1] = powf(col[count].mV[1], 2.2f);
col[count].mV[2] = powf(col[count].mV[2], 2.2f);*/
far_z = llmin(light[count].mV[2]-light[count].mV[3], far_z);
//col[count] = pow4fsrgb(col[count], 2.2f);
count++;
if (count == max_count || fullscreen_lights.empty())
{
@ -9088,11 +9077,7 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target)
setupSpotLight(gDeferredMultiSpotLightProgram, drawablep);
LLColor3 col = volume->getLightColor();
/*col.mV[0] = powf(col.mV[0], 2.2f);
col.mV[1] = powf(col.mV[1], 2.2f);
col.mV[2] = powf(col.mV[2], 2.2f);*/
LLColor3 col = volume->getLightSRGBColor();
gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, tc.v);
gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s);

View File

@ -253,6 +253,8 @@
height="20"
layout="topleft"
name="edt_invname_alt1"
use_bg_color="true"
bg_color="TextBgReadOnlyColor"
width="155">
Unknown
</line_editor>
@ -297,6 +299,8 @@
height="20"
layout="topleft"
name="edt_invname_alt2"
use_bg_color="true"
bg_color="TextBgReadOnlyColor"
width="155">
Unknown
</line_editor>
@ -342,6 +346,8 @@
height="20"
layout="topleft"
name="edt_invname_alt3"
use_bg_color="true"
bg_color="TextBgReadOnlyColor"
width="155">
Unknown
</line_editor>
@ -460,6 +466,8 @@
height="20"
layout="topleft"
name="edt_invname_ground"
use_bg_color="true"
bg_color="TextBgReadOnlyColor"
width="155">
Unknown
</line_editor>
@ -514,6 +522,8 @@
height="20"
layout="topleft"
name="edt_invname_water"
use_bg_color="true"
bg_color="TextBgReadOnlyColor"
width="155">
Unknown
</line_editor>

View File

@ -6,6 +6,7 @@
commit_on_focus_lost="true"
ignore_tab="true"
cursor_color="TextCursorColor"
bg_color="White"
text_color="TextFgColor"
text_pad_left="2"
text_readonly_color="TextFgReadOnlyColor"