Merge branch 'master' of https://github.com/supertuxkart/stk-code into devel
This commit is contained in:
commit
d6b75dc2ea
@ -22,6 +22,7 @@ layout (std140) uniform MatrixesData
|
||||
flat in vec3 center;
|
||||
flat in float energy;
|
||||
flat in vec3 col;
|
||||
flat in float radius;
|
||||
|
||||
out vec4 Diffuse;
|
||||
out vec4 Specular;
|
||||
@ -46,8 +47,7 @@ void main()
|
||||
vec3 light_col = col.xyz;
|
||||
float d = distance(light_pos, xpos.xyz);
|
||||
float att = energy * 20. / (1. + d * d);
|
||||
float max_d = 5. * energy;
|
||||
att *= (max_d - d) / max_d;
|
||||
att *= (radius - d) / radius;
|
||||
if (att <= 0.) discard;
|
||||
|
||||
// Light Direction
|
||||
|
@ -17,10 +17,12 @@ layout (std140) uniform MatrixesData
|
||||
in vec3 Position;
|
||||
in float Energy;
|
||||
in vec3 Color;
|
||||
in float Radius;
|
||||
|
||||
flat out vec3 center;
|
||||
flat out float energy;
|
||||
flat out vec3 col;
|
||||
flat out float radius;
|
||||
|
||||
const float zNear = 1.;
|
||||
|
||||
@ -86,12 +88,11 @@ vec4 ComputeClipRegion(vec3 lightPosView, float lightRadius)
|
||||
|
||||
void main(void)
|
||||
{
|
||||
float radius = 5. * Energy;
|
||||
vec4 Center = ViewMatrix * vec4(Position, 1.);
|
||||
Center /= Center.w;
|
||||
|
||||
vec2 ProjectedCornerPosition;
|
||||
vec4 clip = ComputeClipRegion(Center.xyz, radius);
|
||||
vec4 clip = ComputeClipRegion(Center.xyz, Radius);
|
||||
switch (gl_VertexID)
|
||||
{
|
||||
case 0:
|
||||
@ -110,7 +111,7 @@ void main(void)
|
||||
|
||||
// Work out nearest depth for quad Z
|
||||
// Clamp to near plane in case this light intersects the near plane... don't want our quad to be clipped
|
||||
float quadDepth = max(zNear, Center.z - radius);
|
||||
float quadDepth = max(zNear, Center.z - Radius);
|
||||
|
||||
// Project quad depth into clip space
|
||||
vec4 quadClip = ProjectionMatrix * vec4(0., 0., quadDepth, 1.0f);
|
||||
@ -119,4 +120,5 @@ void main(void)
|
||||
col = Color;
|
||||
center = Position;
|
||||
energy = Energy;
|
||||
radius = Radius;
|
||||
}
|
||||
|
@ -1,80 +1,84 @@
|
||||
// From paper http://graphics.cs.williams.edu/papers/AlchemyHPG11/
|
||||
// and improvements here http://graphics.cs.williams.edu/papers/SAOHPG12/
|
||||
|
||||
uniform sampler2D ntex;
|
||||
uniform sampler2D dtex;
|
||||
uniform sampler2D noise_texture;
|
||||
uniform vec4 samplePoints[16];
|
||||
|
||||
#ifdef UBO_DISABLED
|
||||
uniform mat4 ViewMatrix;
|
||||
uniform mat4 ProjectionMatrix;
|
||||
uniform mat4 InverseViewMatrix;
|
||||
uniform mat4 InverseProjectionMatrix;
|
||||
#else
|
||||
layout (std140) uniform MatrixesData
|
||||
{
|
||||
mat4 ViewMatrix;
|
||||
mat4 ProjectionMatrix;
|
||||
mat4 InverseViewMatrix;
|
||||
mat4 InverseProjectionMatrix;
|
||||
mat4 ShadowViewProjMatrixes[4];
|
||||
};
|
||||
#endif
|
||||
|
||||
in vec2 uv;
|
||||
out float AO;
|
||||
|
||||
const float sigma = 1.;
|
||||
const float tau = 7.;
|
||||
const float beta = 0.0001;
|
||||
const float epsilon = .00001;
|
||||
const float radius = 2.;
|
||||
const float k = 1.5;
|
||||
|
||||
#define SAMPLES 16
|
||||
|
||||
const float invSamples = 1. / SAMPLES;
|
||||
|
||||
vec3 DecodeNormal(vec2 n);
|
||||
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 cur = texture(ntex, uv);
|
||||
float curdepth = texture(dtex, uv).x;
|
||||
vec4 FragPos = getPosFromUVDepth(vec3(uv, curdepth), InverseProjectionMatrix);
|
||||
|
||||
// get the normal of current fragment
|
||||
vec3 ddx = dFdx(FragPos.xyz);
|
||||
vec3 ddy = dFdy(FragPos.xyz);
|
||||
vec3 norm = normalize(cross(ddy, ddx));
|
||||
// Workaround for nvidia and skyboxes
|
||||
float len = dot(vec3(1.0), abs(cur.xyz));
|
||||
if (len < 0.2) discard;
|
||||
|
||||
int x = int(1024. * uv.x), y = int(1024. * uv.y);
|
||||
float r = radius / FragPos.z;
|
||||
float phi = 30. * (x ^ y) + 10. * x * y;
|
||||
float bl = 0.0;
|
||||
|
||||
for(int i = 0; i < SAMPLES; ++i) {
|
||||
float alpha = (i + .5) * invSamples;
|
||||
float theta = 2. * 3.14 * tau * alpha + phi;
|
||||
float h = r * alpha;
|
||||
vec2 occluder_uv = h * vec2(cos(theta), sin(theta));
|
||||
occluder_uv += uv;
|
||||
|
||||
if (occluder_uv.x < 0. || occluder_uv.x > 1. || occluder_uv.y < 0. || occluder_uv.y > 1.) continue;
|
||||
|
||||
float m = round(log2(h)) + 7.;
|
||||
|
||||
float occluderFragmentDepth = textureLod(dtex, occluder_uv, m).x;
|
||||
vec4 OccluderPos = getPosFromUVDepth(vec3(occluder_uv, occluderFragmentDepth), InverseProjectionMatrix);
|
||||
|
||||
vec3 vi = (OccluderPos - FragPos).xyz;
|
||||
bl += max(0, dot(vi, norm) - FragPos.z * beta) / (dot(vi, vi) + epsilon);
|
||||
}
|
||||
|
||||
AO = max(pow(1.0 - 2. * sigma * bl * invSamples, k), 0.);
|
||||
}
|
||||
// From paper http://graphics.cs.williams.edu/papers/AlchemyHPG11/
|
||||
// and improvements here http://graphics.cs.williams.edu/papers/SAOHPG12/
|
||||
|
||||
uniform sampler2D ntex;
|
||||
uniform sampler2D dtex;
|
||||
uniform sampler2D noise_texture;
|
||||
uniform vec4 samplePoints[16];
|
||||
uniform vec2 screen = vec2(1680, 1050);
|
||||
|
||||
#ifdef UBO_DISABLED
|
||||
uniform mat4 ViewMatrix;
|
||||
uniform mat4 ProjectionMatrix;
|
||||
uniform mat4 InverseViewMatrix;
|
||||
uniform mat4 InverseProjectionMatrix;
|
||||
#else
|
||||
layout (std140) uniform MatrixesData
|
||||
{
|
||||
mat4 ViewMatrix;
|
||||
mat4 ProjectionMatrix;
|
||||
mat4 InverseViewMatrix;
|
||||
mat4 InverseProjectionMatrix;
|
||||
mat4 ShadowViewProjMatrixes[4];
|
||||
};
|
||||
#endif
|
||||
|
||||
in vec2 uv;
|
||||
out float AO;
|
||||
|
||||
const float sigma = 1.;
|
||||
const float tau = 2.;
|
||||
const float beta = 0.0001;
|
||||
const float epsilon = .00001;
|
||||
const float radius = 1.;
|
||||
const float k = 1.;
|
||||
|
||||
#define SAMPLES 16
|
||||
|
||||
const float invSamples = 1. / SAMPLES;
|
||||
|
||||
vec3 DecodeNormal(vec2 n);
|
||||
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 cur = texture(ntex, uv);
|
||||
float curdepth = texture(dtex, uv).x;
|
||||
vec4 FragPos = getPosFromUVDepth(vec3(uv, curdepth), InverseProjectionMatrix);
|
||||
|
||||
// get the normal of current fragment
|
||||
vec3 ddx = dFdx(FragPos.xyz);
|
||||
vec3 ddy = dFdy(FragPos.xyz);
|
||||
vec3 norm = normalize(cross(ddy, ddx));
|
||||
// Workaround for nvidia and skyboxes
|
||||
float len = dot(vec3(1.0), abs(cur.xyz));
|
||||
if (len < 0.2) discard;
|
||||
|
||||
int x = int(gl_FragCoord.x), y = int(gl_FragCoord.y);
|
||||
float r = radius / FragPos.z;
|
||||
float phi = 30. * (x ^ y) + 10. * x * y;
|
||||
float bl = 0.0;
|
||||
|
||||
for(int i = 0; i < SAMPLES; ++i) {
|
||||
float alpha = (i + .5) * invSamples;
|
||||
float theta = 2. * 3.14 * tau * alpha + phi;
|
||||
float h = r * alpha;
|
||||
vec2 occluder_uv = h * vec2(cos(theta), sin(theta)) * screen;
|
||||
occluder_uv += gl_FragCoord.xy;
|
||||
|
||||
float m = round(log2(h)) + 7;
|
||||
ivec2 ioccluder_uv = ivec2(occluder_uv);
|
||||
occluder_uv = (ioccluder_uv >> int(m)) << int(m);
|
||||
occluder_uv /= screen;
|
||||
|
||||
if (occluder_uv.x < 0. || occluder_uv.x > 1. || occluder_uv.y < 0. || occluder_uv.y > 1.) continue;
|
||||
|
||||
float occluderFragmentDepth = textureLod(dtex, occluder_uv, m).x;
|
||||
vec4 OccluderPos = getPosFromUVDepth(vec3(occluder_uv, occluderFragmentDepth), InverseProjectionMatrix);
|
||||
|
||||
vec3 vi = (OccluderPos - FragPos).xyz;
|
||||
bl += max(0, dot(vi, norm) - FragPos.z * beta) / (dot(vi, vi) + epsilon);
|
||||
}
|
||||
|
||||
AO = max(pow(1.0 - 2. * sigma * bl * invSamples, k), 0.);
|
||||
}
|
@ -264,6 +264,7 @@ bool CIrrDeviceLinux::switchToFullscreen(bool reset)
|
||||
// enumerate video modes
|
||||
s32 modeCount;
|
||||
XF86VidModeModeInfo** modes;
|
||||
float refresh_rate;
|
||||
|
||||
XF86VidModeGetAllModeLines(display, screennr, &modeCount, &modes);
|
||||
|
||||
@ -271,13 +272,37 @@ bool CIrrDeviceLinux::switchToFullscreen(bool reset)
|
||||
for (s32 i = 0; i<modeCount; ++i)
|
||||
{
|
||||
if (bestMode==-1 && modes[i]->hdisplay >= Width && modes[i]->vdisplay >= Height)
|
||||
{
|
||||
float pixels_per_second = modes[i]->dotclock * 1000.0;
|
||||
float pixels_per_frame = modes[i]->htotal * modes[i]->vtotal;
|
||||
refresh_rate = pixels_per_second / pixels_per_frame;
|
||||
bestMode = i;
|
||||
}
|
||||
else if (bestMode!=-1 &&
|
||||
modes[i]->hdisplay == modes[bestMode]->hdisplay &&
|
||||
modes[i]->vdisplay == modes[bestMode]->vdisplay)
|
||||
{
|
||||
float pixels_per_second = modes[i]->dotclock * 1000.0;
|
||||
float pixels_per_frame = modes[i]->htotal * modes[i]->vtotal;
|
||||
float refresh_rate_tmp = pixels_per_second / pixels_per_frame;
|
||||
|
||||
if (refresh_rate_tmp > refresh_rate)
|
||||
{
|
||||
refresh_rate = refresh_rate_tmp;
|
||||
bestMode = i;
|
||||
}
|
||||
}
|
||||
else if (bestMode!=-1 &&
|
||||
modes[i]->hdisplay >= Width &&
|
||||
modes[i]->vdisplay >= Height &&
|
||||
modes[i]->hdisplay <= modes[bestMode]->hdisplay &&
|
||||
modes[i]->vdisplay <= modes[bestMode]->vdisplay)
|
||||
{
|
||||
float pixels_per_second = modes[i]->dotclock * 1000.0;
|
||||
float pixels_per_frame = modes[i]->htotal * modes[i]->vtotal;
|
||||
refresh_rate = pixels_per_second / pixels_per_frame;
|
||||
bestMode = i;
|
||||
}
|
||||
}
|
||||
if (bestMode != -1)
|
||||
{
|
||||
|
@ -789,7 +789,7 @@ static void renderPointLights(unsigned count)
|
||||
setTexture(1, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST);
|
||||
LightShader::PointLightShader
|
||||
::setUniforms(core::vector2df(float(UserConfigParams::m_width),
|
||||
float(UserConfigParams::m_height) ),
|
||||
float(UserConfigParams::m_height) ),
|
||||
200, 0, 1);
|
||||
|
||||
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, count);
|
||||
@ -870,6 +870,9 @@ void IrrDriver::renderLights(scene::ICameraSceneNode * const camnode, float dt)
|
||||
PointLightsInfo[lightnum].red = col.X;
|
||||
PointLightsInfo[lightnum].green = col.Y;
|
||||
PointLightsInfo[lightnum].blue = col.Z;
|
||||
|
||||
// Light radius
|
||||
PointLightsInfo[lightnum].radius = 20 * light_node->getEffectiveEnergy();
|
||||
}
|
||||
}
|
||||
if (lightnum > MAXLIGHT)
|
||||
|
@ -1825,6 +1825,7 @@ namespace LightShader
|
||||
GLuint PointLightShader::attrib_Position;
|
||||
GLuint PointLightShader::attrib_Color;
|
||||
GLuint PointLightShader::attrib_Energy;
|
||||
GLuint PointLightShader::attrib_Radius;
|
||||
GLuint PointLightShader::uniform_ntex;
|
||||
GLuint PointLightShader::uniform_dtex;
|
||||
GLuint PointLightShader::uniform_spec;
|
||||
@ -1843,6 +1844,7 @@ namespace LightShader
|
||||
attrib_Position = glGetAttribLocation(Program, "Position");
|
||||
attrib_Color = glGetAttribLocation(Program, "Color");
|
||||
attrib_Energy = glGetAttribLocation(Program, "Energy");
|
||||
attrib_Radius = glGetAttribLocation(Program, "Radius");
|
||||
uniform_ntex = glGetUniformLocation(Program, "ntex");
|
||||
uniform_dtex = glGetUniformLocation(Program, "dtex");
|
||||
uniform_spec = glGetUniformLocation(Program, "spec");
|
||||
@ -1861,10 +1863,13 @@ namespace LightShader
|
||||
glVertexAttribPointer(attrib_Energy, 1, GL_FLOAT, GL_FALSE, sizeof(PointLightInfo), (GLvoid*)(3 * sizeof(float)));
|
||||
glEnableVertexAttribArray(attrib_Color);
|
||||
glVertexAttribPointer(attrib_Color, 3, GL_FLOAT, GL_FALSE, sizeof(PointLightInfo), (GLvoid*)(4 * sizeof(float)));
|
||||
glEnableVertexAttribArray(attrib_Radius);
|
||||
glVertexAttribPointer(attrib_Radius, 1, GL_FLOAT, GL_FALSE, sizeof(PointLightInfo), (GLvoid*)(7 * sizeof(float)));
|
||||
|
||||
glVertexAttribDivisor(attrib_Position, 1);
|
||||
glVertexAttribDivisor(attrib_Energy, 1);
|
||||
glVertexAttribDivisor(attrib_Color, 1);
|
||||
glVertexAttribDivisor(attrib_Radius, 1);
|
||||
}
|
||||
|
||||
void PointLightShader::setUniforms(const core::vector2df &screen, unsigned spec, unsigned TU_ntex, unsigned TU_dtex)
|
||||
|
@ -440,7 +440,7 @@ namespace LightShader
|
||||
float red;
|
||||
float green;
|
||||
float blue;
|
||||
float padding;
|
||||
float radius;
|
||||
};
|
||||
|
||||
|
||||
@ -448,7 +448,7 @@ namespace LightShader
|
||||
{
|
||||
public:
|
||||
static GLuint Program;
|
||||
static GLuint attrib_Position, attrib_Energy, attrib_Color;
|
||||
static GLuint attrib_Position, attrib_Energy, attrib_Color, attrib_Radius;
|
||||
static GLuint uniform_ntex, uniform_dtex, uniform_spec, uniform_screen;
|
||||
static GLuint vbo;
|
||||
static GLuint vao;
|
||||
|
Loading…
Reference in New Issue
Block a user