Skip to content

Commit

Permalink
Experiment with IBL and skybox
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesTKhan committed Jul 9, 2022
1 parent bc89c08 commit 54646ce
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
16 changes: 13 additions & 3 deletions commons/src/main/com/mbrlabs/mundus/commons/Scene.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ public Scene() {
}

private void initPBR() {
brdfLUT = new Texture(Gdx.files.classpath("net/mgsx/gltf/shaders/brdfLUT.png"));
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .3f, .3f, .3f, 1));
environment.set(new PBRTextureAttribute(PBRTextureAttribute.BRDFLUTTexture, brdfLUT));
initIBL();
}

private void initIBL() {
DirectionalLightEx directionalLightEx = new DirectionalLightEx();
directionalLightEx.intensity = DirectionalLight.DEFAULT_INTENSITY;
directionalLightEx.setColor(DirectionalLight.DEFAULT_COLOR);
Expand All @@ -132,9 +139,6 @@ private void initPBR() {
specularCubemap = iblBuilder.buildRadianceMap(10);
iblBuilder.dispose();

brdfLUT = new Texture(Gdx.files.classpath("net/mgsx/gltf/shaders/brdfLUT.png"));
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .3f, .3f, .3f, 1));
environment.set(new PBRTextureAttribute(PBRTextureAttribute.BRDFLUTTexture, brdfLUT));
environment.set(PBRCubemapAttribute.createSpecularEnv(specularCubemap));
environment.set(PBRCubemapAttribute.createDiffuseEnv(diffuseCubemap));
}
Expand Down Expand Up @@ -343,6 +347,12 @@ public void setSkybox(SkyboxAsset skyboxAsset, Shader skyboxShader) {
skybox.setRotateSpeed(skyboxAsset.rotateSpeed);
skybox.setRotateEnabled(skyboxAsset.rotateEnabled);

skybox.setUseIBL(true);
if (skybox.useWithIBL()) {
environment.set(PBRCubemapAttribute.createDiffuseEnv(skybox.getCubemap()));
} else {
initIBL();
}
}

@Override
Expand Down
12 changes: 12 additions & 0 deletions commons/src/main/com/mbrlabs/mundus/commons/skybox/Skybox.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class Skybox implements Disposable {
private FileHandle positiveZ;
private FileHandle negativeZ;

private boolean useIBL;
private boolean rotateEnabled;
private float rotateSpeed;

Expand Down Expand Up @@ -121,6 +122,10 @@ public void setRotateEnabled(boolean rotateEnabled) {
((SkyboxShader) shader).setRotateEnabled(rotateEnabled);
}

public Cubemap getCubemap() {
return cubemap;
}

public float getRotateSpeed() {
return rotateSpeed;
}
Expand All @@ -138,4 +143,11 @@ public void dispose() {
cubemap.dispose();
}

public void setUseIBL(boolean value) {
useIBL = value;
}

public boolean useWithIBL() {
return useIBL;
}
}

0 comments on commit 54646ce

Please sign in to comment.