Skip to content

Commit

Permalink
Merge pull request #207 from JamesTKhan/upgrade-gdx-gltf
Browse files Browse the repository at this point in the history
Upgrade gdx-gltf version to support CSM in future
  • Loading branch information
JamesTKhan authored Sep 1, 2024
2 parents 15f4204 + 9ae2ae2 commit a894e60
Show file tree
Hide file tree
Showing 13 changed files with 826 additions and 857 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ allprojects {
mockitoVersion = '1.10.19'
commonsIoVersion = '2.5'
commonsLangVersion = '3.12.0'
gltfVersion = '2.1.0'
gltfVersion = '2.2.1'
args4jVersion = '2.33'
pf4jVersion = '3.11.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

import com.badlogic.gdx.graphics.g3d.Attributes;
import com.badlogic.gdx.graphics.g3d.Renderable;
import com.badlogic.gdx.graphics.g3d.attributes.PointLightsAttribute;
import com.badlogic.gdx.graphics.g3d.attributes.SpotLightsAttribute;
import com.badlogic.gdx.graphics.g3d.environment.PointLight;
import com.badlogic.gdx.graphics.g3d.environment.SpotLight;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import com.mbrlabs.mundus.commons.env.MundusEnvironment;
import net.mgsx.gltf.scene3d.shaders.PBRShader;

Expand All @@ -15,6 +20,10 @@ public class MundusPBRShader extends PBRShader {

private final int u_clipPlane = register("u_clipPlane");

protected final int UNIFORM_POINT_LIGHT_NUM_ACTIVE = register(new Uniform("u_activeNumPointLights"));

protected final int UNIFORM_SPOT_LIGHT_NUM_ACTIVE = register(new Uniform("u_activeNumSpotLights"));

public MundusPBRShader(Renderable renderable, Config config, String prefix) {
super(renderable, config, prefix);
}
Expand All @@ -38,6 +47,24 @@ protected void bindLights(Renderable renderable, Attributes attributes) {
Vector3 clippingPlane = env.getClippingPlane();
set(u_clipPlane, clippingPlane.x, clippingPlane.y, clippingPlane.z, env.getClippingHeight());

//
PointLightsAttribute attr = env.get(PointLightsAttribute.class, PointLightsAttribute.Type);
final Array<PointLight> pointLights = attr == null ? null : attr.lights;
if (pointLights != null && pointLights.size > 0) {
set(UNIFORM_POINT_LIGHT_NUM_ACTIVE, pointLights.size);
} else {
set(UNIFORM_POINT_LIGHT_NUM_ACTIVE, 0);
}

SpotLightsAttribute spotAttr = env.get(SpotLightsAttribute.class, SpotLightsAttribute.Type);
final Array<SpotLight> spotLights = spotAttr == null ? null : spotAttr.lights;

if (spotLights != null && spotLights.size > 0) {
set(UNIFORM_SPOT_LIGHT_NUM_ACTIVE, spotLights.size);
} else {
set(UNIFORM_SPOT_LIGHT_NUM_ACTIVE, 0);
}

super.bindLights(renderable, attributes);
}
}
Loading

0 comments on commit a894e60

Please sign in to comment.