Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect decals after scaling happens, use glPolygonOffset instead of m… #74

Merged
merged 2 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ A typical solution to this problem is to have the second player connect via a VP

## Known issues
* There is a bug in networked multiplayer where specific types of lag spikes cause the game to lose track of timing and [play old frames at an advanced rate](https://www.youtube.com/watch?v=zxm1zzFzor0). Thankfully this is somewhat rare during normal play.
* [#26](https://github.com/avaraline/Avara/issues/26) Some levels have graphical "z-fighting" issues where geometry is too close to other geometry and our current graphics pipeline does not reconcile this correctly causing moire-like patterns.
* [#25](https://github.com/avaraline/Avara/issues/25) Avara's usage of SDL does not play well with PulseAudio on some Linux systems. If you get a segfault when launching, try telling SDL to use ALSA instead with `export SDL_AUDIODRIVER=alsa`

[See other active bugs](https://github.com/avaraline/Avara/issues?q=is%3Aissue+is%3Aopen+label%3Abug)


## Challenges overcome while porting
Porting this game has been a heroic effort, mostly pulled off in the [span of four or five insanely productive weeks](https://github.com/avaraline/Avara/commits?after=1163cea5b338c17e406986b2926c1cdc626dccaa+34&author=dcwatson) by @dcwatson.
Expand Down
1 change: 0 additions & 1 deletion shaders/avara_frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ uniform vec3 light2 = vec3(0, 0, 0);
uniform vec3 light3 = vec3(0, 0, 0);
uniform float ambient = 0;
uniform float lights_active = 1.0;
uniform float decal;

out vec3 color;

Expand Down
16 changes: 9 additions & 7 deletions src/bsp/CBSPPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,7 @@ void CBSPPart::IBSPPart(short resId, char* levelsetName) {
maxBounds.z = ToFixed(doc["bounds"]["max"][2]);
maxBounds.w = FIX1;

float sigma = .001f;

isDecal = (
std::abs(maxX - minX) < sigma ||
std::abs(maxY - minY) < sigma ||
std::abs(maxZ - minZ) < sigma
);
isDecal = false;

pointTable = (Vector *)NewPtr(pointCount * sizeof(Vector));
polyTable = (PolyRecord *)NewPtr(polyCount * sizeof(PolyRecord));
Expand Down Expand Up @@ -159,6 +153,14 @@ void CBSPPart::IBSPPart(short resId, char* levelsetName) {
void CBSPPart::PostRender() {}

void CBSPPart::UpdateOpenGLData() {
float sigma = .001f;

isDecal = (
std::abs(maxBounds.x - minBounds.x) < sigma ||
std::abs(maxBounds.y - minBounds.y) < sigma ||
std::abs(maxBounds.z - minBounds.z) < sigma
);

if (!AvaraGLIsRendering()) return;
glDataSize = totalPoints * sizeof(GLData);
glData = (GLData *)NewPtr(glDataSize);
Expand Down
22 changes: 9 additions & 13 deletions src/util/AvaraGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ float skyboxVertices[] = {
};

GLuint gProgram;
GLuint mvLoc, ntLoc, ambLoc, lights_activeLoc, projLoc, viewLoc, decalLoc;
GLuint mvLoc, ntLoc, ambLoc, lights_activeLoc, projLoc, viewLoc;
GLuint light0Loc, light1Loc, light2Loc, light3Loc;

GLuint skyProgram;
Expand Down Expand Up @@ -170,11 +170,6 @@ void AvaraGLLightDefaults() {
AvaraGLSetAmbient(0.4f);
}

void AvaraGLSetDecal(float active) {
glUseProgram(gProgram);
glUniform1f(decalLoc, active);
}

void SetTransforms(Matrix *modelview, Matrix *normal_transform) {
glUniformMatrix4fv(mvLoc, 1, GL_FALSE, glm::value_ptr(ToFloatMat(modelview)));
glm::mat3 normal_mat = glm::mat3(1.0f);
Expand All @@ -201,7 +196,6 @@ void AvaraGLInitContext() {
ntLoc = glGetUniformLocation(gProgram, "normal_transform");
ambLoc = glGetUniformLocation(gProgram, "ambient");
lights_activeLoc = glGetUniformLocation(gProgram, "lights_active");
decalLoc = glGetUniformLocation(gProgram, "decal");
glCheckErrors();


Expand All @@ -222,7 +216,6 @@ void AvaraGLInitContext() {
groundColorLoc = glGetUniformLocation(skyProgram, "groundColor");
horizonColorLoc = glGetUniformLocation(skyProgram, "horizonColor");
skyColorLoc = glGetUniformLocation(skyProgram, "skyColor");

}

void AvaraGLDrawPolygons(CBSPPart* part) {
Expand Down Expand Up @@ -259,9 +252,11 @@ void AvaraGLDrawPolygons(CBSPPart* part) {

// if we're drawing something thin
// give it a little z-buffer push towards
// the camera by scaling down the z-value
if (part->isDecal) {
AvaraGLSetDecal(.9995f);
// the camera by scaling the z-value
bool decal = part->isDecal;
if (decal) {
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(-1.0, 1.0);
}

SetTransforms(&part->fullTransform, &part->itsTransform);
Expand All @@ -275,8 +270,8 @@ void AvaraGLDrawPolygons(CBSPPart* part) {
glDisableVertexAttribArray(2);

// reset z-buffer scale
if (part->isDecal) {
AvaraGLSetDecal(1.0);
if (decal) {
glDisable(GL_POLYGON_OFFSET_FILL);
}

// restore previous lighting state
Expand All @@ -295,6 +290,7 @@ void AvaraGLDrawPolygons(CBSPPart* part) {

glBindBuffer(GL_ARRAY_BUFFER, NULL);
glCheckErrors();

}


Expand Down