Skip to content

Commit

Permalink
Only allow gl_FragDepth in desktop GL
Browse files Browse the repository at this point in the history
  • Loading branch information
GlennFolker committed Feb 18, 2024
1 parent 7dccada commit e96ec1a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions assets/shaders/confictura/portal-forcefield.frag
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,10 @@ void main(){

vec3 outlineColor = v_color.xyz * pow(max(1.0 - v_color.a - 0.5, 0.0) * 2.0, 4.0) * outline;
gl_FragColor = vec4(baseColor + outlineColor, 1.0);

#ifdef HAS_GL_FRAGDEPTH
float far = gl_DepthRange.far, near = gl_DepthRange.near;
vec4 clip = u_proj * vec4(u_camPos + ray * intersect.x, 1.0);
gl_FragDepth = (((far - near) * (clip.z / clip.w)) + near + far) / 2.0;
#endif
}
11 changes: 11 additions & 0 deletions src/confictura/graphics/CShaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import arc.files.*;
import arc.graphics.gl.*;
import arc.graphics.gl.GLVersion.*;
import confictura.graphics.shaders.*;
import mindustry.*;

import static arc.Core.*;
import static mindustry.Vars.*;

/**
Expand All @@ -23,10 +25,19 @@ private CShaders(){

/** Loads the shaders. Client-side and main thread only! */
public static void load(){
String prevVert = Shader.prependVertexCode, prevFrag = Shader.prependFragmentCode;

if(graphics.getGLVersion().type == GlType.OpenGL){
Shader.prependFragmentCode = "#define HAS_GL_FRAGDEPTH\n";
}

depth = new DepthShader();
depthAtmosphere = new DepthAtmosphereShader();
portalForcefield = new PortalForcefieldShader();
celestial = new CelestialShader();

Shader.prependVertexCode = prevVert;
Shader.prependFragmentCode = prevFrag;
}

/**
Expand Down

0 comments on commit e96ec1a

Please sign in to comment.