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