Skip to content

Commit

Permalink
#23 improve shadows quality; shader and lighting refactoring; fix muz…
Browse files Browse the repository at this point in the history
…zle flash alpha; increase light radius by 2; #15 WebGL version on Safari/Edge fix audio and shadows support
  • Loading branch information
XProger committed Dec 19, 2016
1 parent b0b7034 commit 77f40a9
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 207 deletions.
Binary file modified bin/OpenLara.exe
Binary file not shown.
31 changes: 20 additions & 11 deletions src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
PFNGLUNIFORM1IVPROC glUniform1iv;
PFNGLUNIFORM1FVPROC glUniform1fv;
PFNGLUNIFORM2FVPROC glUniform2fv;
PFNGLUNIFORM3FVPROC glUniform3fv;
PFNGLUNIFORM4FVPROC glUniform4fv;
Expand All @@ -86,9 +87,9 @@
// Render to texture
PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;
PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;
PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
Expand Down Expand Up @@ -190,6 +191,7 @@ namespace Core {
GetProcOGL(glGetShaderInfoLog);
GetProcOGL(glGetUniformLocation);
GetProcOGL(glUniform1iv);
GetProcOGL(glUniform1fv);
GetProcOGL(glUniform2fv);
GetProcOGL(glUniform3fv);
GetProcOGL(glUniform4fv);
Expand All @@ -209,9 +211,9 @@ namespace Core {

GetProcOGL(glGenFramebuffers);
GetProcOGL(glBindFramebuffer);
GetProcOGL(glFramebufferTexture2D);
GetProcOGL(glGenRenderbuffers);
GetProcOGL(glBindRenderbuffer);
GetProcOGL(glFramebufferTexture2D);
GetProcOGL(glFramebufferRenderbuffer);
GetProcOGL(glRenderbufferStorage);
GetProcOGL(glCheckFramebufferStatus);
Expand All @@ -227,18 +229,22 @@ namespace Core {
//LOG("%s\n", ext);
support.depthTexture = extSupport(ext, "_depth_texture");
support.shadowSampler = extSupport(ext, "EXT_shadow_samplers") || extSupport(ext, "GL_ARB_shadow");
support.VAO = (void*)glBindVertexArray != NULL;

LOG("Vendor : %s\n", glGetString(GL_VENDOR));
support.VAO = extSupport(ext, "_vertex_array_object");

char *vendor = (char*)glGetString(GL_VENDOR);
LOG("Vendor : %s\n", vendor);
LOG("Renderer : %s\n", glGetString(GL_RENDERER));
LOG("Version : %s\n", glGetString(GL_VERSION));

LOG("supports:\n");
LOG(" depth texture : %s\n", support.depthTexture ? "true" : "false");
LOG(" depth texture : %s\n", support.depthTexture ? "true" : "false");
LOG(" shadow sampler : %s\n", support.shadowSampler ? "true" : "false");
LOG(" vertex arrays : %s\n", support.VAO ? "true" : "false");
LOG(" vertex arrays : %s\n", support.VAO ? "true" : "false");
LOG("\n");

// if (strcmp(vendor, "WebKit") == 0) // TODO: check for safari
// support.depthTexture = support.shadowSampler = false; // depth textures is not supported in Safari browser in fact :(

glGenFramebuffers(1, &RT);

Sound::init();
Expand All @@ -254,7 +260,7 @@ namespace Core {

void clear(const vec4 &color) {
glClearColor(color.x, color.y, color.z, color.w);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
}

void setViewport(int x, int y, int width, int height) {
Expand Down Expand Up @@ -303,15 +309,18 @@ namespace Core {
void setTarget(Texture *target) {
if (!target) {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glColorMask(true, true, true, true);
return;
}

glBindFramebuffer(GL_FRAMEBUFFER, RT);
glFramebufferTexture2D(GL_FRAMEBUFFER, target->depth ? GL_DEPTH_ATTACHMENT : GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, target->ID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, target->depth ? GL_COLOR_ATTACHMENT0 : GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, target->depth ? GL_COLOR_ATTACHMENT0 : GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, target->dummy ? target->dummy->ID : 0, 0);

GLenum buffers[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(target->depth ? 0 : 1, buffers);
bool mask = !target->depth;
glColorMask(mask, mask, mask, mask);
// GLenum buffers[] = { GL_COLOR_ATTACHMENT0 };
// glDrawBuffers(target->depth ? 0 : 1, buffers);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ namespace Debug {
}
}

void lights(const TR::Level &level) {
void lights(const TR::Level &level, int room) {
// int roomIndex = level.entities[lara->entity].room;
// int lightIndex = getLightIndex(lara->pos, roomIndex);

Expand All @@ -361,10 +361,12 @@ namespace Debug {
float a = l.intensity / 8191.0f;
vec3 p = vec3(l.x, l.y, l.z);
vec4 color = vec4(a, a, a, 1);
if (i == room) color.x = color.z = 0;
Debug::Draw::point(p, color);
//if (i == roomIndex && j == lightIndex)
// color = vec4(0, 1, 0, 1);
Debug::Draw::sphere(p, l.attenuation, color);
Debug::Draw::sphere(p, l.radius, color);

}
}

Expand Down
9 changes: 6 additions & 3 deletions src/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ namespace TR {
int32 x, y, z;
uint16 align; // ! not exists in file !
uint16 intensity;
uint32 attenuation;
uint32 radius;
} *lights;

struct Mesh {
Expand Down Expand Up @@ -924,7 +924,9 @@ namespace TR {
light.intensity = stream.read(intensity);
} else
stream.read(light.intensity);
stream.read(light.attenuation);
stream.read(light.radius);

light.radius *= 2;
}
// meshes
r.meshes = new Room::Mesh[stream.read(r.meshesCount)];
Expand Down Expand Up @@ -1107,7 +1109,6 @@ namespace TR {
stream.read(c.x);
stream.read(c.y);
stream.read(c.z);
c.w = 0;
}
int16 nCount;
stream.read(nCount);
Expand All @@ -1120,6 +1121,7 @@ namespace TR {
stream.read(n.y);
stream.read(n.z);
n.w = 1;
c.w = 0x1FFF;
} else { // intensity
stream.read(c.w);
n = { 0, 0, 0, 0 };
Expand Down Expand Up @@ -1173,6 +1175,7 @@ namespace TR {
if (nCount > 0) { // normal
stream.read(n);
n.w = 1;
c.w = 0x1FFF;
} else { // intensity
stream.read(c.w);
n = { 0, 0, 0, 0 };
Expand Down
5 changes: 4 additions & 1 deletion src/lara.h
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,7 @@ struct Lara : Character {
mat4 m(matrix);
m.rotateX(-PI * 0.5f);
m.translate(offset);

Core::active.shader->setParam(uColor, vec4(lum, lum, lum, alpha));
renderMesh(m, mesh, level->extra.muzzleFlash->mStart);
}
Expand All @@ -1741,10 +1742,12 @@ struct Lara : Character {
Controller::render(frustum, mesh);
chestOffset = animation.getJoints(getMatrix(), 7).getPos(); // TODO: move to update func

if (wpnCurrent != Weapon::SHOTGUN && Core::pass != Core::passShadow) {
if (wpnCurrent != Weapon::SHOTGUN && Core::pass != Core::passShadow && (arms[0].shotTimer < MUZZLE_FLASH_TIME || arms[1].shotTimer < MUZZLE_FLASH_TIME)) {
mat4 matrix = getMatrix();
Core::active.shader->setParam(uType, Shader::FLASH);
renderMuzzleFlash(mesh, animation.getJoints(matrix, 10, true), vec3(-10, -50, 150), arms[0].shotTimer);
renderMuzzleFlash(mesh, animation.getJoints(matrix, 13, true), vec3( 10, -50, 150), arms[1].shotTimer);
Core::active.shader->setParam(uType, Shader::ENTITY);
}
}
};
Expand Down
Loading

0 comments on commit 77f40a9

Please sign in to comment.