Permalink
Browse files

noisemap tweaks and cleanup.

  • Loading branch information...
Shyotl committed Mar 28, 2017
1 parent f1063af commit 97a6f3a7b23b9e57f3d165f7cb3a4bc190da5323
@@ -1215,6 +1215,7 @@ void LLShaderMgr::initAttribsAndUniforms()
mReservedUniforms.push_back("ssao_factor_inv");
mReservedUniforms.push_back("ssao_effect");
mReservedUniforms.push_back("kern_scale");
mReservedUniforms.push_back("noise_scale");
mReservedUniforms.push_back("near_clip");
mReservedUniforms.push_back("shadow_offset");
mReservedUniforms.push_back("shadow_bias");
@@ -124,6 +124,7 @@ class LLShaderMgr
DEFERRED_SSAO_FACTOR_INV,
DEFERRED_SSAO_EFFECT,
DEFERRED_KERN_SCALE,
DEFERRED_NOISE_SCALE,
DEFERRED_NEAR_CLIP,
DEFERRED_SHADOW_OFFSET,
DEFERRED_SHADOW_BIAS,
@@ -43,6 +43,7 @@ uniform float ssao_radius;
uniform float ssao_max_radius;
uniform float ssao_factor;
uniform vec2 kern_scale;
uniform vec2 noise_scale;
vec3 decode_normal (vec2 enc)
{
@@ -87,7 +88,7 @@ vec2 getKern(int i)
float calcAmbientOcclusion(vec4 pos, vec3 norm)
{
vec2 pos_screen = vary_fragcoord.xy;
vec2 noise_reflect = texture2D(noiseMap, vary_fragcoord.xy / kern_scale / 128).xy;
vec2 noise_reflect = texture2D(noiseMap, vary_fragcoord.xy * noise_scale).xy;
// We treat the first sample as the origin, which definitely doesn't obscure itself thanks to being visible for sampling in the first place.
float points = 1.0;
@@ -125,7 +125,6 @@ vary_normal = n;
#if HAS_NORMAL_MAP
vec3 t = normalize(normal_matrix * tangent.xyz);
vec3 b = cross(n,t)*tangent.w;
//vec3 t = cross(b,n) * binormal.w;
vary_mat0 = vec3(t.x, b.x, n.x);
vary_mat1 = vec3(t.y, b.y, n.y);
@@ -53,6 +53,7 @@ VARYING vec4 vary_fragcoord;
uniform float far_z;
uniform mat4 inv_proj;
uniform vec2 noise_scale;
vec2 encode_normal(vec3 n)
{
@@ -98,7 +99,7 @@ void main()
vec4 spec = texture2D(specularRect, frag.xy);
vec3 diff = texture2D(diffuseRect, frag.xy).rgb;
float noise = texture2D(noiseMap, frag.xy/128.0).b;
float noise = texture2D(noiseMap, frag.xy*noise_scale).b;
vec3 out_col = vec3(0,0,0);
vec3 npos = normalize(-pos);
@@ -64,6 +64,7 @@ uniform float size;
VARYING vec4 vary_fragcoord;
uniform mat4 inv_proj;
uniform vec2 noise_scale;
vec2 encode_normal(vec3 n)
{
@@ -210,7 +211,7 @@ void main()
vec3 diff_tex = texture2D(diffuseRect, frag.xy).rgb;
vec3 dlit = vec3(0, 0, 0);
float noise = texture2D(noiseMap, frag.xy/128.0).b;
float noise = texture2D(noiseMap, frag.xy*noise_scale).b;
if (proj_tc.z > 0.0 &&
proj_tc.x < 1.0 &&
proj_tc.y < 1.0 &&
@@ -51,6 +51,7 @@ VARYING vec3 trans_center;
uniform mat4 inv_proj;
uniform vec4 viewport;
uniform vec2 noise_scale;
vec2 encode_normal(vec3 n)
{
@@ -108,7 +109,7 @@ void main()
lv = normalize(lv);
da = dot(norm, lv);
float noise = texture2D(noiseMap, frag.xy/128.0).b;
float noise = texture2D(noiseMap, frag.xy*noise_scale).b;
vec3 col = texture2D(diffuseRect, frag.xy).rgb;
float fa = falloff+1.0;
@@ -64,6 +64,7 @@ VARYING vec3 trans_center;
VARYING vec4 vary_fragcoord;
uniform mat4 inv_proj;
uniform vec2 noise_scale;
vec2 encode_normal(vec3 n)
{
@@ -219,7 +220,7 @@ void main()
float noise = texture2D(noiseMap, frag.xy/128.0).b;
float noise = texture2D(noiseMap, frag.xy*noise_scale).b;
vec3 dlit = vec3(0, 0, 0);
if (proj_tc.z > 0.0 &&
@@ -42,7 +42,7 @@ uniform vec2 kern_scale;
void main()
{
frag_color[0] = 1.0;
frag_color[1] = texture2D(diffuseRect,vary_fragcoord.xy * kern_scale).r;
frag_color[1] = texture2D(diffuseRect,vary_fragcoord.xy * kern_scale).r; // Scales to handle lower-res ssao.
frag_color[2] = 1.0;
frag_color[3] = 1.0;
}
@@ -65,6 +65,7 @@ uniform float size;
VARYING vec4 vary_fragcoord;
uniform mat4 inv_proj;
uniform vec2 noise_scale;
vec2 encode_normal(vec3 n)
@@ -225,7 +226,7 @@ void main()
vec3 diff_tex = texture2D(diffuseRect, frag.xy).rgb;
vec3 dlit = vec3(0, 0, 0);
float noise = texture2D(noiseMap, frag.xy/128.0).b;
float noise = texture2D(noiseMap, frag.xy*noise_scale).b;
if (proj_tc.z > 0.0 &&
proj_tc.x < 1.0 &&
proj_tc.y < 1.0 &&
@@ -65,6 +65,7 @@ VARYING vec3 trans_center;
VARYING vec4 vary_fragcoord;
uniform mat4 inv_proj;
uniform vec2 noise_scale;
vec2 encode_normal(vec3 n)
{
@@ -228,7 +229,7 @@ void main()
vec4 spec = texture2D(specularRect, frag.xy);
float noise = texture2D(noiseMap, frag.xy/128.0).b; // This is probably wrong
float noise = texture2D(noiseMap, frag.xy*noise_scale).b;
vec3 dlit = vec3(0, 0, 0);
if (proj_tc.z > 0.0 &&
View
@@ -152,7 +152,7 @@ const F32 BACKLIGHT_DAY_MAGNITUDE_OBJECT = 0.1f;
const F32 BACKLIGHT_NIGHT_MAGNITUDE_OBJECT = 0.08f;
const S32 MAX_ACTIVE_OBJECT_QUIET_FRAMES = 40;
const S32 MAX_OFFSCREEN_GEOMETRY_CHANGES_PER_FRAME = 10;
const U32 REFLECTION_MAP_RES = 128;
const U32 NOISE_MAP_RES = 256;
const U32 AUX_VB_MASK = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_TEXCOORD1;
// Max number of occluders to search for. JC
const S32 MAX_OCCLUDER_COUNT = 2;
@@ -206,14 +206,8 @@ LLTrace::BlockTimerStatHandle FTM_RENDER_DEFERRED("Deferred Shading");
static LLTrace::BlockTimerStatHandle FTM_STATESORT_DRAWABLE("Sort Drawables");
static LLTrace::BlockTimerStatHandle FTM_STATESORT_POSTSORT("Post Sort");
//static LLStaticHashedString sTint("tint");
//static LLStaticHashedString sAmbiance("ambiance");
//static LLStaticHashedString sAlphaScale("alpha_scale");
static LLStaticHashedString sNormMat("norm_mat");
//static LLStaticHashedString sOffset("offset");
static LLStaticHashedString sDelta("delta");
static LLStaticHashedString sDistFactor("dist_factor");
static LLStaticHashedString sKernScale("kern_scale");
//----------------------------------------
std::string gPoolNames[] =
@@ -388,7 +382,6 @@ LLPipeline::LLPipeline() :
mLightingDetail(0)
{
mNoiseMap = 0;
mTrueNoiseMap = 0;
mLightFunc = 0;
}
@@ -969,12 +962,6 @@ void LLPipeline::releaseGLBuffers()
mNoiseMap = 0;
}
if (mTrueNoiseMap)
{
LLImageGL::deleteTextures(1, &mTrueNoiseMap);
mTrueNoiseMap = 0;
}
releaseLUTBuffers();
mWaterRef.release();
@@ -1086,36 +1073,20 @@ void LLPipeline::createGLBuffers()
{
if (!mNoiseMap)
{
const U32 noiseRes = 128;
LLVector3 noise[noiseRes*noiseRes];
LLVector3 noise[NOISE_MAP_RES*NOISE_MAP_RES];
F32 scaler = gSavedSettings.getF32("RenderDeferredNoise")/100.f;
for (U32 i = 0; i < noiseRes*noiseRes; ++i)
for (auto& val : noise)
{
noise[i] = LLVector3(ll_frand()-0.5f, ll_frand()-0.5f, 0.f);
noise[i].normVec();
noise[i].mV[2] = ll_frand()*scaler+1.f-scaler/2.f;
val = LLVector3(ll_frand()-0.5f, ll_frand()-0.5f, 0.f);
val.normVec();
val.mV[2] = ll_frand()*scaler+1.f-scaler/2.f;
}
LLImageGL::generateTextures(1, &mNoiseMap);
gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mNoiseMap);
LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, GL_RGB16F_ARB, noiseRes, noiseRes, GL_RGB, GL_FLOAT, noise, false);
gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
}
if (!mTrueNoiseMap)
{
const U32 noiseRes = 128;
F32 noise[noiseRes*noiseRes*3];
for (U32 i = 0; i < noiseRes*noiseRes*3; i++)
{
noise[i] = ll_frand()*2.0-1.0;
}
LLImageGL::generateTextures(1, &mTrueNoiseMap);
gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mTrueNoiseMap);
LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, GL_RGB16F_ARB, noiseRes, noiseRes, GL_RGB,GL_FLOAT, noise, false);
LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, GL_RGB16F_ARB, NOISE_MAP_RES, NOISE_MAP_RES, GL_RGB, GL_FLOAT, noise, false);
gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
}
@@ -7621,6 +7592,7 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* diffus
shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_EFFECT, ssao_effect[0]);
shader.uniform2f(LLShaderMgr::DEFERRED_KERN_SCALE, 1.f / mDeferredScreen.getWidth(), 1.f / mDeferredScreen.getHeight());
shader.uniform2f(LLShaderMgr::DEFERRED_NOISE_SCALE, mDeferredScreen.getWidth() / NOISE_MAP_RES, mDeferredScreen.getHeight() / NOISE_MAP_RES);
//F32 shadow_offset_error = 1.f + RenderShadowOffsetError * fabsf(LLViewerCamera::getInstance()->getOrigin().mV[2]);
F32 shadow_bias_error = RenderShadowBiasError * fabsf(LLViewerCamera::getInstance()->getOrigin().mV[2])/3000.f;
View
@@ -637,7 +637,6 @@ class LLPipeline
//noise map
U32 mNoiseMap;
U32 mTrueNoiseMap;
U32 mLightFunc;
LLColor4 mSunDiffuse;

0 comments on commit 97a6f3a

Please sign in to comment.