From ebb701784dc8dc5444ff27533da703cbe7873961 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 16 Oct 2022 20:00:15 -0400 Subject: [PATCH 1/4] Add Water Uber Shader --- .../attributes => }/MundusAttribute.java | 2 +- .../mundus/commons/assets/WaterAsset.java | 22 +- .../scene3d/components/WaterComponent.java | 15 +- .../shaders/MundusPBRShaderProvider.java | 10 + .../commons/shaders/TerrainUberShader.java | 10 +- .../commons/shaders/WaterUberShader.java | 294 ++++++++++++++++++ .../commons/shaders/water.uber.frag.glsl | 240 ++++++++++++++ .../commons/shaders/water.uber.vert.glsl | 41 +++ .../terrain/attributes/TerrainAttribute.java | 2 + .../terrain/attributes/TerrainAttributes.java | 1 + .../mundus/commons/utils/ShaderUtils.java | 14 + .../mbrlabs/mundus/commons/water/Water.java | 48 +-- .../mundus/commons/water/WaterMaterial.java | 88 ++++++ .../water/attributes/WaterAttributes.java | 223 +++++++++++++ .../attributes/WaterFloatAttributeU.java | 89 ++++++ .../attributes/WaterMaterialAttribute.java | 53 ++++ .../attributes/WaterTextureAttributeU.java | 130 ++++++++ .../editor/assets/EditorAssetManager.kt | 22 +- .../mundus/editor/ui/widgets/WaterWidget.kt | 62 ++-- 19 files changed, 1274 insertions(+), 92 deletions(-) rename commons/src/main/com/mbrlabs/mundus/commons/{terrain/attributes => }/MundusAttribute.java (97%) create mode 100644 commons/src/main/com/mbrlabs/mundus/commons/shaders/WaterUberShader.java create mode 100644 commons/src/main/com/mbrlabs/mundus/commons/shaders/water.uber.frag.glsl create mode 100644 commons/src/main/com/mbrlabs/mundus/commons/shaders/water.uber.vert.glsl create mode 100644 commons/src/main/com/mbrlabs/mundus/commons/water/WaterMaterial.java create mode 100644 commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterAttributes.java create mode 100644 commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterFloatAttributeU.java create mode 100644 commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterMaterialAttribute.java create mode 100644 commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterTextureAttributeU.java diff --git a/commons/src/main/com/mbrlabs/mundus/commons/terrain/attributes/MundusAttribute.java b/commons/src/main/com/mbrlabs/mundus/commons/MundusAttribute.java similarity index 97% rename from commons/src/main/com/mbrlabs/mundus/commons/terrain/attributes/MundusAttribute.java rename to commons/src/main/com/mbrlabs/mundus/commons/MundusAttribute.java index bfb02e66d..969af4dea 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/terrain/attributes/MundusAttribute.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/MundusAttribute.java @@ -1,4 +1,4 @@ -package com.mbrlabs.mundus.commons.terrain.attributes; +package com.mbrlabs.mundus.commons; import com.badlogic.gdx.utils.Array; diff --git a/commons/src/main/com/mbrlabs/mundus/commons/assets/WaterAsset.java b/commons/src/main/com/mbrlabs/mundus/commons/assets/WaterAsset.java index 0a019a223..3e772a1d6 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/assets/WaterAsset.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/assets/WaterAsset.java @@ -7,7 +7,7 @@ import com.badlogic.gdx.utils.PropertiesUtils; import com.mbrlabs.mundus.commons.assets.meta.Meta; import com.mbrlabs.mundus.commons.water.Water; -import com.mbrlabs.mundus.commons.water.WaterFloatAttribute; +import com.mbrlabs.mundus.commons.water.attributes.WaterFloatAttributeU; import java.io.IOException; import java.io.Reader; @@ -62,16 +62,16 @@ public void load() { normaMapID = MAP.get(PROP_NORMAL_MAP, "waterNormal"); // float attributes - water.setFloatAttribute(WaterFloatAttribute.Tiling, Float.parseFloat(MAP.get(PROP_TILING, String.valueOf(Water.DEFAULT_TILING)))); - water.setFloatAttribute(WaterFloatAttribute.WaveStrength, Float.parseFloat(MAP.get(PROP_WAVE_STRENGTH, String.valueOf(Water.DEFAULT_WAVE_STRENGTH)))); - water.setFloatAttribute(WaterFloatAttribute.WaveSpeed, Float.parseFloat(MAP.get(PROP_WAVE_SPEED, String.valueOf(Water.DEFAULT_WAVE_SPEED)))); - water.setFloatAttribute(WaterFloatAttribute.FoamPatternScale, Float.parseFloat(MAP.get(PROP_FOAM_SCALE, String.valueOf(Water.DEFAULT_FOAM_SCALE)))); - water.setFloatAttribute(WaterFloatAttribute.FoamEdgeBias, Float.parseFloat(MAP.get(PROP_FOAM_EDGE_BIAS, String.valueOf(Water.DEFAULT_FOAM_EDGE_BIAS)))); - water.setFloatAttribute(WaterFloatAttribute.FoamEdgeDistance, Float.parseFloat(MAP.get(PROP_FOAM_EDGE_DISTANCE, String.valueOf(Water.DEFAULT_FOAM_EDGE_DISTANCE)))); - water.setFloatAttribute(WaterFloatAttribute.FoamFallOffDistance, Float.parseFloat(MAP.get(PROP_FOAM_FALL_OFF_DISTANCE, String.valueOf(Water.DEFAULT_FOAM_FALL_OFF_DISTANCE)))); - water.setFloatAttribute(WaterFloatAttribute.FoamScrollSpeed, Float.parseFloat(MAP.get(PROP_FOAM_FALL_SCROLL_SPEED, String.valueOf(Water.DEFAULT_FOAM_SCROLL_SPEED)))); - water.setFloatAttribute(WaterFloatAttribute.Reflectivity, Float.parseFloat(MAP.get(PROP_REFLECTIVITY, String.valueOf(Water.DEFAULT_REFLECTIVITY)))); - water.setFloatAttribute(WaterFloatAttribute.ShineDamper, Float.parseFloat(MAP.get(PROP_SHINE_DAMPER, String.valueOf(Water.DEFAULT_SHINE_DAMPER)))); + water.setFloatAttribute(WaterFloatAttributeU.Tiling, Float.parseFloat(MAP.get(PROP_TILING, String.valueOf(Water.DEFAULT_TILING)))); + water.setFloatAttribute(WaterFloatAttributeU.WaveStrength, Float.parseFloat(MAP.get(PROP_WAVE_STRENGTH, String.valueOf(Water.DEFAULT_WAVE_STRENGTH)))); + water.setFloatAttribute(WaterFloatAttributeU.WaveSpeed, Float.parseFloat(MAP.get(PROP_WAVE_SPEED, String.valueOf(Water.DEFAULT_WAVE_SPEED)))); + water.setFloatAttribute(WaterFloatAttributeU.FoamPatternScale, Float.parseFloat(MAP.get(PROP_FOAM_SCALE, String.valueOf(Water.DEFAULT_FOAM_SCALE)))); + water.setFloatAttribute(WaterFloatAttributeU.FoamEdgeBias, Float.parseFloat(MAP.get(PROP_FOAM_EDGE_BIAS, String.valueOf(Water.DEFAULT_FOAM_EDGE_BIAS)))); + water.setFloatAttribute(WaterFloatAttributeU.FoamEdgeDistance, Float.parseFloat(MAP.get(PROP_FOAM_EDGE_DISTANCE, String.valueOf(Water.DEFAULT_FOAM_EDGE_DISTANCE)))); + water.setFloatAttribute(WaterFloatAttributeU.FoamFallOffDistance, Float.parseFloat(MAP.get(PROP_FOAM_FALL_OFF_DISTANCE, String.valueOf(Water.DEFAULT_FOAM_FALL_OFF_DISTANCE)))); + water.setFloatAttribute(WaterFloatAttributeU.FoamScrollSpeed, Float.parseFloat(MAP.get(PROP_FOAM_FALL_SCROLL_SPEED, String.valueOf(Water.DEFAULT_FOAM_SCROLL_SPEED)))); + water.setFloatAttribute(WaterFloatAttributeU.Reflectivity, Float.parseFloat(MAP.get(PROP_REFLECTIVITY, String.valueOf(Water.DEFAULT_REFLECTIVITY)))); + water.setFloatAttribute(WaterFloatAttributeU.ShineDamper, Float.parseFloat(MAP.get(PROP_SHINE_DAMPER, String.valueOf(Water.DEFAULT_SHINE_DAMPER)))); } catch (IOException e) { e.printStackTrace(); diff --git a/commons/src/main/com/mbrlabs/mundus/commons/scene3d/components/WaterComponent.java b/commons/src/main/com/mbrlabs/mundus/commons/scene3d/components/WaterComponent.java index 507ad2d70..82eedbed6 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/scene3d/components/WaterComponent.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/scene3d/components/WaterComponent.java @@ -22,7 +22,7 @@ import com.mbrlabs.mundus.commons.assets.Asset; import com.mbrlabs.mundus.commons.assets.WaterAsset; import com.mbrlabs.mundus.commons.scene3d.GameObject; -import com.mbrlabs.mundus.commons.water.WaterFloatAttribute; +import com.mbrlabs.mundus.commons.water.attributes.WaterFloatAttributeU; public class WaterComponent extends CullableComponent implements AssetUsage { @@ -56,17 +56,14 @@ public void setShader(Shader shader) { @Override public boolean usesAsset(Asset assetToCheck) { - if (assetToCheck == waterAsset) - return true; - - return false; + return assetToCheck == waterAsset; } @Override public void render(float delta) { super.render(delta); if (isCulled) return; - gameObject.sceneGraph.scene.batch.render(waterAsset.water, gameObject.sceneGraph.scene.environment, shader); + gameObject.sceneGraph.scene.batch.render(waterAsset.water, gameObject.sceneGraph.scene.environment); } @Override @@ -85,14 +82,14 @@ private void updateFoamScroll() { u_Offset = 0.0f; } - waterAsset.water.setFloatAttribute(WaterFloatAttribute.FoamUVOffset, u_Offset); + waterAsset.water.setFloatAttribute(WaterFloatAttributeU.FoamUVOffset, u_Offset); } private void updateMoveFactor() { - float waveSpeed = waterAsset.water.getFloatAttribute(WaterFloatAttribute.WaveSpeed); + float waveSpeed = waterAsset.water.getFloatAttribute(WaterFloatAttributeU.WaveSpeed); moveFactor += waveSpeed * Gdx.graphics.getDeltaTime(); moveFactor %= 1; - waterAsset.water.setFloatAttribute(WaterFloatAttribute.MoveFactor, moveFactor); + waterAsset.water.setFloatAttribute(WaterFloatAttributeU.MoveFactor, moveFactor); } @Override diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/MundusPBRShaderProvider.java b/commons/src/main/com/mbrlabs/mundus/commons/shaders/MundusPBRShaderProvider.java index 84e722940..c6e13aee1 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/shaders/MundusPBRShaderProvider.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/shaders/MundusPBRShaderProvider.java @@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.g3d.Renderable; import com.badlogic.gdx.graphics.g3d.Shader; import com.mbrlabs.mundus.commons.terrain.attributes.TerrainTextureAttribute; +import com.mbrlabs.mundus.commons.water.attributes.WaterMaterialAttribute; import net.mgsx.gltf.scene3d.shaders.PBRShader; import net.mgsx.gltf.scene3d.shaders.PBRShaderConfig; import net.mgsx.gltf.scene3d.shaders.PBRShaderProvider; @@ -22,6 +23,8 @@ public MundusPBRShaderProvider(PBRShaderConfig config) { protected Shader createShader(Renderable renderable) { if (renderable.material.has(TerrainTextureAttribute.ATTRIBUTE_SPLAT0)) return createTerrainShader(renderable); + else if (renderable.material.has(WaterMaterialAttribute.WaterMaterial)) + return createWaterShader(renderable); return super.createShader(renderable); } @@ -37,4 +40,11 @@ protected Shader createTerrainShader(Renderable renderable) { Gdx.app.log(MundusPBRShader.class.getSimpleName(), "Terrain Shader Compiled"); return shader; } + + private Shader createWaterShader(Renderable renderable) { + Shader shader = new WaterUberShader(renderable); + shaders.add(shader); + Gdx.app.log(MundusPBRShader.class.getSimpleName(), "Water Shader Compiled"); + return shader; + } } diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/TerrainUberShader.java b/commons/src/main/com/mbrlabs/mundus/commons/shaders/TerrainUberShader.java index ad48bcaee..7f95e8bfb 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/shaders/TerrainUberShader.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/shaders/TerrainUberShader.java @@ -163,7 +163,7 @@ public TerrainUberShader(Renderable renderable, DefaultShader.Config config) { TerrainTextureAttribute textureAttribute = renderable.material.get(TerrainTextureAttribute.class, TerrainTextureAttribute.ATTRIBUTE_SPLAT0); - attributesMask = combineAttributeMasks(renderable); + attributesMask = ShaderUtils.combineAttributeMasks(renderable); terrainTextureMask = textureAttribute.terrainTexture.getMask(); String prefix = createPrefixForRenderable(renderable); @@ -299,7 +299,7 @@ public int compareTo(Shader other) { @Override public boolean canRender(Renderable instance) { - if (combineAttributeMasks(instance) != attributesMask) { + if (ShaderUtils.combineAttributeMasks(instance) != attributesMask) { return false; } @@ -307,10 +307,4 @@ public boolean canRender(Renderable instance) { return terrainTextureMask == terrainTextureAttribute.terrainTexture.getMask(); } - private static long combineAttributeMasks (final Renderable renderable) { - long mask = 0; - if (renderable.environment != null) mask |= renderable.environment.getMask(); - if (renderable.material != null) mask |= renderable.material.getMask(); - return mask; - } } diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/WaterUberShader.java b/commons/src/main/com/mbrlabs/mundus/commons/shaders/WaterUberShader.java new file mode 100644 index 000000000..ebdf9c1a1 --- /dev/null +++ b/commons/src/main/com/mbrlabs/mundus/commons/shaders/WaterUberShader.java @@ -0,0 +1,294 @@ +package com.mbrlabs.mundus.commons.shaders; + +import com.badlogic.gdx.graphics.Camera; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.g3d.Attributes; +import com.badlogic.gdx.graphics.g3d.Renderable; +import com.badlogic.gdx.graphics.g3d.Shader; +import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute; +import com.badlogic.gdx.graphics.g3d.shaders.BaseShader; +import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader; +import com.badlogic.gdx.graphics.g3d.utils.RenderContext; +import com.badlogic.gdx.graphics.glutils.ShaderProgram; +import com.mbrlabs.mundus.commons.env.MundusEnvironment; +import com.mbrlabs.mundus.commons.utils.ShaderUtils; +import com.mbrlabs.mundus.commons.water.Water; +import com.mbrlabs.mundus.commons.water.WaterMaterial; +import com.mbrlabs.mundus.commons.water.attributes.WaterFloatAttributeU; +import com.mbrlabs.mundus.commons.water.attributes.WaterMaterialAttribute; +import com.mbrlabs.mundus.commons.water.attributes.WaterTextureAttributeU; +import net.mgsx.gltf.scene3d.attributes.FogAttribute; + +/** + * @author JamesTKhan + * @version October 16, 2022 + */ +public class WaterUberShader extends LightShader { + protected static final String VERTEX_SHADER = "com/mbrlabs/mundus/commons/shaders/water.uber.vert.glsl"; + protected static final String FRAGMENT_SHADER = "com/mbrlabs/mundus/commons/shaders/water.uber.frag.glsl"; + + public static class WaterInputs { + public final static Uniform diffuseUVTransform = new Uniform("u_diffuseUVTransform"); + + // Float attributes + public final static Uniform moveFactor = new Uniform("u_moveFactor"); + public final static Uniform tiling = new Uniform("u_tiling"); + public final static Uniform waveStrength = new Uniform("u_waveStrength"); + public final static Uniform reflectivity = new Uniform("u_reflectivity"); + public final static Uniform shineDamper = new Uniform("u_shineDamper"); + public final static Uniform foamScale = new Uniform("u_foamScale"); + public final static Uniform foamEdgeBias = new Uniform("u_foamEdgeBias"); + public final static Uniform foamEdgeDistance = new Uniform("u_foamEdgeDistance"); + public final static Uniform foamFallOffDistance = new Uniform("u_foamFallOffDistance"); + public final static Uniform foamScrollSpeed = new Uniform("u_foamScrollSpeed"); + + // Texture attributes + public final static Uniform reflectionTexture = new Uniform("u_reflectionTexture"); + public final static Uniform refractionTexture = new Uniform("u_refractionTexture"); + public final static Uniform refractionDepthTexture = new Uniform("u_refractionDepthTexture"); + public final static Uniform dudvTexture = new Uniform("u_dudvTexture"); + public final static Uniform normalMapTexture = new Uniform("u_normalMapTexture"); + public final static Uniform foamTexture = new Uniform("u_foamTexture"); + + public final static Uniform fogColor = new Uniform("u_fogColor"); + public final static Uniform fogEquation = new Uniform("u_fogEquation"); + } + + public static class WaterSetters { + public final static Setter diffuseUVTransform = new LocalSetter() { + @Override + public void set (BaseShader shader, int inputID, Renderable renderable, Attributes combinedAttributes) { + WaterMaterial mat = getWaterMaterial(renderable); + WaterFloatAttributeU attr = (WaterFloatAttributeU) mat.get(WaterFloatAttributeU.FoamUVOffset); + if (attr != null) + shader.set(inputID, attr.value, attr.value, 200f, 200f); + } + }; + + // Float attributes + public final static Setter moveFactor = new FloatSetter(WaterFloatAttributeU.MoveFactor, 0); + public final static Setter tiling = new FloatSetter(WaterFloatAttributeU.Tiling, Water.DEFAULT_TILING); + public final static Setter waveStrength = new FloatSetter(WaterFloatAttributeU.WaveStrength, Water.DEFAULT_WAVE_STRENGTH); + public final static Setter reflectivity = new FloatSetter(WaterFloatAttributeU.Reflectivity, Water.DEFAULT_REFLECTIVITY); + public final static Setter shineDamper = new FloatSetter(WaterFloatAttributeU.ShineDamper, Water.DEFAULT_SHINE_DAMPER); + public final static Setter foamScale = new FloatSetter(WaterFloatAttributeU.FoamPatternScale, Water.DEFAULT_FOAM_SCALE); + public final static Setter foamEdgeBias = new FloatSetter(WaterFloatAttributeU.FoamEdgeBias, Water.DEFAULT_FOAM_EDGE_BIAS); + public final static Setter foamEdgeDistance = new FloatSetter(WaterFloatAttributeU.FoamEdgeDistance, Water.DEFAULT_FOAM_EDGE_DISTANCE); + public final static Setter foamFallOffDistance = new FloatSetter(WaterFloatAttributeU.FoamFallOffDistance, Water.DEFAULT_FOAM_FALL_OFF_DISTANCE); + public final static Setter foamScrollSpeed = new FloatSetter(WaterFloatAttributeU.FoamScrollSpeed, Water.DEFAULT_FOAM_SCROLL_SPEED); + + // Texture attributes + public final static Setter reflectionTexture = getTextureSetter(WaterTextureAttributeU.Reflection); + public final static Setter refractionTexture = getTextureSetter(WaterTextureAttributeU.Refraction); + public final static Setter refractionDepthTexture = getTextureSetter(WaterTextureAttributeU.RefractionDepth); + public final static Setter dudvTexture = getTextureSetter(WaterTextureAttributeU.Dudv); + public final static Setter normalMapTexture = getTextureSetter(WaterTextureAttributeU.NormalMap); + public final static Setter foamTexture = getTextureSetter(WaterTextureAttributeU.Foam); + + private static Setter getTextureSetter(final long attribute) { + return new LocalSetter() { + @Override + public void set(BaseShader shader, int inputID, Renderable renderable, Attributes combinedAttributes) { + WaterMaterialAttribute waterMaterialAttribute = (WaterMaterialAttribute) combinedAttributes + .get(WaterMaterialAttribute.WaterMaterial); + WaterMaterial waterMaterial = waterMaterialAttribute.waterMaterial; + + WaterTextureAttributeU waterTextureAttributeU = waterMaterial.get(WaterTextureAttributeU.class, attribute); + final int unit = shader.context.textureBinder + .bind(waterTextureAttributeU.textureDescription); + shader.set(inputID, unit); + } + }; + } + + } + + /** + * Custom Setter that tracks the long attribute value and default value to set + */ + public static class FloatSetter extends LocalSetter { + private final long attribute; + private final float defaultValue; + + public FloatSetter(long attribute, float defaultValue) { + this.attribute = attribute; + this.defaultValue = defaultValue; + } + + @Override + public void set(BaseShader shader, int inputID, Renderable renderable, Attributes combinedAttributes) { + shader.set(inputID, getFloatValue(renderable, attribute, defaultValue)); + } + } + + // Global uniforms + public final int u_projViewTrans; + + // env + public final int u_fogColor; + public final int u_fogEquation; + + // Object uniforms + public final int u_worldTrans; + public final int u_cameraPosition; + public final int u_cameraNearFar; + + // Water float uniforms + public final int u_diffuseUVTransform; + public final int u_tiling; + public final int u_moveFactor; + public final int u_waveStrength; + public final int u_reflectivity; + public final int u_shineDamper; + public final int u_foamScale; + public final int u_foamEdgeBias; + public final int u_foamEdgeDistance; + public final int u_foamFallOffDistance; + public final int u_foamScrollSpeed; + + // Water texture uniforms + public final int u_reflectionTexture; + public final int u_refractionTexture; + public final int u_refractionDepthTexture; + public final int u_dudvTexture; + public final int u_normalMapTexture; + public final int u_foamTexture; + + /** The renderable used to create this shader, invalid after the call to init */ + private Renderable renderable; + + /** The attributes that this shader supports */ + protected final long attributesMask; + protected final long waterMaterialMask; + + public WaterUberShader(Renderable renderable) { + this.renderable = renderable; + + WaterMaterial waterMaterial = getWaterMaterial(renderable); + + attributesMask = ShaderUtils.combineAttributeMasks(renderable); + waterMaterialMask = waterMaterial.getMask(); + + String prefix = createPrefixForRenderable(renderable); + + // Compile the shaders + program = ShaderUtils.compile(VERTEX_SHADER, FRAGMENT_SHADER, this, prefix); + + u_projViewTrans = register(DefaultShader.Inputs.projViewTrans, DefaultShader.Setters.projViewTrans); + u_worldTrans = register(DefaultShader.Inputs.worldTrans, DefaultShader.Setters.worldTrans); + u_cameraPosition = register(DefaultShader.Inputs.cameraPosition, DefaultShader.Setters.cameraPosition); + u_cameraNearFar = register(DefaultShader.Inputs.cameraNearFar, DefaultShader.Setters.cameraNearFar); + + // Water specific + u_diffuseUVTransform = register(WaterInputs.diffuseUVTransform, WaterSetters.diffuseUVTransform); + u_tiling = register(WaterInputs.tiling, WaterSetters.tiling); + + u_moveFactor = register(WaterInputs.moveFactor, WaterSetters.moveFactor); + u_waveStrength = register(WaterInputs.waveStrength, WaterSetters.waveStrength); + u_reflectivity = register(WaterInputs.reflectivity, WaterSetters.reflectivity); + u_shineDamper = register(WaterInputs.shineDamper, WaterSetters.shineDamper); + u_foamScale = register(WaterInputs.foamScale, WaterSetters.foamScale); + u_foamEdgeBias = register(WaterInputs.foamEdgeBias, WaterSetters.foamEdgeBias); + u_foamEdgeDistance = register(WaterInputs.foamEdgeDistance, WaterSetters.foamEdgeDistance); + u_foamFallOffDistance = register(WaterInputs.foamFallOffDistance, WaterSetters.foamFallOffDistance); + u_foamScrollSpeed = register(WaterInputs.foamScrollSpeed, WaterSetters.foamScrollSpeed); + + u_reflectionTexture = register(WaterInputs.reflectionTexture, WaterSetters.reflectionTexture); + u_refractionTexture = register(WaterInputs.refractionTexture, WaterSetters.refractionTexture); + u_refractionDepthTexture = register(WaterInputs.refractionDepthTexture, WaterSetters.refractionDepthTexture); + u_dudvTexture = register(WaterInputs.dudvTexture, WaterSetters.dudvTexture); + u_normalMapTexture = register(WaterInputs.normalMapTexture, WaterSetters.normalMapTexture); + u_foamTexture = register(WaterInputs.foamTexture, WaterSetters.foamTexture); + + u_fogColor = register(WaterInputs.fogColor); + u_fogEquation = register(WaterInputs.fogEquation); + } + + @Override + public void init() { + final ShaderProgram program = this.program; + this.program = null; + this.init(program, renderable); + renderable = null; + } + + @Override + public void begin(Camera camera, RenderContext context) { + context.begin(); + context.setCullFace(GL20.GL_BACK); + + context.setDepthTest(GL20.GL_LEQUAL, 0f, 1f); + context.setDepthMask(true); + + super.begin(camera, context); + } + + @Override + public void render(Renderable renderable) { + final MundusEnvironment env = (MundusEnvironment) renderable.environment; + setLights(env); + + super.render(renderable); + } + + @Override + public void render(Renderable renderable, Attributes combinedAttributes) { + if (combinedAttributes.has(ColorAttribute.Fog) && combinedAttributes.has(FogAttribute.FogEquation)) { + set(u_fogColor, ((ColorAttribute)combinedAttributes.get(ColorAttribute.Fog)).color); + set(u_fogEquation, ((FogAttribute)combinedAttributes.get(FogAttribute.FogEquation)).value); + } + + super.render(renderable, combinedAttributes); + } + + @Override + public int compareTo(Shader other) { + if (other == null) return -1; + if (other == this) return 0; + return 0; // FIXME compare shaders on their impact on performance + } + + @Override + public boolean canRender(Renderable instance) { + if (ShaderUtils.combineAttributeMasks(instance) != attributesMask) { + return false; + } + + WaterMaterial waterMaterial = getWaterMaterial(instance); + return waterMaterialMask == waterMaterial.getMask(); + } + + private static float getFloatValue(Renderable renderable, long attribute, float defaultValue) { + WaterMaterial waterMaterial = getWaterMaterial(renderable); + WaterFloatAttributeU attr = (WaterFloatAttributeU) waterMaterial.get(attribute); + if (attr != null) { + return attr.value; + } else { + return defaultValue; + } + } + + private static WaterMaterial getWaterMaterial(Renderable renderable) { + return renderable.material.get(WaterMaterialAttribute.class, WaterMaterialAttribute.WaterMaterial).waterMaterial; + } + + private String createPrefixForRenderable(Renderable renderable) { + String prefix = ""; + + if (renderable.environment.has(ColorAttribute.Fog)) { + prefix += "#define fogFlag\n"; + } + + WaterMaterial waterMaterial = getWaterMaterial(renderable); + + if (waterMaterial.has(WaterTextureAttributeU.Reflection)) { + prefix += "#define reflectionFlag\n"; + } + + if (waterMaterial.has(WaterTextureAttributeU.Refraction)) { + prefix += "#define refractionFlag\n"; + } + + return prefix; + } +} diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.uber.frag.glsl b/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.uber.frag.glsl new file mode 100644 index 000000000..3bf987c64 --- /dev/null +++ b/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.uber.frag.glsl @@ -0,0 +1,240 @@ +#ifdef GL_ES +#define LOW lowp +#define MED mediump +#define HIGH highp +precision highp float; +#else +#define MED +#define LOW +#define HIGH +#endif + +varying MED vec2 v_texCoord0; +varying vec2 v_waterTexCoords; +varying vec4 v_clipSpace; +varying vec3 v_toCameraVector; +varying vec2 v_diffuseUV; + +#ifdef reflectionFlag +uniform sampler2D u_reflectionTexture; +#endif + +#ifdef refractionFlag +uniform sampler2D u_refractionTexture; +#endif + +uniform sampler2D u_refractionDepthTexture; +uniform sampler2D u_dudvTexture; +uniform sampler2D u_normalMapTexture; +uniform sampler2D u_foamTexture; +uniform MED float u_waveStrength; +uniform MED float u_moveFactor; +uniform MED float u_shineDamper; +uniform MED float u_reflectivity; +uniform MED float u_foamScale; +uniform MED float u_foamEdgeBias; +uniform MED float u_foamEdgeDistance; +uniform MED float u_foamFallOffDistance; +uniform MED float u_foamScrollSpeed; +uniform vec2 u_cameraNearFar; + +const vec4 COLOR_TURQUOISE = vec4(0,0.5,0.686, 0.2); + +#ifdef fogFlag +uniform vec3 u_fogEquation; +uniform MED vec4 u_fogColor; +#endif + +//https://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/ +float DecodeFloatRGBA( vec4 rgba ) { + return dot( rgba, vec4(1.0, 1.0/255.0, 1.0/65025.0, 1.0/16581375.0) ); +} + +vec3 calcSpecularHighlights(BaseLight baseLight, vec3 direction, vec3 normal, vec3 viewVector, float waterDepth) { + vec3 reflectedLight = reflect(normalize(direction), normal); + float specular = max(dot(reflectedLight, viewVector), 0.0); + specular = pow(specular, u_shineDamper); + vec3 specularHighlights = vec3(baseLight.Color) * baseLight.DiffuseIntensity * specular * u_reflectivity * clamp(waterDepth/5.0, 0.0, 1.0); + + return specularHighlights; +} + +void main() { + + // Normalized device coordinates + vec2 ndc = (v_clipSpace.xy/v_clipSpace.w)/2.0 + 0.5; + vec2 refractTexCoords = vec2(ndc.x, ndc.y); + + float near = u_cameraNearFar.x; + float far = u_cameraNearFar.y; + float depth = DecodeFloatRGBA(texture2D(u_refractionDepthTexture, refractTexCoords)); + float floorDistance = 2.0 * near * far / (far + near - (2.0 * depth - 1.0) * (far - near)); + + depth = gl_FragCoord.z; + float waterDistance = 2.0 * near * far / (far + near - (2.0 * depth - 1.0) * (far - near)); + float waterDepth = floorDistance - waterDistance; + + // Dudv distortion + vec2 distortedTexCoords = texture2D(u_dudvTexture, vec2(v_waterTexCoords.x + u_moveFactor, v_waterTexCoords.y)).rg*0.1; + distortedTexCoords = v_waterTexCoords + vec2(distortedTexCoords.x, distortedTexCoords.y+u_moveFactor); + vec2 totalDistortion = (texture2D(u_dudvTexture, distortedTexCoords).rg * 2.0 - 1.0) * u_waveStrength * clamp(waterDepth/20.0, 0.0, 1.0); + + float minTexCoord = 0.005; + float maxTexCoord = 1.0 - minTexCoord; + + // Normal map + vec4 normalMapColor = texture2D(u_normalMapTexture, distortedTexCoords); + vec3 normal = vec3(normalMapColor.r * 2.0 - 1.0, normalMapColor.b * 3.0, normalMapColor.g * 2.0 - 1.0); + normal = normalize(normal); + + // Sample textures with distortion + #ifdef reflectionFlag + vec2 reflectTexCoords = vec2(ndc.x, 1.0-ndc.y); + reflectTexCoords = reflectTexCoords + totalDistortion; + reflectTexCoords.x = clamp(reflectTexCoords.x, 0.001, 0.999); + reflectTexCoords.y = clamp(reflectTexCoords.y, 0.001, 0.999); + + vec4 reflectColor = texture2D(u_reflectionTexture, reflectTexCoords); + #else + vec4 reflectColor = vec4(0); + #endif + + #ifdef refractionFlag + refractTexCoords = refractTexCoords + totalDistortion; + refractTexCoords = clamp(refractTexCoords, 0.001, 0.999); + + vec4 refractColor = texture2D(u_refractionTexture, refractTexCoords); + #endif + + // Fresnel Effect + vec3 viewVector = normalize(v_toCameraVector); + float refractiveFactor = dot(viewVector, normal); + + #ifdef reflectionFlag + + #ifdef refractionFlag + // If we have both Reflection and Reflection, blend based on fresnel effect + vec4 color = mix(reflectColor, refractColor, refractiveFactor); + #else + // No Refraction but we have reflection + vec4 color = reflectColor; + #endif + + #else + + #ifdef refractionFlag + // No Reflection but we have refraction + vec4 color = refractColor; + #else + // We have neither reflection or refraction + vec4 color = COLOR_TURQUOISE; + #endif + + #endif + + // Mix some color in + color = mix(color, COLOR_TURQUOISE, 0.2); + + // Water Foam implemented from http://fire-face.com/personal/water/ + float edgePatternScroll = u_moveFactor * u_foamScrollSpeed; + vec4 edgeFalloffColor = vec4(0.8,0.8,0.8,0.6); + + vec2 scaledUV = v_diffuseUV * u_foamScale; + + // Calculate linear falloff value + float falloff = 1.0 - (waterDepth / u_foamFallOffDistance) + u_foamEdgeBias; + + vec2 coords = v_texCoord0 + totalDistortion; + + // Sample the mask + float channelA = texture2D(u_foamTexture, scaledUV - vec2(edgePatternScroll, cos(coords.x))).r; + float channelB = texture2D(u_foamTexture, scaledUV * 0.5 + vec2(sin(coords.y), edgePatternScroll)).b; + + // Modify it to our liking + float mask = (channelA + channelB) * 0.95; + mask = pow(mask, 2.0); + mask = clamp(mask, 0.0, 1.0); + + // Is this pixel in the leading edge? + if(waterDepth < u_foamFallOffDistance * u_foamEdgeDistance) + { + // Modulate the surface alpha and the mask strength + float leading = waterDepth / (u_foamFallOffDistance * u_foamEdgeDistance); + color.a *= leading; + mask *= leading; + } + + // Color the foam, blend based on alpha + vec3 edge = edgeFalloffColor.rgb * falloff * edgeFalloffColor.a; + + // This is a workaround fix to resolve an issue when using packed depth that causes white borders on water + // so if the red channel is full 1.0 its probably pure white (border) so we ignore it. + if (edge.r < 0.99) { + // Fade foam out after a distance, otherwise we get ugly 1 pixel lines + float distanceToCam = length(v_worldPos - u_cameraPosition.xyz); + float foamVisibleFactor = clamp(1.0 - distanceToCam / 500.0, 0.0, 1.0); + + // Subtract mask value from foam gradient, then add the foam value to the final pixel color + color.rgb += clamp(edge - vec3(mask), 0.0, 1.0) * foamVisibleFactor; + } + + // Get directional light + vec4 totalLight = CalcDirectionalLight(normal); + + // Calculate specular hightlights for directional light + vec3 specularHighlights = calcSpecularHighlights(u_directionalLight.Base, u_directionalLight.Direction, normal, viewVector, waterDepth); + + // Calculate specular and lighting for point lights + for (int i = 0 ; i < numPointLights ; i++) { + if (i >= u_activeNumPointLights){break;} + vec4 lightColor = vec4(u_pointLights[i].Base.Color, 1.0) * u_pointLights[i].Base.DiffuseIntensity; + + vec3 lightDirection = v_worldPos - u_pointLights[i].LocalPos; + float dist = length(lightDirection); + lightDirection = normalize(lightDirection); + + float attenuation = u_pointLights[i].Atten.Constant + + u_pointLights[i].Atten.Linear * dist + + u_pointLights[i].Atten.Exp * dist * dist; + + float specularDistanceFactor = length(u_cameraPosition.xyz - u_pointLights[i].LocalPos); + + // Limit distance of point lights specular highlights over water by 500 units + specularDistanceFactor = clamp(1.0 - specularDistanceFactor / 500.0, 0.0, 1.0); + + // We want specular to adjust based on attenuation, but not to the same degree otherwise we lose too much + float specularAttenuationFactor = 0.1; + + // Add point light contribution to specular highlights + specularHighlights += (calcSpecularHighlights(u_pointLights[i].Base, lightDirection, normal, viewVector, waterDepth) * specularDistanceFactor) / (attenuation * specularAttenuationFactor); + + // Apply point light colors to overall color + totalLight += lightColor / attenuation; + } + + for (int i = 0; i < numSpotLights; i++) { + if (i >= u_activeNumSpotLights){break;} + totalLight += CalcSpotLight(u_spotLights[i], normal); + } + + // Apply all lighting + color *= totalLight; + + // Apply final specular values + color += vec4(specularHighlights, 0.0); + + // Fog + #ifdef fogFlag + if (u_fogEquation.z > 0.0) { + float fog = (waterDistance - u_fogEquation.x) / (u_fogEquation.y - u_fogEquation.x); + fog = clamp(fog, 0.0, 1.0); + fog = pow(fog, u_fogEquation.z); + + color.rgb = mix(color.rgb, u_fogColor.rgb, fog * u_fogColor.a); + } + #endif + + gl_FragColor = color; + //gl_FragColor = vec4(waterDepth/50.0); + //gl_FragColor.a = clamp(waterDepth/5.0, 0.0, 1.0); +} \ No newline at end of file diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.uber.vert.glsl b/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.uber.vert.glsl new file mode 100644 index 000000000..b575fafb9 --- /dev/null +++ b/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.uber.vert.glsl @@ -0,0 +1,41 @@ +#ifdef GL_ES +precision highp float; +#endif + +attribute vec3 a_position; +attribute vec3 a_normal; +attribute vec2 a_texCoord0; + +// Default Uniforms +uniform mat4 u_worldTrans; +uniform mat4 u_projViewTrans; +uniform vec4 u_cameraPosition; + +// Water uniforms +uniform vec4 u_diffuseUVTransform; +uniform float u_tiling; + +varying vec2 v_diffuseUV; +varying vec2 v_texCoord0; +varying vec2 v_waterTexCoords; +varying vec4 v_clipSpace; +varying vec3 v_toCameraVector; +varying vec3 v_worldPos; +varying vec3 v_shadowMapUv; + +void main() { + vec4 worldPos = u_worldTrans * vec4(a_position, 1.0); + v_worldPos = worldPos.xyz; + + v_shadowMapUv = vec3(0.0); + + v_clipSpace = u_projViewTrans * worldPos; + gl_Position = v_clipSpace; + + v_texCoord0 = a_texCoord0; + v_diffuseUV = u_diffuseUVTransform.xy + a_texCoord0 * u_diffuseUVTransform.zw; + + v_waterTexCoords = vec2(a_position.x/2.0 + 0.5, a_position.z/2.0 + 0.5) * u_tiling; + + v_toCameraVector = u_cameraPosition.xyz - worldPos.xyz; +} \ No newline at end of file diff --git a/commons/src/main/com/mbrlabs/mundus/commons/terrain/attributes/TerrainAttribute.java b/commons/src/main/com/mbrlabs/mundus/commons/terrain/attributes/TerrainAttribute.java index 60e323eda..045c6859d 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/terrain/attributes/TerrainAttribute.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/terrain/attributes/TerrainAttribute.java @@ -1,5 +1,7 @@ package com.mbrlabs.mundus.commons.terrain.attributes; +import com.mbrlabs.mundus.commons.MundusAttribute; + /** * @author JamesTKhan * @version August 13, 2022 diff --git a/commons/src/main/com/mbrlabs/mundus/commons/terrain/attributes/TerrainAttributes.java b/commons/src/main/com/mbrlabs/mundus/commons/terrain/attributes/TerrainAttributes.java index 93b44ceb0..938a6fae3 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/terrain/attributes/TerrainAttributes.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/terrain/attributes/TerrainAttributes.java @@ -1,6 +1,7 @@ package com.mbrlabs.mundus.commons.terrain.attributes; import com.badlogic.gdx.utils.Array; +import com.mbrlabs.mundus.commons.MundusAttribute; import java.util.Comparator; import java.util.Iterator; diff --git a/commons/src/main/com/mbrlabs/mundus/commons/utils/ShaderUtils.java b/commons/src/main/com/mbrlabs/mundus/commons/utils/ShaderUtils.java index 671f3cebb..3db87b63f 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/utils/ShaderUtils.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/utils/ShaderUtils.java @@ -19,6 +19,7 @@ import com.badlogic.gdx.Application; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.g3d.Renderable; import com.badlogic.gdx.graphics.g3d.Shader; import com.badlogic.gdx.graphics.g3d.shaders.DepthShader; import com.badlogic.gdx.graphics.glutils.ShaderProgram; @@ -133,4 +134,17 @@ public static DepthShader.Config buildPBRShaderDepthConfig(int numBones) { return depthConfig; } + /** + * Combine the environment and material of the renderable to create a bitmask. + * + * @param renderable renderable to combine masks for + * @return mask of environment and material + */ + public static long combineAttributeMasks(final Renderable renderable) { + long mask = 0; + if (renderable.environment != null) mask |= renderable.environment.getMask(); + if (renderable.material != null) mask |= renderable.material.getMask(); + return mask; + } + } diff --git a/commons/src/main/com/mbrlabs/mundus/commons/water/Water.java b/commons/src/main/com/mbrlabs/mundus/commons/water/Water.java index 9c4e3fe61..de48d598f 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/water/Water.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/water/Water.java @@ -11,6 +11,9 @@ import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.utils.Pool; +import com.mbrlabs.mundus.commons.water.attributes.WaterFloatAttributeU; +import com.mbrlabs.mundus.commons.water.attributes.WaterMaterialAttribute; +import com.mbrlabs.mundus.commons.water.attributes.WaterTextureAttributeU; public class Water implements RenderableProvider, Disposable { public static final int DEFAULT_SIZE = 1600; @@ -31,8 +34,7 @@ public class Water implements RenderableProvider, Disposable { public int waterWidth; public int waterDepth; - // Textures - private Material material; + private WaterMaterial waterMaterial; // Mesh private Model model; @@ -62,19 +64,23 @@ public void init() { modelInstance.transform = transform; // Hold reference to the material - material = modelInstance.getMaterial(materialId); + waterMaterial = new WaterMaterial(); + + // Attach our custom water material to the main material + Material material = modelInstance.getMaterial(materialId); + material.set(WaterMaterialAttribute.createWaterMaterialAttribute(waterMaterial)); // Set default values - setFloatAttribute(WaterFloatAttribute.Tiling, DEFAULT_TILING); - setFloatAttribute(WaterFloatAttribute.WaveStrength, DEFAULT_WAVE_STRENGTH); - setFloatAttribute(WaterFloatAttribute.WaveSpeed, DEFAULT_WAVE_SPEED); - setFloatAttribute(WaterFloatAttribute.FoamPatternScale, Water.DEFAULT_FOAM_SCALE); - setFloatAttribute(WaterFloatAttribute.FoamScrollSpeed, Water.DEFAULT_FOAM_SCROLL_SPEED); - setFloatAttribute(WaterFloatAttribute.FoamEdgeDistance, Water.DEFAULT_FOAM_EDGE_DISTANCE); - setFloatAttribute(WaterFloatAttribute.FoamEdgeBias, Water.DEFAULT_FOAM_EDGE_BIAS); - setFloatAttribute(WaterFloatAttribute.FoamFallOffDistance, Water.DEFAULT_FOAM_FALL_OFF_DISTANCE); - setFloatAttribute(WaterFloatAttribute.Reflectivity, DEFAULT_REFLECTIVITY); - setFloatAttribute(WaterFloatAttribute.ShineDamper, DEFAULT_SHINE_DAMPER); + setFloatAttribute(WaterFloatAttributeU.Tiling, DEFAULT_TILING); + setFloatAttribute(WaterFloatAttributeU.WaveStrength, DEFAULT_WAVE_STRENGTH); + setFloatAttribute(WaterFloatAttributeU.WaveSpeed, DEFAULT_WAVE_SPEED); + setFloatAttribute(WaterFloatAttributeU.FoamPatternScale, Water.DEFAULT_FOAM_SCALE); + setFloatAttribute(WaterFloatAttributeU.FoamScrollSpeed, Water.DEFAULT_FOAM_SCROLL_SPEED); + setFloatAttribute(WaterFloatAttributeU.FoamEdgeDistance, Water.DEFAULT_FOAM_EDGE_DISTANCE); + setFloatAttribute(WaterFloatAttributeU.FoamEdgeBias, Water.DEFAULT_FOAM_EDGE_BIAS); + setFloatAttribute(WaterFloatAttributeU.FoamFallOffDistance, Water.DEFAULT_FOAM_FALL_OFF_DISTANCE); + setFloatAttribute(WaterFloatAttributeU.Reflectivity, DEFAULT_REFLECTIVITY); + setFloatAttribute(WaterFloatAttributeU.ShineDamper, DEFAULT_SHINE_DAMPER); } @Override @@ -88,34 +94,34 @@ public void dispose() { } public void setWaterReflection(Texture texture) { - material.set(new WaterTextureAttribute(WaterTextureAttribute.Reflection, texture)); + waterMaterial.set(new WaterTextureAttributeU(WaterTextureAttributeU.Reflection, texture)); } public void setFoamTexture(Texture texture) { - material.set(new WaterTextureAttribute(WaterTextureAttribute.Foam, texture)); + waterMaterial.set(new WaterTextureAttributeU(WaterTextureAttributeU.Foam, texture)); } public void setDudvTexture(Texture texture) { - material.set(new WaterTextureAttribute(WaterTextureAttribute.Dudv, texture)); + waterMaterial.set(new WaterTextureAttributeU(WaterTextureAttributeU.Dudv, texture)); } public void setNormalMap(Texture texture) { - material.set(new WaterTextureAttribute(WaterTextureAttribute.NormalMap, texture)); + waterMaterial.set(new WaterTextureAttributeU(WaterTextureAttributeU.NormalMap, texture)); } public void setWaterRefractionTexture(Texture texture) { - material.set(new WaterTextureAttribute(WaterTextureAttribute.Refraction, texture)); + waterMaterial.set(new WaterTextureAttributeU(WaterTextureAttributeU.Refraction, texture)); } public void setWaterRefractionDepthTexture(Texture texture) { - material.set(new WaterTextureAttribute(WaterTextureAttribute.RefractionDepth, texture)); + waterMaterial.set(new WaterTextureAttributeU(WaterTextureAttributeU.RefractionDepth, texture)); } public void setFloatAttribute(long attributeType, float value) { - material.set(new WaterFloatAttribute(attributeType, value)); + waterMaterial.set(new WaterFloatAttributeU(attributeType, value)); } public float getFloatAttribute(long attributeType) { - return material.get(WaterFloatAttribute.class, attributeType).value; + return waterMaterial.get(WaterFloatAttributeU.class, attributeType).value; } } diff --git a/commons/src/main/com/mbrlabs/mundus/commons/water/WaterMaterial.java b/commons/src/main/com/mbrlabs/mundus/commons/water/WaterMaterial.java new file mode 100644 index 000000000..917a5d302 --- /dev/null +++ b/commons/src/main/com/mbrlabs/mundus/commons/water/WaterMaterial.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright 2011 See AUTHORS file. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package com.mbrlabs.mundus.commons.water; + +import com.badlogic.gdx.utils.Array; +import com.mbrlabs.mundus.commons.MundusAttribute; +import com.mbrlabs.mundus.commons.water.attributes.WaterAttributes; + +public class WaterMaterial extends WaterAttributes { + private static int counter = 0; + + public String id; + + /** Create an empty material */ + public WaterMaterial() { + this("mtl" + (++counter)); + } + + /** Create an empty material */ + public WaterMaterial(final String id) { + this.id = id; + } + + /** Create a material with the specified attributes */ + public WaterMaterial(final MundusAttribute... attributes) { + this(); + set(attributes); + } + + /** Create a material with the specified attributes */ + public WaterMaterial(final String id, final MundusAttribute... attributes) { + this(id); + set(attributes); + } + + /** Create a material with the specified attributes */ + public WaterMaterial(final Array attributes) { + this(); + set(attributes); + } + + /** Create a material with the specified attributes */ + public WaterMaterial(final String id, final Array attributes) { + this(id); + set(attributes); + } + + /** Create a material which is an exact copy of the specified material */ + public WaterMaterial(final WaterMaterial copyFrom) { + this(copyFrom.id, copyFrom); + } + + /** Create a material which is an exact copy of the specified material */ + public WaterMaterial(final String id, final WaterMaterial copyFrom) { + this(id); + for (MundusAttribute attr : copyFrom) + set(attr.copy()); + } + + /** Create a copy of this material */ + public WaterMaterial copy () { + return new WaterMaterial(this); + } + + @Override + public int hashCode () { + return super.hashCode() + 3 * id.hashCode(); + } + + @Override + public boolean equals (Object other) { + return (other instanceof WaterMaterial) && ((other == this) || ((((WaterMaterial)other).id.equals(id)) && super.equals(other))); + } +} diff --git a/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterAttributes.java b/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterAttributes.java new file mode 100644 index 000000000..c9629ffe9 --- /dev/null +++ b/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterAttributes.java @@ -0,0 +1,223 @@ +package com.mbrlabs.mundus.commons.water.attributes; + +import com.badlogic.gdx.utils.Array; +import com.mbrlabs.mundus.commons.MundusAttribute; + +import java.util.Comparator; +import java.util.Iterator; + +/** + * Copied from libGDX Attributes, due to 64 attribute limit in libGDX. + * @author JamesTKhan + * @version August 13, 2022 + */ +public class WaterAttributes implements Iterable, Comparator, Comparable { + protected long mask; + protected final Array MundusAttributes = new Array(); + + protected boolean sorted = true; + + /** Sort the MundusAttributes by their ID */ + public final void sort () { + if (!sorted) { + MundusAttributes.sort(this); + sorted = true; + } + } + + /** @return Bitwise mask of the ID's of all the containing MundusAttributes */ + public final long getMask () { + return mask; + } + + /** Example usage: ((BlendingMundusAttribute)material.get(BlendingMundusAttribute.ID)).sourceFunction; + * @return The MundusAttribute (which can safely be cast) if any, otherwise null */ + public final MundusAttribute get (final long type) { + if (has(type)) for (int i = 0; i < MundusAttributes.size; i++) + if (MundusAttributes.get(i).type == type) return MundusAttributes.get(i); + return null; + } + + /** Example usage: ((BlendingMundusAttribute)material.get(BlendingMundusAttribute.ID)).sourceFunction; + * @return The MundusAttribute if any, otherwise null */ + public final T get (Class clazz, final long type) { + return (T)get(type); + } + + /** Get multiple MundusAttributes at once. Example: material.get(out, ColorMundusAttribute.Diffuse | ColorMundusAttribute.Specular | + * TextureMundusAttribute.Diffuse); */ + public final Array get (final Array out, final long type) { + for (int i = 0; i < MundusAttributes.size; i++) + if ((MundusAttributes.get(i).type & type) != 0) out.add(MundusAttributes.get(i)); + return out; + } + + /** Removes all MundusAttributes */ + public void clear () { + mask = 0; + MundusAttributes.clear(); + } + + /** @return The amount of MundusAttributes this material contains. */ + public int size () { + return MundusAttributes.size; + } + + private final void enable (final long mask) { + this.mask |= mask; + } + + private final void disable (final long mask) { + this.mask &= ~mask; + } + + /** Add a MundusAttribute to this material. If the material already contains an MundusAttribute of the same type it is overwritten. */ + public final void set (final MundusAttribute MundusAttribute) { + final int idx = indexOf(MundusAttribute.type); + if (idx < 0) { + enable(MundusAttribute.type); + MundusAttributes.add(MundusAttribute); + sorted = false; + } else { + MundusAttributes.set(idx, MundusAttribute); + } + sort(); //FIXME: See #4186 + } + + /** Add multiple MundusAttributes to this material. If the material already contains an MundusAttribute of the same type it is overwritten. */ + public final void set (final MundusAttribute MundusAttribute1, final MundusAttribute MundusAttribute2) { + set(MundusAttribute1); + set(MundusAttribute2); + } + + /** Add multiple MundusAttributes to this material. If the material already contains an MundusAttribute of the same type it is overwritten. */ + public final void set (final MundusAttribute MundusAttribute1, final MundusAttribute MundusAttribute2, final MundusAttribute MundusAttribute3) { + set(MundusAttribute1); + set(MundusAttribute2); + set(MundusAttribute3); + } + + /** Add multiple MundusAttributes to this material. If the material already contains an MundusAttribute of the same type it is overwritten. */ + public final void set (final MundusAttribute MundusAttribute1, final MundusAttribute MundusAttribute2, final MundusAttribute MundusAttribute3, + final MundusAttribute MundusAttribute4) { + set(MundusAttribute1); + set(MundusAttribute2); + set(MundusAttribute3); + set(MundusAttribute4); + } + + /** Add an array of MundusAttributes to this material. If the material already contains an MundusAttribute of the same type it is + * overwritten. */ + public final void set (final MundusAttribute... MundusAttributes) { + for (final MundusAttribute attr : MundusAttributes) + set(attr); + } + + /** Add an array of MundusAttributes to this material. If the material already contains an MundusAttribute of the same type it is + * overwritten. */ + public final void set (final Iterable MundusAttributes) { + for (final MundusAttribute attr : MundusAttributes) + set(attr); + } + + /** Removes the MundusAttribute from the material, i.e.: material.remove(BlendingMundusAttribute.ID); Can also be used to remove multiple + * MundusAttributes also, i.e. remove(MundusAttributeA.ID | MundusAttributeB.ID); */ + public final void remove (final long mask) { + for (int i = MundusAttributes.size - 1; i >= 0; i--) { + final long type = MundusAttributes.get(i).type; + if ((mask & type) == type) { + MundusAttributes.removeIndex(i); + disable(type); + sorted = false; + } + } + sort(); //FIXME: See #4186 + } + + /** @return True if this collection has the specified MundusAttribute, i.e. MundusAttributes.has(ColorMundusAttribute.Diffuse); Or when multiple + * MundusAttribute types are specified, true if this collection has all specified MundusAttributes, i.e. MundusAttributes.has(out, + * ColorMundusAttribute.Diffuse | ColorMundusAttribute.Specular | TextureMundusAttribute.Diffuse); */ + public final boolean has (final long type) { + return type != 0 && (this.mask & type) == type; + } + + /** @return the index of the MundusAttribute with the specified type or negative if not available. */ + protected int indexOf (final long type) { + if (has(type)) for (int i = 0; i < MundusAttributes.size; i++) + if (MundusAttributes.get(i).type == type) return i; + return -1; + } + + /** Check if this collection has the same MundusAttributes as the other collection. If compareValues is true, it also compares the + * values of each MundusAttribute. + * @param compareValues True to compare MundusAttribute values, false to only compare MundusAttribute types + * @return True if this collection contains the same MundusAttributes (and optionally MundusAttribute values) as the other. */ + public final boolean same (final WaterAttributes other, boolean compareValues) { + if (other == this) return true; + if ((other == null) || (mask != other.mask)) return false; + if (!compareValues) return true; + sort(); + other.sort(); + for (int i = 0; i < MundusAttributes.size; i++) + if (!MundusAttributes.get(i).equals(other.MundusAttributes.get(i))) return false; + return true; + } + + /** See {@link #same(WaterAttributes, boolean)} + * @return True if this collection contains the same MundusAttributes (but not values) as the other. */ + public final boolean same (final WaterAttributes other) { + return same(other, false); + } + + /** Used for sorting MundusAttributes by type (not by value) */ + @Override + public final int compare (final MundusAttribute arg0, final MundusAttribute arg1) { + return (int)(arg0.type - arg1.type); + } + + /** Used for iterating through the MundusAttributes */ + @Override + public final Iterator iterator () { + return MundusAttributes.iterator(); + } + + /** @return A hash code based on only the MundusAttribute values, which might be different compared to {@link #hashCode()} because the latter + * might include other properties as well, i.e. the material id. */ + public int MundusAttributesHash () { + sort(); + final int n = MundusAttributes.size; + long result = 71 + mask; + int m = 1; + for (int i = 0; i < n; i++) + result += mask * MundusAttributes.get(i).hashCode() * (m = (m * 7) & 0xFFFF); + return (int)(result ^ (result >> 32)); + } + + @Override + public int hashCode () { + return MundusAttributesHash(); + } + + @Override + public boolean equals (Object other) { + if (!(other instanceof WaterAttributes)) return false; + if (other == this) return true; + return same((WaterAttributes)other, true); + } + + @Override + public int compareTo (WaterAttributes other) { + if (other == this) + return 0; + if (mask != other.mask) + return mask < other.mask ? -1 : 1; + sort(); + other.sort(); + for (int i = 0; i < MundusAttributes.size; i++) { + final int c = MundusAttributes.get(i).compareTo(other.MundusAttributes.get(i)); + if (c != 0) + return c < 0 ? -1 : (c > 0 ? 1 : 0); + } + return 0; + } +} diff --git a/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterFloatAttributeU.java b/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterFloatAttributeU.java new file mode 100644 index 000000000..bf6fd28d3 --- /dev/null +++ b/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterFloatAttributeU.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright 2011 See AUTHORS file. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package com.mbrlabs.mundus.commons.water.attributes; + +import com.badlogic.gdx.math.MathUtils; +import com.badlogic.gdx.utils.NumberUtils; +import com.mbrlabs.mundus.commons.MundusAttribute; + +public class WaterFloatAttributeU extends MundusAttribute { + public static final String TilingAlias = "tiling"; + public static final long Tiling = register(TilingAlias); + + public static final String WaveStrengthAlias = "waveStrength"; + public static final long WaveStrength = register(WaveStrengthAlias); + + public static final String WaveSpeedAlias = "waveSpeed"; + public static final long WaveSpeed = register(WaveSpeedAlias); + + public static final String ReflectivityAlias = "reflectivity"; + public static final long Reflectivity = register(ReflectivityAlias); + + public static final String ShineDamperAlias = "shineDamper"; + public static final long ShineDamper = register(ShineDamperAlias); + + public static final String FoamPatternScaleAlias = "foamPatternScale"; + public static final long FoamPatternScale = register(FoamPatternScaleAlias); + + public static final String FoamEdgeBiasAlias = "foamEdgeBias"; + public static final long FoamEdgeBias = register(FoamEdgeBiasAlias); + + public static final String FoamScrollSpeedAlias = "foamScrollSpeed"; + public static final long FoamScrollSpeed = register(FoamScrollSpeedAlias); + + public static final String FoamFallOffDistanceAlias = "foamFallOffDistance"; + public static final long FoamFallOffDistance = register(FoamFallOffDistanceAlias); + + public static final String FoamEdgeDistanceAlias = "foamEdgeDistance"; + public static final long FoamEdgeDistance = register(FoamEdgeDistanceAlias); + + public static final String FoamUVOffsetAlias = "foamUVOffset"; + public static final long FoamUVOffset = register(FoamUVOffsetAlias); + + public static final String MoveFactorAlias = "moveFactor"; + public static final long MoveFactor = register(MoveFactorAlias); + + public float value; + + public WaterFloatAttributeU(long type) { + super(type); + } + + public WaterFloatAttributeU(long type, float value) { + super(type); + this.value = value; + } + + @Override + public MundusAttribute copy () { + return new WaterFloatAttributeU(type, value); + } + + @Override + public int hashCode () { + int result = super.hashCode(); + result = 977 * result + NumberUtils.floatToRawIntBits(value); + return result; + } + + @Override + public int compareTo (MundusAttribute o) { + if (type != o.type) return (int)(type - o.type); + final float v = ((WaterFloatAttributeU)o).value; + return MathUtils.isEqual(value, v) ? 0 : value < v ? -1 : 1; + } +} diff --git a/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterMaterialAttribute.java b/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterMaterialAttribute.java new file mode 100644 index 000000000..0603a2ff8 --- /dev/null +++ b/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterMaterialAttribute.java @@ -0,0 +1,53 @@ +package com.mbrlabs.mundus.commons.water.attributes; + +import com.badlogic.gdx.graphics.g3d.Attribute; +import com.mbrlabs.mundus.commons.terrain.TerrainTexture; +import com.mbrlabs.mundus.commons.terrain.attributes.TerrainTextureAttribute; +import com.mbrlabs.mundus.commons.water.WaterMaterial; + +/** + * A standard libGDX attribute to hold our WaterMaterial + * + * @author JamesTKhan + * @version August 15, 2022 + */ +public class WaterMaterialAttribute extends Attribute { + public final static String WaterMaterialAlias = "waterData"; + public final static long WaterMaterial = register(WaterMaterialAlias); + + protected static long Mask = WaterMaterial; + + public WaterMaterial waterMaterial; + + /** + * Method to check whether the specified type is a valid DoubleAttribute + * type + */ + public static Boolean is(final long type) { + return (type & Mask) != 0; + } + + protected WaterMaterialAttribute(long type) { + super(type); + } + + public WaterMaterialAttribute(long type, WaterMaterial waterMaterial) { + super(type); + this.waterMaterial = waterMaterial; + } + + public static WaterMaterialAttribute createWaterMaterialAttribute(WaterMaterial waterMaterial) { + return new WaterMaterialAttribute(WaterMaterial, waterMaterial); + } + @Override + public Attribute copy() { + return new WaterMaterialAttribute(this.type); + } + + @Override + public int compareTo(Attribute o) { + if (type != o.type) return type < o.type ? -1 : 1; + WaterMaterialAttribute otherValue = ((WaterMaterialAttribute) o); + return waterMaterial.equals(otherValue.waterMaterial) ? 0 : -1; + } +} diff --git a/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterTextureAttributeU.java b/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterTextureAttributeU.java new file mode 100644 index 000000000..bf473030d --- /dev/null +++ b/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterTextureAttributeU.java @@ -0,0 +1,130 @@ +package com.mbrlabs.mundus.commons.water.attributes; + +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.graphics.g3d.Attribute; +import com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor; +import com.badlogic.gdx.math.MathUtils; +import com.badlogic.gdx.utils.GdxRuntimeException; +import com.badlogic.gdx.utils.NumberUtils; +import com.mbrlabs.mundus.commons.MundusAttribute; +/** + * @author JamesTKhan + * @version October 16, 2022 + */ +public class WaterTextureAttributeU extends MundusAttribute { + public final static String DudvAlias = "dudvTexture"; + public final static long Dudv = register(DudvAlias); + + public final static String NormalMapAlias = "waterNormalMap"; + public final static long NormalMap = register(NormalMapAlias); + + public final static String ReflectionAlias = "reflection"; + public final static long Reflection = register(ReflectionAlias); + + public final static String FoamAlias = "waterFoam"; + public final static long Foam = register(FoamAlias); + + public final static String RefractionAlias = "refraction"; + public final static long Refraction = register(RefractionAlias); + + public final static String RefractionDepthAlias = "refractionDepth"; + public final static long RefractionDepth = register(RefractionDepthAlias); + + protected static long Mask = Dudv | NormalMap | Reflection | Foam | Refraction | RefractionDepth; + + public final static boolean is (final long mask) { + return (mask & Mask) != 0; + } + + public final TextureDescriptor textureDescription; + public float offsetU = 0; + public float offsetV = 0; + public float scaleU = 1; + public float scaleV = 1; + /** The index of the texture coordinate vertex attribute to use for this TextureAttribute. Whether this value is used, depends + * on the shader and {@link Attribute#type} value. For basic (model specific) types + * etc.), this value is usually ignored and the first texture coordinate vertex attribute is used. */ + public int uvIndex = 0; + + public WaterTextureAttributeU(final long type) { + super(type); + if (!is(type)) throw new GdxRuntimeException("Invalid type specified"); + textureDescription = new TextureDescriptor(); + } + + public WaterTextureAttributeU(final long type, final TextureDescriptor textureDescription) { + this(type); + this.textureDescription.set(textureDescription); + } + + public WaterTextureAttributeU(final long type, final TextureDescriptor textureDescription, float offsetU, + float offsetV, float scaleU, float scaleV, int uvIndex) { + this(type, textureDescription); + this.offsetU = offsetU; + this.offsetV = offsetV; + this.scaleU = scaleU; + this.scaleV = scaleV; + this.uvIndex = uvIndex; + } + + public WaterTextureAttributeU(final long type, final TextureDescriptor textureDescription, float offsetU, + float offsetV, float scaleU, float scaleV) { + this(type, textureDescription, offsetU, offsetV, scaleU, scaleV, 0); + } + + public WaterTextureAttributeU(final long type, final Texture texture) { + this(type); + textureDescription.texture = texture; + } + + public WaterTextureAttributeU(final long type, final TextureRegion region) { + this(type); + set(region); + } + + public WaterTextureAttributeU(final WaterTextureAttributeU copyFrom) { + this(copyFrom.type, copyFrom.textureDescription, copyFrom.offsetU, copyFrom.offsetV, copyFrom.scaleU, copyFrom.scaleV, + copyFrom.uvIndex); + } + + public void set (final TextureRegion region) { + textureDescription.texture = region.getTexture(); + offsetU = region.getU(); + offsetV = region.getV(); + scaleU = region.getU2() - offsetU; + scaleV = region.getV2() - offsetV; + } + + @Override + public MundusAttribute copy () { + return new WaterTextureAttributeU(this); + } + + @Override + public int hashCode () { + int result = super.hashCode(); + result = 991 * result + textureDescription.hashCode(); + result = 991 * result + NumberUtils.floatToRawIntBits(offsetU); + result = 991 * result + NumberUtils.floatToRawIntBits(offsetV); + result = 991 * result + NumberUtils.floatToRawIntBits(scaleU); + result = 991 * result + NumberUtils.floatToRawIntBits(scaleV); + result = 991 * result + uvIndex; + return result; + } + + @Override + public int compareTo (MundusAttribute o) { + if (type != o.type) return type < o.type ? -1 : 1; + WaterTextureAttributeU other = (WaterTextureAttributeU)o; + final int c = textureDescription.compareTo(other.textureDescription); + if (c != 0) return c; + if (uvIndex != other.uvIndex) return uvIndex - other.uvIndex; + if (!MathUtils.isEqual(scaleU, other.scaleU)) return scaleU > other.scaleU ? 1 : -1; + if (!MathUtils.isEqual(scaleV, other.scaleV)) return scaleV > other.scaleV ? 1 : -1; + if (!MathUtils.isEqual(offsetU, other.offsetU)) return offsetU > other.offsetU ? 1 : -1; + if (!MathUtils.isEqual(offsetV, other.offsetV)) return offsetV > other.offsetV ? 1 : -1; + return 0; + } +} + diff --git a/editor/src/main/com/mbrlabs/mundus/editor/assets/EditorAssetManager.kt b/editor/src/main/com/mbrlabs/mundus/editor/assets/EditorAssetManager.kt index 145c37e0a..14bc912c2 100644 --- a/editor/src/main/com/mbrlabs/mundus/editor/assets/EditorAssetManager.kt +++ b/editor/src/main/com/mbrlabs/mundus/editor/assets/EditorAssetManager.kt @@ -40,7 +40,7 @@ import com.mbrlabs.mundus.commons.assets.meta.MetaTerrain import com.mbrlabs.mundus.commons.scene3d.GameObject import com.mbrlabs.mundus.commons.scene3d.components.AssetUsage import com.mbrlabs.mundus.commons.utils.FileFormatUtils -import com.mbrlabs.mundus.commons.water.WaterFloatAttribute +import com.mbrlabs.mundus.commons.water.attributes.WaterFloatAttributeU import com.mbrlabs.mundus.editor.Mundus.postEvent import com.mbrlabs.mundus.editor.core.project.ProjectManager import com.mbrlabs.mundus.editor.events.LogEvent @@ -753,18 +753,18 @@ class EditorAssetManager(assetsRoot: FileHandle) : AssetManager(assetsRoot) { props.setProperty(WaterAsset.PROP_DUDV, asset.dudvTexture.id) props.setProperty(WaterAsset.PROP_NORMAL_MAP, asset.normalMapTexture.id) - props.setProperty(WaterAsset.PROP_TILING, asset.water.getFloatAttribute(WaterFloatAttribute.Tiling).toString()) - props.setProperty(WaterAsset.PROP_WAVE_STRENGTH, asset.water.getFloatAttribute(WaterFloatAttribute.WaveStrength).toString()) - props.setProperty(WaterAsset.PROP_WAVE_SPEED, asset.water.getFloatAttribute(WaterFloatAttribute.WaveSpeed).toString()) + props.setProperty(WaterAsset.PROP_TILING, asset.water.getFloatAttribute(WaterFloatAttributeU.Tiling).toString()) + props.setProperty(WaterAsset.PROP_WAVE_STRENGTH, asset.water.getFloatAttribute(WaterFloatAttributeU.WaveStrength).toString()) + props.setProperty(WaterAsset.PROP_WAVE_SPEED, asset.water.getFloatAttribute(WaterFloatAttributeU.WaveSpeed).toString()) - props.setProperty(WaterAsset.PROP_FOAM_SCALE, asset.water.getFloatAttribute(WaterFloatAttribute.FoamPatternScale).toString()) - props.setProperty(WaterAsset.PROP_FOAM_EDGE_BIAS, asset.water.getFloatAttribute(WaterFloatAttribute.FoamEdgeBias).toString()) - props.setProperty(WaterAsset.PROP_FOAM_EDGE_DISTANCE, asset.water.getFloatAttribute(WaterFloatAttribute.FoamEdgeDistance).toString()) - props.setProperty(WaterAsset.PROP_FOAM_FALL_OFF_DISTANCE, asset.water.getFloatAttribute(WaterFloatAttribute.FoamFallOffDistance).toString()) - props.setProperty(WaterAsset.PROP_FOAM_FALL_SCROLL_SPEED, asset.water.getFloatAttribute(WaterFloatAttribute.FoamScrollSpeed).toString()) + props.setProperty(WaterAsset.PROP_FOAM_SCALE, asset.water.getFloatAttribute(WaterFloatAttributeU.FoamPatternScale).toString()) + props.setProperty(WaterAsset.PROP_FOAM_EDGE_BIAS, asset.water.getFloatAttribute(WaterFloatAttributeU.FoamEdgeBias).toString()) + props.setProperty(WaterAsset.PROP_FOAM_EDGE_DISTANCE, asset.water.getFloatAttribute(WaterFloatAttributeU.FoamEdgeDistance).toString()) + props.setProperty(WaterAsset.PROP_FOAM_FALL_OFF_DISTANCE, asset.water.getFloatAttribute(WaterFloatAttributeU.FoamFallOffDistance).toString()) + props.setProperty(WaterAsset.PROP_FOAM_FALL_SCROLL_SPEED, asset.water.getFloatAttribute(WaterFloatAttributeU.FoamScrollSpeed).toString()) - props.setProperty(WaterAsset.PROP_REFLECTIVITY, asset.water.getFloatAttribute(WaterFloatAttribute.Reflectivity).toString()) - props.setProperty(WaterAsset.PROP_SHINE_DAMPER, asset.water.getFloatAttribute(WaterFloatAttribute.ShineDamper).toString()) + props.setProperty(WaterAsset.PROP_REFLECTIVITY, asset.water.getFloatAttribute(WaterFloatAttributeU.Reflectivity).toString()) + props.setProperty(WaterAsset.PROP_SHINE_DAMPER, asset.water.getFloatAttribute(WaterFloatAttributeU.ShineDamper).toString()) val fileOutputStream = FileOutputStream(asset.file.file()) props.store(fileOutputStream, null) diff --git a/editor/src/main/com/mbrlabs/mundus/editor/ui/widgets/WaterWidget.kt b/editor/src/main/com/mbrlabs/mundus/editor/ui/widgets/WaterWidget.kt index 51a61d650..cc7264976 100644 --- a/editor/src/main/com/mbrlabs/mundus/editor/ui/widgets/WaterWidget.kt +++ b/editor/src/main/com/mbrlabs/mundus/editor/ui/widgets/WaterWidget.kt @@ -13,8 +13,8 @@ import com.kotcrab.vis.ui.widget.VisTextButton import com.kotcrab.vis.ui.widget.VisTextField import com.mbrlabs.mundus.commons.scene3d.components.WaterComponent import com.mbrlabs.mundus.commons.water.Water -import com.mbrlabs.mundus.commons.water.WaterFloatAttribute import com.mbrlabs.mundus.commons.water.WaterResolution +import com.mbrlabs.mundus.commons.water.attributes.WaterFloatAttributeU import com.mbrlabs.mundus.editor.Mundus import com.mbrlabs.mundus.editor.core.project.ProjectManager import com.mbrlabs.mundus.editor.events.LogEvent @@ -127,16 +127,16 @@ class WaterWidget(val waterComponent: WaterComponent) : VisTable() { add(resetDefaults).padTop(10f).growX().row() // Register listeners for the float fields - registerFloatFieldListener(tilingField, WaterFloatAttribute.Tiling) - registerFloatFieldListener(waveStrength, WaterFloatAttribute.WaveStrength) - registerFloatFieldListener(waveSpeed, WaterFloatAttribute.WaveSpeed) - registerFloatFieldListener(foamPatternScale, WaterFloatAttribute.FoamPatternScale) - registerFloatFieldListener(foamEdgeBias, WaterFloatAttribute.FoamEdgeBias) - registerFloatFieldListener(foamScrollSpeedFactor, WaterFloatAttribute.FoamScrollSpeed) - registerFloatFieldListener(foamEdgeDistance, WaterFloatAttribute.FoamEdgeDistance) - registerFloatFieldListener(foamFallOffDistance, WaterFloatAttribute.FoamFallOffDistance) - registerFloatFieldListener(reflectivity, WaterFloatAttribute.Reflectivity) - registerFloatFieldListener(shineDamper, WaterFloatAttribute.ShineDamper) + registerFloatFieldListener(tilingField, WaterFloatAttributeU.Tiling) + registerFloatFieldListener(waveStrength, WaterFloatAttributeU.WaveStrength) + registerFloatFieldListener(waveSpeed, WaterFloatAttributeU.WaveSpeed) + registerFloatFieldListener(foamPatternScale, WaterFloatAttributeU.FoamPatternScale) + registerFloatFieldListener(foamEdgeBias, WaterFloatAttributeU.FoamEdgeBias) + registerFloatFieldListener(foamScrollSpeedFactor, WaterFloatAttributeU.FoamScrollSpeed) + registerFloatFieldListener(foamEdgeDistance, WaterFloatAttributeU.FoamEdgeDistance) + registerFloatFieldListener(foamFallOffDistance, WaterFloatAttributeU.FoamFallOffDistance) + registerFloatFieldListener(reflectivity, WaterFloatAttributeU.Reflectivity) + registerFloatFieldListener(shineDamper, WaterFloatAttributeU.ShineDamper) // resolution selectBox.addListener(object : ChangeListener() { @@ -148,16 +148,16 @@ class WaterWidget(val waterComponent: WaterComponent) : VisTable() { resetDefaults.addListener(object : ClickListener() { override fun clicked(event: InputEvent?, x: Float, y: Float) { - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.Tiling, Water.DEFAULT_TILING) - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.WaveStrength, Water.DEFAULT_WAVE_STRENGTH) - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.WaveSpeed, Water.DEFAULT_WAVE_SPEED) - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.Reflectivity, Water.DEFAULT_REFLECTIVITY) - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.ShineDamper, Water.DEFAULT_SHINE_DAMPER) - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.FoamPatternScale, Water.DEFAULT_FOAM_SCALE) - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.FoamScrollSpeed, Water.DEFAULT_FOAM_SCROLL_SPEED) - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.FoamEdgeDistance, Water.DEFAULT_FOAM_EDGE_DISTANCE) - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.FoamEdgeBias, Water.DEFAULT_FOAM_EDGE_BIAS) - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.FoamFallOffDistance, Water.DEFAULT_FOAM_FALL_OFF_DISTANCE) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.Tiling, Water.DEFAULT_TILING) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.WaveStrength, Water.DEFAULT_WAVE_STRENGTH) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.WaveSpeed, Water.DEFAULT_WAVE_SPEED) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.Reflectivity, Water.DEFAULT_REFLECTIVITY) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.ShineDamper, Water.DEFAULT_SHINE_DAMPER) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.FoamPatternScale, Water.DEFAULT_FOAM_SCALE) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.FoamScrollSpeed, Water.DEFAULT_FOAM_SCROLL_SPEED) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.FoamEdgeDistance, Water.DEFAULT_FOAM_EDGE_DISTANCE) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.FoamEdgeBias, Water.DEFAULT_FOAM_EDGE_BIAS) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.FoamFallOffDistance, Water.DEFAULT_FOAM_FALL_OFF_DISTANCE) projectManager.current().currScene.settings.waterResolution = WaterResolution.DEFAULT_WATER_RESOLUTION projectManager.current().assetManager.addModifiedAsset(waterComponent.waterAsset) @@ -186,16 +186,16 @@ class WaterWidget(val waterComponent: WaterComponent) : VisTable() { } fun setFieldsToCurrentValues() { - tilingField.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.Tiling).toString() - waveStrength.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.WaveStrength).toString() - waveSpeed.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.WaveSpeed).toString() - reflectivity.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.Reflectivity).toString() - shineDamper.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.ShineDamper).toString() - foamPatternScale.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.FoamPatternScale).toString() - foamEdgeBias.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.FoamEdgeBias).toString() - foamScrollSpeedFactor.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.FoamScrollSpeed).toString() - foamFallOffDistance.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.FoamFallOffDistance).toString() - foamEdgeDistance.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.FoamEdgeDistance).toString() + tilingField.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.Tiling).toString() + waveStrength.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.WaveStrength).toString() + waveSpeed.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.WaveSpeed).toString() + reflectivity.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.Reflectivity).toString() + shineDamper.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.ShineDamper).toString() + foamPatternScale.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.FoamPatternScale).toString() + foamEdgeBias.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.FoamEdgeBias).toString() + foamScrollSpeedFactor.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.FoamScrollSpeed).toString() + foamFallOffDistance.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.FoamFallOffDistance).toString() + foamEdgeDistance.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.FoamEdgeDistance).toString() if (!selectBox.items.contains(projectManager.current().currScene.settings.waterResolution.value)) { selectBox.selected = WaterResolution.DEFAULT_WATER_RESOLUTION.value From 32aa4692e9b15495dcfee3ae52493f9ddc944f43 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 17 Oct 2022 08:25:34 -0400 Subject: [PATCH 2/4] Remove legacy water shader --- .../mundus/commons/shaders/WaterShader.java | 186 ------------------ .../commons/water/WaterFloatAttribute.java | 45 ----- .../commons/water/WaterTextureAttribute.java | 51 ----- .../converter/WaterComponentConverter.java | 2 +- .../mbrlabs/mundus/editor/shader/Shaders.kt | 5 - .../modules/outline/OutlineRightClickMenu.kt | 3 +- .../mbrlabs/mundus/editor/utils/WaterUtils.kt | 8 +- .../com/mbrlabs/mundus/runtime/Shaders.java | 8 - .../converter/GameObjectConverter.java | 2 +- .../converter/WaterComponentConverter.java | 6 +- 10 files changed, 9 insertions(+), 307 deletions(-) delete mode 100644 commons/src/main/com/mbrlabs/mundus/commons/shaders/WaterShader.java delete mode 100644 commons/src/main/com/mbrlabs/mundus/commons/water/WaterFloatAttribute.java delete mode 100644 commons/src/main/com/mbrlabs/mundus/commons/water/WaterTextureAttribute.java diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/WaterShader.java b/commons/src/main/com/mbrlabs/mundus/commons/shaders/WaterShader.java deleted file mode 100644 index 9eaad216f..000000000 --- a/commons/src/main/com/mbrlabs/mundus/commons/shaders/WaterShader.java +++ /dev/null @@ -1,186 +0,0 @@ -package com.mbrlabs.mundus.commons.shaders; - -import com.badlogic.gdx.graphics.Camera; -import com.badlogic.gdx.graphics.GL20; -import com.badlogic.gdx.graphics.g3d.Renderable; -import com.badlogic.gdx.graphics.g3d.Shader; -import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute; -import com.badlogic.gdx.graphics.g3d.utils.RenderContext; -import com.badlogic.gdx.graphics.glutils.ShaderProgram; -import com.badlogic.gdx.math.Vector3; -import com.mbrlabs.mundus.commons.env.MundusEnvironment; -import com.mbrlabs.mundus.commons.utils.ShaderUtils; -import com.mbrlabs.mundus.commons.water.Water; -import com.mbrlabs.mundus.commons.water.WaterFloatAttribute; -import com.mbrlabs.mundus.commons.water.WaterTextureAttribute; -import net.mgsx.gltf.scene3d.attributes.FogAttribute; - -public class WaterShader extends LightShader { - - protected static final String VERTEX_SHADER = "com/mbrlabs/mundus/commons/shaders/water.vert.glsl"; - protected static final String FRAGMENT_SHADER = "com/mbrlabs/mundus/commons/shaders/water.frag.glsl"; - - // ============================ MATRICES & CAM POSITION ============================ - protected final int UNIFORM_PROJ_VIEW_MATRIX = register(new Uniform("u_projViewMatrix")); - protected final int UNIFORM_TRANS_MATRIX = register(new Uniform("u_transMatrix")); - protected final int UNIFORM_CAM_POS = register(new Uniform("u_cameraPosition")); - protected final int UNIFORM_DIFFUSE_UV = register(new Uniform("u_diffuseUVTransform")); - - // ============================ TEXTURES ============================ - protected final int UNIFORM_TEXTURE = register(new Uniform("u_texture")); - public final int UNIFORM_REFRACTION_TEXTURE = register(new Uniform("u_refractionTexture")); - public final int UNIFORM_REFRACTION_DEPTH_TEXTURE = register(new Uniform("u_refractionDepthTexture")); - protected final int UNIFORM_DUDV_TEXTURE = register(new Uniform("u_dudvTexture")); - protected final int UNIFORM_NORMAL_MAP_TEXTURE = register(new Uniform("u_normalMapTexture")); - protected final int UNIFORM_FOAM_TEXTURE = register(new Uniform("u_foamTexture")); - - // ============================ FLOATS ============================ - protected final int UNIFORM_CLIP_PLANE = register(new Uniform("u_clipPlane")); - protected final int UNIFORM_MOVE_FACTOR = register(new Uniform("u_moveFactor")); - protected final int UNIFORM_TILING = register(new Uniform("u_tiling")); - protected final int UNIFORM_WAVE_STRENGTH = register(new Uniform("u_waveStrength")); - protected final int UNIFORM_SPECULAR_REFLECTIVITY = register(new Uniform("u_reflectivity")); - protected final int UNIFORM_SHINE_DAMPER = register(new Uniform("u_shineDamper")); - protected final int UNIFORM_FOAM_SCALE = register(new Uniform("u_foamScale")); - protected final int UNIFORM_FOAM_EDGE_BIAS = register(new Uniform("u_foamEdgeBias")); - protected final int UNIFORM_FOAM_EDGE_DISTANCE = register(new Uniform("u_foamEdgeDistance")); - protected final int UNIFORM_FOAM_FALL_OFF_DISTANCE = register(new Uniform("u_foamFallOffDistance")); - protected final int UNIFORM_FOAM_FALL_SCROLL_SPEED = register(new Uniform("u_foamScrollSpeed")); - protected final int UNIFORM_CAM_NEAR_PLANE= register(new Uniform("u_camNearPlane")); - protected final int UNIFORM_CAM_FAR_PLANE= register(new Uniform("u_camFarPlane")); - - // ============================ FOG ============================ - protected final int UNIFORM_FOG_EQUATION = register(new Uniform("u_fogEquation")); - protected final int UNIFORM_FOG_COLOR = register(new Uniform("u_fogColor")); - - - public ShaderProgram program; - - - public WaterShader() { - program = ShaderUtils.compile(VERTEX_SHADER, FRAGMENT_SHADER, this); - } - - @Override - public void init() { - super.init(program, null); - } - - @Override - public int compareTo(Shader other) { - return 0; - } - - @Override - public boolean canRender(Renderable instance) { - return true; - } - - @Override - public void begin(Camera camera, RenderContext context) { - this.context = context; - - context.begin(); - context.setCullFace(GL20.GL_BACK); - - this.context.setDepthTest(GL20.GL_LEQUAL, 0f, 1f); - this.context.setDepthMask(true); - - program.bind(); - - set(UNIFORM_PROJ_VIEW_MATRIX, camera.combined); - set(UNIFORM_CAM_NEAR_PLANE, camera.near); - set(UNIFORM_CAM_FAR_PLANE, camera.far); - set(UNIFORM_CAM_POS, camera.position.x, camera.position.y, camera.position.z, - 1.1881f / (camera.far * camera.far)); - } - - @Override - public void render(Renderable renderable) { - final MundusEnvironment env = (MundusEnvironment) renderable.environment; - - setLights(env); - - // Set Textures - WaterTextureAttribute dudvAttrib = (WaterTextureAttribute) renderable.material.get(WaterTextureAttribute.Dudv); - if (dudvAttrib != null) { - set(UNIFORM_DUDV_TEXTURE, dudvAttrib.getTexture()); - } - - WaterTextureAttribute normalAttrib = (WaterTextureAttribute) renderable.material.get(WaterTextureAttribute.NormalMap); - if (normalAttrib != null) { - set(UNIFORM_NORMAL_MAP_TEXTURE, normalAttrib.getTexture()); - } - - WaterTextureAttribute reflectTexture = (WaterTextureAttribute) renderable.material.get(WaterTextureAttribute.Reflection); - if (reflectTexture != null) { - set(UNIFORM_TEXTURE, reflectTexture.getTexture()); - } - - WaterTextureAttribute refractTexture = (WaterTextureAttribute) renderable.material.get(WaterTextureAttribute.Refraction); - if (refractTexture != null) { - set(UNIFORM_REFRACTION_TEXTURE, refractTexture.getTexture()); - } - - WaterTextureAttribute refractDepthTexture = (WaterTextureAttribute) renderable.material.get(WaterTextureAttribute.RefractionDepth); - if (refractDepthTexture != null) { - set(UNIFORM_REFRACTION_DEPTH_TEXTURE, refractDepthTexture.getTexture()); - } - - WaterTextureAttribute foamTexture = (WaterTextureAttribute) renderable.material.get(WaterTextureAttribute.Foam); - if (foamTexture != null) { - set(UNIFORM_FOAM_TEXTURE, foamTexture.getTexture()); - } - - setFloatUniform(renderable, WaterFloatAttribute.Tiling, UNIFORM_TILING, Water.DEFAULT_TILING); - setFloatUniform(renderable, WaterFloatAttribute.WaveStrength, UNIFORM_WAVE_STRENGTH, Water.DEFAULT_WAVE_STRENGTH); - setFloatUniform(renderable, WaterFloatAttribute.Reflectivity, UNIFORM_SPECULAR_REFLECTIVITY, Water.DEFAULT_REFLECTIVITY); - setFloatUniform(renderable, WaterFloatAttribute.ShineDamper, UNIFORM_SHINE_DAMPER, Water.DEFAULT_SHINE_DAMPER); - setFloatUniform(renderable, WaterFloatAttribute.FoamPatternScale, UNIFORM_FOAM_SCALE, Water.DEFAULT_FOAM_SCALE); - setFloatUniform(renderable, WaterFloatAttribute.FoamEdgeBias, UNIFORM_FOAM_EDGE_BIAS, Water.DEFAULT_FOAM_EDGE_BIAS); - setFloatUniform(renderable, WaterFloatAttribute.FoamEdgeDistance, UNIFORM_FOAM_EDGE_DISTANCE, Water.DEFAULT_FOAM_EDGE_DISTANCE); - setFloatUniform(renderable, WaterFloatAttribute.FoamFallOffDistance, UNIFORM_FOAM_FALL_OFF_DISTANCE, Water.DEFAULT_FOAM_FALL_OFF_DISTANCE); - setFloatUniform(renderable, WaterFloatAttribute.FoamScrollSpeed, UNIFORM_FOAM_FALL_SCROLL_SPEED, Water.DEFAULT_FOAM_SCROLL_SPEED); - setFloatUniform(renderable, WaterFloatAttribute.MoveFactor, UNIFORM_MOVE_FACTOR, 0); - - WaterFloatAttribute uvOffset = (WaterFloatAttribute) renderable.material.get(WaterFloatAttribute.FoamUVOffset); - if (uvOffset != null) { - set(UNIFORM_DIFFUSE_UV, uvOffset.value, uvOffset.value, 200f, 200f); - } - - set(UNIFORM_TRANS_MATRIX, renderable.worldTransform); - - // Fog - FogAttribute fogEquation = renderable.environment.get(FogAttribute.class, FogAttribute.FogEquation); - ColorAttribute colorAttribute = renderable.environment.get(ColorAttribute.class, ColorAttribute.Fog); - if (fogEquation != null && colorAttribute != null) { - set(UNIFORM_FOG_EQUATION, fogEquation.value); - set(UNIFORM_FOG_COLOR, colorAttribute.color); - } else { - set(UNIFORM_FOG_EQUATION, Vector3.Zero); - } - - // bind attributes, bind mesh & render; then unbinds everything - renderable.meshPart.render(program); - } - - private void setFloatUniform(Renderable renderable, long attribute, int uniform, float defaultValue) { - WaterFloatAttribute attr = (WaterFloatAttribute) renderable.material.get(attribute); - if (attr != null) { - set(uniform, attr.value); - } else { - set(uniform, defaultValue); - } - } - - @Override - public void end() { - context.end(); - } - - @Override - public void dispose() { - program.dispose(); - } - -} diff --git a/commons/src/main/com/mbrlabs/mundus/commons/water/WaterFloatAttribute.java b/commons/src/main/com/mbrlabs/mundus/commons/water/WaterFloatAttribute.java deleted file mode 100644 index 237edb8c7..000000000 --- a/commons/src/main/com/mbrlabs/mundus/commons/water/WaterFloatAttribute.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.mbrlabs.mundus.commons.water; - -import com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute; - -public class WaterFloatAttribute extends FloatAttribute { - public static final String TilingAlias = "tiling"; - public static final long Tiling = register(TilingAlias); - - public static final String WaveStrengthAlias = "waveStrength"; - public static final long WaveStrength = register(WaveStrengthAlias); - - public static final String WaveSpeedAlias = "waveSpeed"; - public static final long WaveSpeed = register(WaveSpeedAlias); - - public static final String ReflectivityAlias = "reflectivity"; - public static final long Reflectivity = register(ReflectivityAlias); - - public static final String ShineDamperAlias = "shineDamper"; - public static final long ShineDamper = register(ShineDamperAlias); - - public static final String FoamPatternScaleAlias = "foamPatternScale"; - public static final long FoamPatternScale = register(FoamPatternScaleAlias); - - public static final String FoamEdgeBiasAlias = "foamEdgeBias"; - public static final long FoamEdgeBias = register(FoamEdgeBiasAlias); - - public static final String FoamScrollSpeedAlias = "foamScrollSpeed"; - public static final long FoamScrollSpeed = register(FoamScrollSpeedAlias); - - public static final String FoamFallOffDistanceAlias = "foamFallOffDistance"; - public static final long FoamFallOffDistance = register(FoamFallOffDistanceAlias); - - public static final String FoamEdgeDistanceAlias = "foamEdgeDistance"; - public static final long FoamEdgeDistance = register(FoamEdgeDistanceAlias); - - public static final String FoamUVOffsetAlias = "foamUVOffset"; - public static final long FoamUVOffset = register(FoamUVOffsetAlias); - - public static final String MoveFactorAlias = "moveFactor"; - public static final long MoveFactor = register(MoveFactorAlias); - - public WaterFloatAttribute(long type, float value) { - super(type, value); - } -} diff --git a/commons/src/main/com/mbrlabs/mundus/commons/water/WaterTextureAttribute.java b/commons/src/main/com/mbrlabs/mundus/commons/water/WaterTextureAttribute.java deleted file mode 100644 index 1eb9cf6b1..000000000 --- a/commons/src/main/com/mbrlabs/mundus/commons/water/WaterTextureAttribute.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.mbrlabs.mundus.commons.water; - - -import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g3d.Attribute; - -public class WaterTextureAttribute extends Attribute { - public final static String DudvAlias = "dudvTexture"; - public final static long Dudv = register(DudvAlias); - - public final static String NormalMapAlias = "waterNormalMap"; - public final static long NormalMap = register(NormalMapAlias); - - public final static String ReflectionAlias = "reflection"; - public final static long Reflection = register(ReflectionAlias); - - public final static String FoamAlias = "waterFoam"; - public final static long Foam = register(FoamAlias); - - public final static String RefractionAlias = "refraction"; - public final static long Refraction = register(RefractionAlias); - - public final static String RefractionDepthAlias = "refractionDepth"; - public final static long RefractionDepth = register(RefractionDepthAlias); - - private Texture texture; - - protected WaterTextureAttribute(long type, Texture texture) { - super(type); - this.texture = texture; - } - - public Texture getTexture() { - return texture; - } - - public void setTexture(Texture texture) { - this.texture = texture; - } - - @Override - public Attribute copy() { - //todo - return null; - } - - @Override - public int compareTo(Attribute o) { - return 0; - } -} diff --git a/editor/src/main/com/mbrlabs/mundus/editor/core/converter/WaterComponentConverter.java b/editor/src/main/com/mbrlabs/mundus/editor/core/converter/WaterComponentConverter.java index 523caa4ae..022eea23f 100644 --- a/editor/src/main/com/mbrlabs/mundus/editor/core/converter/WaterComponentConverter.java +++ b/editor/src/main/com/mbrlabs/mundus/editor/core/converter/WaterComponentConverter.java @@ -47,7 +47,7 @@ public static PickableWaterComponent convert(WaterComponentDTO dto, GameObject g } water.water.transform = go.getTransform(); - PickableWaterComponent waterComponent = new PickableWaterComponent(go, Shaders.INSTANCE.getWaterShader()); + PickableWaterComponent waterComponent = new PickableWaterComponent(go, null); waterComponent.setWaterAsset(water); go.hasWaterComponent = true; diff --git a/editor/src/main/com/mbrlabs/mundus/editor/shader/Shaders.kt b/editor/src/main/com/mbrlabs/mundus/editor/shader/Shaders.kt index 728893a96..bb64ee794 100644 --- a/editor/src/main/com/mbrlabs/mundus/editor/shader/Shaders.kt +++ b/editor/src/main/com/mbrlabs/mundus/editor/shader/Shaders.kt @@ -21,7 +21,6 @@ import com.badlogic.gdx.utils.Disposable import com.mbrlabs.mundus.commons.shaders.DepthShader import com.mbrlabs.mundus.commons.shaders.ShadowMapShader import com.mbrlabs.mundus.commons.shaders.SkyboxShader -import com.mbrlabs.mundus.commons.shaders.WaterShader import com.mbrlabs.mundus.editor.tools.picker.PickerShader /** @@ -32,7 +31,6 @@ import com.mbrlabs.mundus.editor.tools.picker.PickerShader object Shaders : Disposable { val wireframeShader: WireframeShader - val waterShader: WaterShader val skyboxShader: SkyboxShader val pickerShader: PickerShader val depthShader: DepthShader @@ -42,8 +40,6 @@ object Shaders : Disposable { ShaderProgram.pedantic = false wireframeShader = WireframeShader() wireframeShader.init() - waterShader = WaterShader() - waterShader.init() skyboxShader = SkyboxShader() skyboxShader.init() pickerShader = PickerShader() @@ -58,7 +54,6 @@ object Shaders : Disposable { wireframeShader.dispose() skyboxShader.dispose() pickerShader.dispose() - waterShader.dispose() depthShader.dispose() } diff --git a/editor/src/main/com/mbrlabs/mundus/editor/ui/modules/outline/OutlineRightClickMenu.kt b/editor/src/main/com/mbrlabs/mundus/editor/ui/modules/outline/OutlineRightClickMenu.kt index 5352a6c85..91587e39b 100644 --- a/editor/src/main/com/mbrlabs/mundus/editor/ui/modules/outline/OutlineRightClickMenu.kt +++ b/editor/src/main/com/mbrlabs/mundus/editor/ui/modules/outline/OutlineRightClickMenu.kt @@ -14,7 +14,6 @@ import com.mbrlabs.mundus.editor.core.kryo.KryoManager import com.mbrlabs.mundus.editor.core.project.ProjectManager import com.mbrlabs.mundus.editor.events.AssetImportEvent import com.mbrlabs.mundus.editor.events.SceneGraphChangedEvent -import com.mbrlabs.mundus.editor.shader.Shaders import com.mbrlabs.mundus.editor.ui.UI import com.mbrlabs.mundus.editor.utils.Log import com.mbrlabs.mundus.editor.utils.createWaterGO @@ -311,7 +310,7 @@ class OutlineRightClickMenu(outline: Outline) : PopupMenu() { asset.applyDependencies() val waterGO = createWaterGO(sceneGraph, - Shaders.waterShader, goID, name, asset) + null, goID, name, asset) // update sceneGraph sceneGraph.addGameObject(waterGO) // update outline diff --git a/editor/src/main/com/mbrlabs/mundus/editor/utils/WaterUtils.kt b/editor/src/main/com/mbrlabs/mundus/editor/utils/WaterUtils.kt index d229587ba..0f05749f3 100644 --- a/editor/src/main/com/mbrlabs/mundus/editor/utils/WaterUtils.kt +++ b/editor/src/main/com/mbrlabs/mundus/editor/utils/WaterUtils.kt @@ -1,23 +1,21 @@ package com.mbrlabs.mundus.editor.utils +import com.badlogic.gdx.graphics.g3d.Shader import com.mbrlabs.mundus.commons.assets.WaterAsset import com.mbrlabs.mundus.commons.scene3d.GameObject import com.mbrlabs.mundus.commons.scene3d.SceneGraph -import com.mbrlabs.mundus.commons.shaders.WaterShader import com.mbrlabs.mundus.editor.scene3d.components.PickableWaterComponent -import com.mbrlabs.mundus.editor.shader.Shaders -fun createWaterGO(sg: SceneGraph, shader: WaterShader, goID: Int, goName: String, +fun createWaterGO(sg: SceneGraph, shader: Shader?, goID: Int, goName: String, water: WaterAsset): GameObject { val waterGO = GameObject(sg, null, goID) waterGO.name = goName waterGO.hasWaterComponent = true water.water.setTransform(waterGO.transform) - val waterComponent = PickableWaterComponent(waterGO, Shaders.waterShader) + val waterComponent = PickableWaterComponent(waterGO, shader) waterComponent.waterAsset = water waterGO.components.add(waterComponent) - waterComponent.shader = shader waterComponent.encodeRaypickColorId() return waterGO diff --git a/gdx-runtime/src/com/mbrlabs/mundus/runtime/Shaders.java b/gdx-runtime/src/com/mbrlabs/mundus/runtime/Shaders.java index a5e84379a..30a27dd17 100644 --- a/gdx-runtime/src/com/mbrlabs/mundus/runtime/Shaders.java +++ b/gdx-runtime/src/com/mbrlabs/mundus/runtime/Shaders.java @@ -19,18 +19,14 @@ import com.mbrlabs.mundus.commons.shaders.DepthShader; import com.mbrlabs.mundus.commons.shaders.ShadowMapShader; import com.mbrlabs.mundus.commons.shaders.SkyboxShader; -import com.mbrlabs.mundus.commons.shaders.WaterShader; public class Shaders { - private final WaterShader waterShader; private final SkyboxShader skyboxShader; private final DepthShader depthShader; private final ShadowMapShader shadowMapShader; public Shaders() { - waterShader = new WaterShader(); - waterShader.init(); skyboxShader = new SkyboxShader(); skyboxShader.init(); depthShader = new DepthShader(); @@ -39,10 +35,6 @@ public Shaders() { shadowMapShader.init(); } - public WaterShader getWaterShader() { - return waterShader; - } - public SkyboxShader getSkyboxShader() { return skyboxShader; } diff --git a/gdx-runtime/src/com/mbrlabs/mundus/runtime/converter/GameObjectConverter.java b/gdx-runtime/src/com/mbrlabs/mundus/runtime/converter/GameObjectConverter.java index 3c09a6685..ec080d38d 100644 --- a/gdx-runtime/src/com/mbrlabs/mundus/runtime/converter/GameObjectConverter.java +++ b/gdx-runtime/src/com/mbrlabs/mundus/runtime/converter/GameObjectConverter.java @@ -53,7 +53,7 @@ public static GameObject convert(GameObjectDTO dto, SceneGraph sceneGraph, Shade } else if (dto.getTerrainComponent() != null) { go.getComponents().add(TerrainComponentConverter.convert(dto.getTerrainComponent(), go, shaders, assetManager)); } else if (dto.getWaterComponent() != null) { - go.getComponents().add(WaterComponentConverter.convert(dto.getWaterComponent(), go, shaders.getWaterShader(), assetManager)); + go.getComponents().add(WaterComponentConverter.convert(dto.getWaterComponent(), go, shaders, assetManager)); } if (dto.getLightComponent() != null) { diff --git a/gdx-runtime/src/com/mbrlabs/mundus/runtime/converter/WaterComponentConverter.java b/gdx-runtime/src/com/mbrlabs/mundus/runtime/converter/WaterComponentConverter.java index ea7dc4d8e..40611d4e6 100644 --- a/gdx-runtime/src/com/mbrlabs/mundus/runtime/converter/WaterComponentConverter.java +++ b/gdx-runtime/src/com/mbrlabs/mundus/runtime/converter/WaterComponentConverter.java @@ -21,7 +21,7 @@ import com.mbrlabs.mundus.commons.dto.WaterComponentDTO; import com.mbrlabs.mundus.commons.scene3d.GameObject; import com.mbrlabs.mundus.commons.scene3d.components.WaterComponent; -import com.mbrlabs.mundus.commons.shaders.WaterShader; +import com.mbrlabs.mundus.runtime.Shaders; /** * The converter for Water. @@ -34,8 +34,8 @@ public class WaterComponentConverter { * Converts {@link WaterComponentDTO} to {@link WaterComponent}. */ public static WaterComponent convert(WaterComponentDTO waterComponentDTO, GameObject gameObject, - WaterShader waterShader, AssetManager assetManager) { - WaterComponent wc = new WaterComponent(gameObject, waterShader); + Shaders shaders, AssetManager assetManager) { + WaterComponent wc = new WaterComponent(gameObject, null); wc.setWaterAsset((WaterAsset) assetManager.findAssetByID(waterComponentDTO.getWaterId())); gameObject.hasWaterComponent = true; From 5f08d5d1a523c4e07265e00fed264607a4d931f1 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 17 Oct 2022 08:28:52 -0400 Subject: [PATCH 3/4] Rename temp water classes --- .../mundus/commons/assets/WaterAsset.java | 22 +++---- .../scene3d/components/WaterComponent.java | 8 +-- .../commons/shaders/WaterUberShader.java | 46 +++++++------- .../mbrlabs/mundus/commons/water/Water.java | 40 ++++++------ ...tributeU.java => WaterFloatAttribute.java} | 10 +-- ...ibuteU.java => WaterTextureAttribute.java} | 20 +++--- .../editor/assets/EditorAssetManager.kt | 22 +++---- .../mundus/editor/ui/widgets/WaterWidget.kt | 62 +++++++++---------- 8 files changed, 115 insertions(+), 115 deletions(-) rename commons/src/main/com/mbrlabs/mundus/commons/water/attributes/{WaterFloatAttributeU.java => WaterFloatAttribute.java} (92%) rename commons/src/main/com/mbrlabs/mundus/commons/water/attributes/{WaterTextureAttributeU.java => WaterTextureAttribute.java} (84%) diff --git a/commons/src/main/com/mbrlabs/mundus/commons/assets/WaterAsset.java b/commons/src/main/com/mbrlabs/mundus/commons/assets/WaterAsset.java index 3e772a1d6..744dd1727 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/assets/WaterAsset.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/assets/WaterAsset.java @@ -7,7 +7,7 @@ import com.badlogic.gdx.utils.PropertiesUtils; import com.mbrlabs.mundus.commons.assets.meta.Meta; import com.mbrlabs.mundus.commons.water.Water; -import com.mbrlabs.mundus.commons.water.attributes.WaterFloatAttributeU; +import com.mbrlabs.mundus.commons.water.attributes.WaterFloatAttribute; import java.io.IOException; import java.io.Reader; @@ -62,16 +62,16 @@ public void load() { normaMapID = MAP.get(PROP_NORMAL_MAP, "waterNormal"); // float attributes - water.setFloatAttribute(WaterFloatAttributeU.Tiling, Float.parseFloat(MAP.get(PROP_TILING, String.valueOf(Water.DEFAULT_TILING)))); - water.setFloatAttribute(WaterFloatAttributeU.WaveStrength, Float.parseFloat(MAP.get(PROP_WAVE_STRENGTH, String.valueOf(Water.DEFAULT_WAVE_STRENGTH)))); - water.setFloatAttribute(WaterFloatAttributeU.WaveSpeed, Float.parseFloat(MAP.get(PROP_WAVE_SPEED, String.valueOf(Water.DEFAULT_WAVE_SPEED)))); - water.setFloatAttribute(WaterFloatAttributeU.FoamPatternScale, Float.parseFloat(MAP.get(PROP_FOAM_SCALE, String.valueOf(Water.DEFAULT_FOAM_SCALE)))); - water.setFloatAttribute(WaterFloatAttributeU.FoamEdgeBias, Float.parseFloat(MAP.get(PROP_FOAM_EDGE_BIAS, String.valueOf(Water.DEFAULT_FOAM_EDGE_BIAS)))); - water.setFloatAttribute(WaterFloatAttributeU.FoamEdgeDistance, Float.parseFloat(MAP.get(PROP_FOAM_EDGE_DISTANCE, String.valueOf(Water.DEFAULT_FOAM_EDGE_DISTANCE)))); - water.setFloatAttribute(WaterFloatAttributeU.FoamFallOffDistance, Float.parseFloat(MAP.get(PROP_FOAM_FALL_OFF_DISTANCE, String.valueOf(Water.DEFAULT_FOAM_FALL_OFF_DISTANCE)))); - water.setFloatAttribute(WaterFloatAttributeU.FoamScrollSpeed, Float.parseFloat(MAP.get(PROP_FOAM_FALL_SCROLL_SPEED, String.valueOf(Water.DEFAULT_FOAM_SCROLL_SPEED)))); - water.setFloatAttribute(WaterFloatAttributeU.Reflectivity, Float.parseFloat(MAP.get(PROP_REFLECTIVITY, String.valueOf(Water.DEFAULT_REFLECTIVITY)))); - water.setFloatAttribute(WaterFloatAttributeU.ShineDamper, Float.parseFloat(MAP.get(PROP_SHINE_DAMPER, String.valueOf(Water.DEFAULT_SHINE_DAMPER)))); + water.setFloatAttribute(WaterFloatAttribute.Tiling, Float.parseFloat(MAP.get(PROP_TILING, String.valueOf(Water.DEFAULT_TILING)))); + water.setFloatAttribute(WaterFloatAttribute.WaveStrength, Float.parseFloat(MAP.get(PROP_WAVE_STRENGTH, String.valueOf(Water.DEFAULT_WAVE_STRENGTH)))); + water.setFloatAttribute(WaterFloatAttribute.WaveSpeed, Float.parseFloat(MAP.get(PROP_WAVE_SPEED, String.valueOf(Water.DEFAULT_WAVE_SPEED)))); + water.setFloatAttribute(WaterFloatAttribute.FoamPatternScale, Float.parseFloat(MAP.get(PROP_FOAM_SCALE, String.valueOf(Water.DEFAULT_FOAM_SCALE)))); + water.setFloatAttribute(WaterFloatAttribute.FoamEdgeBias, Float.parseFloat(MAP.get(PROP_FOAM_EDGE_BIAS, String.valueOf(Water.DEFAULT_FOAM_EDGE_BIAS)))); + water.setFloatAttribute(WaterFloatAttribute.FoamEdgeDistance, Float.parseFloat(MAP.get(PROP_FOAM_EDGE_DISTANCE, String.valueOf(Water.DEFAULT_FOAM_EDGE_DISTANCE)))); + water.setFloatAttribute(WaterFloatAttribute.FoamFallOffDistance, Float.parseFloat(MAP.get(PROP_FOAM_FALL_OFF_DISTANCE, String.valueOf(Water.DEFAULT_FOAM_FALL_OFF_DISTANCE)))); + water.setFloatAttribute(WaterFloatAttribute.FoamScrollSpeed, Float.parseFloat(MAP.get(PROP_FOAM_FALL_SCROLL_SPEED, String.valueOf(Water.DEFAULT_FOAM_SCROLL_SPEED)))); + water.setFloatAttribute(WaterFloatAttribute.Reflectivity, Float.parseFloat(MAP.get(PROP_REFLECTIVITY, String.valueOf(Water.DEFAULT_REFLECTIVITY)))); + water.setFloatAttribute(WaterFloatAttribute.ShineDamper, Float.parseFloat(MAP.get(PROP_SHINE_DAMPER, String.valueOf(Water.DEFAULT_SHINE_DAMPER)))); } catch (IOException e) { e.printStackTrace(); diff --git a/commons/src/main/com/mbrlabs/mundus/commons/scene3d/components/WaterComponent.java b/commons/src/main/com/mbrlabs/mundus/commons/scene3d/components/WaterComponent.java index 82eedbed6..b5afc945b 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/scene3d/components/WaterComponent.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/scene3d/components/WaterComponent.java @@ -22,7 +22,7 @@ import com.mbrlabs.mundus.commons.assets.Asset; import com.mbrlabs.mundus.commons.assets.WaterAsset; import com.mbrlabs.mundus.commons.scene3d.GameObject; -import com.mbrlabs.mundus.commons.water.attributes.WaterFloatAttributeU; +import com.mbrlabs.mundus.commons.water.attributes.WaterFloatAttribute; public class WaterComponent extends CullableComponent implements AssetUsage { @@ -82,14 +82,14 @@ private void updateFoamScroll() { u_Offset = 0.0f; } - waterAsset.water.setFloatAttribute(WaterFloatAttributeU.FoamUVOffset, u_Offset); + waterAsset.water.setFloatAttribute(WaterFloatAttribute.FoamUVOffset, u_Offset); } private void updateMoveFactor() { - float waveSpeed = waterAsset.water.getFloatAttribute(WaterFloatAttributeU.WaveSpeed); + float waveSpeed = waterAsset.water.getFloatAttribute(WaterFloatAttribute.WaveSpeed); moveFactor += waveSpeed * Gdx.graphics.getDeltaTime(); moveFactor %= 1; - waterAsset.water.setFloatAttribute(WaterFloatAttributeU.MoveFactor, moveFactor); + waterAsset.water.setFloatAttribute(WaterFloatAttribute.MoveFactor, moveFactor); } @Override diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/WaterUberShader.java b/commons/src/main/com/mbrlabs/mundus/commons/shaders/WaterUberShader.java index ebdf9c1a1..305afe1f8 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/shaders/WaterUberShader.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/shaders/WaterUberShader.java @@ -14,9 +14,9 @@ import com.mbrlabs.mundus.commons.utils.ShaderUtils; import com.mbrlabs.mundus.commons.water.Water; import com.mbrlabs.mundus.commons.water.WaterMaterial; -import com.mbrlabs.mundus.commons.water.attributes.WaterFloatAttributeU; +import com.mbrlabs.mundus.commons.water.attributes.WaterFloatAttribute; import com.mbrlabs.mundus.commons.water.attributes.WaterMaterialAttribute; -import com.mbrlabs.mundus.commons.water.attributes.WaterTextureAttributeU; +import com.mbrlabs.mundus.commons.water.attributes.WaterTextureAttribute; import net.mgsx.gltf.scene3d.attributes.FogAttribute; /** @@ -59,31 +59,31 @@ public static class WaterSetters { @Override public void set (BaseShader shader, int inputID, Renderable renderable, Attributes combinedAttributes) { WaterMaterial mat = getWaterMaterial(renderable); - WaterFloatAttributeU attr = (WaterFloatAttributeU) mat.get(WaterFloatAttributeU.FoamUVOffset); + WaterFloatAttribute attr = (WaterFloatAttribute) mat.get(WaterFloatAttribute.FoamUVOffset); if (attr != null) shader.set(inputID, attr.value, attr.value, 200f, 200f); } }; // Float attributes - public final static Setter moveFactor = new FloatSetter(WaterFloatAttributeU.MoveFactor, 0); - public final static Setter tiling = new FloatSetter(WaterFloatAttributeU.Tiling, Water.DEFAULT_TILING); - public final static Setter waveStrength = new FloatSetter(WaterFloatAttributeU.WaveStrength, Water.DEFAULT_WAVE_STRENGTH); - public final static Setter reflectivity = new FloatSetter(WaterFloatAttributeU.Reflectivity, Water.DEFAULT_REFLECTIVITY); - public final static Setter shineDamper = new FloatSetter(WaterFloatAttributeU.ShineDamper, Water.DEFAULT_SHINE_DAMPER); - public final static Setter foamScale = new FloatSetter(WaterFloatAttributeU.FoamPatternScale, Water.DEFAULT_FOAM_SCALE); - public final static Setter foamEdgeBias = new FloatSetter(WaterFloatAttributeU.FoamEdgeBias, Water.DEFAULT_FOAM_EDGE_BIAS); - public final static Setter foamEdgeDistance = new FloatSetter(WaterFloatAttributeU.FoamEdgeDistance, Water.DEFAULT_FOAM_EDGE_DISTANCE); - public final static Setter foamFallOffDistance = new FloatSetter(WaterFloatAttributeU.FoamFallOffDistance, Water.DEFAULT_FOAM_FALL_OFF_DISTANCE); - public final static Setter foamScrollSpeed = new FloatSetter(WaterFloatAttributeU.FoamScrollSpeed, Water.DEFAULT_FOAM_SCROLL_SPEED); + public final static Setter moveFactor = new FloatSetter(WaterFloatAttribute.MoveFactor, 0); + public final static Setter tiling = new FloatSetter(WaterFloatAttribute.Tiling, Water.DEFAULT_TILING); + public final static Setter waveStrength = new FloatSetter(WaterFloatAttribute.WaveStrength, Water.DEFAULT_WAVE_STRENGTH); + public final static Setter reflectivity = new FloatSetter(WaterFloatAttribute.Reflectivity, Water.DEFAULT_REFLECTIVITY); + public final static Setter shineDamper = new FloatSetter(WaterFloatAttribute.ShineDamper, Water.DEFAULT_SHINE_DAMPER); + public final static Setter foamScale = new FloatSetter(WaterFloatAttribute.FoamPatternScale, Water.DEFAULT_FOAM_SCALE); + public final static Setter foamEdgeBias = new FloatSetter(WaterFloatAttribute.FoamEdgeBias, Water.DEFAULT_FOAM_EDGE_BIAS); + public final static Setter foamEdgeDistance = new FloatSetter(WaterFloatAttribute.FoamEdgeDistance, Water.DEFAULT_FOAM_EDGE_DISTANCE); + public final static Setter foamFallOffDistance = new FloatSetter(WaterFloatAttribute.FoamFallOffDistance, Water.DEFAULT_FOAM_FALL_OFF_DISTANCE); + public final static Setter foamScrollSpeed = new FloatSetter(WaterFloatAttribute.FoamScrollSpeed, Water.DEFAULT_FOAM_SCROLL_SPEED); // Texture attributes - public final static Setter reflectionTexture = getTextureSetter(WaterTextureAttributeU.Reflection); - public final static Setter refractionTexture = getTextureSetter(WaterTextureAttributeU.Refraction); - public final static Setter refractionDepthTexture = getTextureSetter(WaterTextureAttributeU.RefractionDepth); - public final static Setter dudvTexture = getTextureSetter(WaterTextureAttributeU.Dudv); - public final static Setter normalMapTexture = getTextureSetter(WaterTextureAttributeU.NormalMap); - public final static Setter foamTexture = getTextureSetter(WaterTextureAttributeU.Foam); + public final static Setter reflectionTexture = getTextureSetter(WaterTextureAttribute.Reflection); + public final static Setter refractionTexture = getTextureSetter(WaterTextureAttribute.Refraction); + public final static Setter refractionDepthTexture = getTextureSetter(WaterTextureAttribute.RefractionDepth); + public final static Setter dudvTexture = getTextureSetter(WaterTextureAttribute.Dudv); + public final static Setter normalMapTexture = getTextureSetter(WaterTextureAttribute.NormalMap); + public final static Setter foamTexture = getTextureSetter(WaterTextureAttribute.Foam); private static Setter getTextureSetter(final long attribute) { return new LocalSetter() { @@ -93,7 +93,7 @@ public void set(BaseShader shader, int inputID, Renderable renderable, Attribute .get(WaterMaterialAttribute.WaterMaterial); WaterMaterial waterMaterial = waterMaterialAttribute.waterMaterial; - WaterTextureAttributeU waterTextureAttributeU = waterMaterial.get(WaterTextureAttributeU.class, attribute); + WaterTextureAttribute waterTextureAttributeU = waterMaterial.get(WaterTextureAttribute.class, attribute); final int unit = shader.context.textureBinder .bind(waterTextureAttributeU.textureDescription); shader.set(inputID, unit); @@ -260,7 +260,7 @@ public boolean canRender(Renderable instance) { private static float getFloatValue(Renderable renderable, long attribute, float defaultValue) { WaterMaterial waterMaterial = getWaterMaterial(renderable); - WaterFloatAttributeU attr = (WaterFloatAttributeU) waterMaterial.get(attribute); + WaterFloatAttribute attr = (WaterFloatAttribute) waterMaterial.get(attribute); if (attr != null) { return attr.value; } else { @@ -281,11 +281,11 @@ private String createPrefixForRenderable(Renderable renderable) { WaterMaterial waterMaterial = getWaterMaterial(renderable); - if (waterMaterial.has(WaterTextureAttributeU.Reflection)) { + if (waterMaterial.has(WaterTextureAttribute.Reflection)) { prefix += "#define reflectionFlag\n"; } - if (waterMaterial.has(WaterTextureAttributeU.Refraction)) { + if (waterMaterial.has(WaterTextureAttribute.Refraction)) { prefix += "#define refractionFlag\n"; } diff --git a/commons/src/main/com/mbrlabs/mundus/commons/water/Water.java b/commons/src/main/com/mbrlabs/mundus/commons/water/Water.java index de48d598f..1b2422122 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/water/Water.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/water/Water.java @@ -11,9 +11,9 @@ import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.utils.Pool; -import com.mbrlabs.mundus.commons.water.attributes.WaterFloatAttributeU; +import com.mbrlabs.mundus.commons.water.attributes.WaterFloatAttribute; import com.mbrlabs.mundus.commons.water.attributes.WaterMaterialAttribute; -import com.mbrlabs.mundus.commons.water.attributes.WaterTextureAttributeU; +import com.mbrlabs.mundus.commons.water.attributes.WaterTextureAttribute; public class Water implements RenderableProvider, Disposable { public static final int DEFAULT_SIZE = 1600; @@ -71,16 +71,16 @@ public void init() { material.set(WaterMaterialAttribute.createWaterMaterialAttribute(waterMaterial)); // Set default values - setFloatAttribute(WaterFloatAttributeU.Tiling, DEFAULT_TILING); - setFloatAttribute(WaterFloatAttributeU.WaveStrength, DEFAULT_WAVE_STRENGTH); - setFloatAttribute(WaterFloatAttributeU.WaveSpeed, DEFAULT_WAVE_SPEED); - setFloatAttribute(WaterFloatAttributeU.FoamPatternScale, Water.DEFAULT_FOAM_SCALE); - setFloatAttribute(WaterFloatAttributeU.FoamScrollSpeed, Water.DEFAULT_FOAM_SCROLL_SPEED); - setFloatAttribute(WaterFloatAttributeU.FoamEdgeDistance, Water.DEFAULT_FOAM_EDGE_DISTANCE); - setFloatAttribute(WaterFloatAttributeU.FoamEdgeBias, Water.DEFAULT_FOAM_EDGE_BIAS); - setFloatAttribute(WaterFloatAttributeU.FoamFallOffDistance, Water.DEFAULT_FOAM_FALL_OFF_DISTANCE); - setFloatAttribute(WaterFloatAttributeU.Reflectivity, DEFAULT_REFLECTIVITY); - setFloatAttribute(WaterFloatAttributeU.ShineDamper, DEFAULT_SHINE_DAMPER); + setFloatAttribute(WaterFloatAttribute.Tiling, DEFAULT_TILING); + setFloatAttribute(WaterFloatAttribute.WaveStrength, DEFAULT_WAVE_STRENGTH); + setFloatAttribute(WaterFloatAttribute.WaveSpeed, DEFAULT_WAVE_SPEED); + setFloatAttribute(WaterFloatAttribute.FoamPatternScale, Water.DEFAULT_FOAM_SCALE); + setFloatAttribute(WaterFloatAttribute.FoamScrollSpeed, Water.DEFAULT_FOAM_SCROLL_SPEED); + setFloatAttribute(WaterFloatAttribute.FoamEdgeDistance, Water.DEFAULT_FOAM_EDGE_DISTANCE); + setFloatAttribute(WaterFloatAttribute.FoamEdgeBias, Water.DEFAULT_FOAM_EDGE_BIAS); + setFloatAttribute(WaterFloatAttribute.FoamFallOffDistance, Water.DEFAULT_FOAM_FALL_OFF_DISTANCE); + setFloatAttribute(WaterFloatAttribute.Reflectivity, DEFAULT_REFLECTIVITY); + setFloatAttribute(WaterFloatAttribute.ShineDamper, DEFAULT_SHINE_DAMPER); } @Override @@ -94,34 +94,34 @@ public void dispose() { } public void setWaterReflection(Texture texture) { - waterMaterial.set(new WaterTextureAttributeU(WaterTextureAttributeU.Reflection, texture)); + waterMaterial.set(new WaterTextureAttribute(WaterTextureAttribute.Reflection, texture)); } public void setFoamTexture(Texture texture) { - waterMaterial.set(new WaterTextureAttributeU(WaterTextureAttributeU.Foam, texture)); + waterMaterial.set(new WaterTextureAttribute(WaterTextureAttribute.Foam, texture)); } public void setDudvTexture(Texture texture) { - waterMaterial.set(new WaterTextureAttributeU(WaterTextureAttributeU.Dudv, texture)); + waterMaterial.set(new WaterTextureAttribute(WaterTextureAttribute.Dudv, texture)); } public void setNormalMap(Texture texture) { - waterMaterial.set(new WaterTextureAttributeU(WaterTextureAttributeU.NormalMap, texture)); + waterMaterial.set(new WaterTextureAttribute(WaterTextureAttribute.NormalMap, texture)); } public void setWaterRefractionTexture(Texture texture) { - waterMaterial.set(new WaterTextureAttributeU(WaterTextureAttributeU.Refraction, texture)); + waterMaterial.set(new WaterTextureAttribute(WaterTextureAttribute.Refraction, texture)); } public void setWaterRefractionDepthTexture(Texture texture) { - waterMaterial.set(new WaterTextureAttributeU(WaterTextureAttributeU.RefractionDepth, texture)); + waterMaterial.set(new WaterTextureAttribute(WaterTextureAttribute.RefractionDepth, texture)); } public void setFloatAttribute(long attributeType, float value) { - waterMaterial.set(new WaterFloatAttributeU(attributeType, value)); + waterMaterial.set(new WaterFloatAttribute(attributeType, value)); } public float getFloatAttribute(long attributeType) { - return waterMaterial.get(WaterFloatAttributeU.class, attributeType).value; + return waterMaterial.get(WaterFloatAttribute.class, attributeType).value; } } diff --git a/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterFloatAttributeU.java b/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterFloatAttribute.java similarity index 92% rename from commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterFloatAttributeU.java rename to commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterFloatAttribute.java index bf6fd28d3..a1bfdb433 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterFloatAttributeU.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterFloatAttribute.java @@ -20,7 +20,7 @@ import com.badlogic.gdx.utils.NumberUtils; import com.mbrlabs.mundus.commons.MundusAttribute; -public class WaterFloatAttributeU extends MundusAttribute { +public class WaterFloatAttribute extends MundusAttribute { public static final String TilingAlias = "tiling"; public static final long Tiling = register(TilingAlias); @@ -59,18 +59,18 @@ public class WaterFloatAttributeU extends MundusAttribute { public float value; - public WaterFloatAttributeU(long type) { + public WaterFloatAttribute(long type) { super(type); } - public WaterFloatAttributeU(long type, float value) { + public WaterFloatAttribute(long type, float value) { super(type); this.value = value; } @Override public MundusAttribute copy () { - return new WaterFloatAttributeU(type, value); + return new WaterFloatAttribute(type, value); } @Override @@ -83,7 +83,7 @@ public int hashCode () { @Override public int compareTo (MundusAttribute o) { if (type != o.type) return (int)(type - o.type); - final float v = ((WaterFloatAttributeU)o).value; + final float v = ((WaterFloatAttribute)o).value; return MathUtils.isEqual(value, v) ? 0 : value < v ? -1 : 1; } } diff --git a/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterTextureAttributeU.java b/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterTextureAttribute.java similarity index 84% rename from commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterTextureAttributeU.java rename to commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterTextureAttribute.java index bf473030d..5b5b7147d 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterTextureAttributeU.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/water/attributes/WaterTextureAttribute.java @@ -12,7 +12,7 @@ * @author JamesTKhan * @version October 16, 2022 */ -public class WaterTextureAttributeU extends MundusAttribute { +public class WaterTextureAttribute extends MundusAttribute { public final static String DudvAlias = "dudvTexture"; public final static long Dudv = register(DudvAlias); @@ -47,18 +47,18 @@ public final static boolean is (final long mask) { * etc.), this value is usually ignored and the first texture coordinate vertex attribute is used. */ public int uvIndex = 0; - public WaterTextureAttributeU(final long type) { + public WaterTextureAttribute(final long type) { super(type); if (!is(type)) throw new GdxRuntimeException("Invalid type specified"); textureDescription = new TextureDescriptor(); } - public WaterTextureAttributeU(final long type, final TextureDescriptor textureDescription) { + public WaterTextureAttribute(final long type, final TextureDescriptor textureDescription) { this(type); this.textureDescription.set(textureDescription); } - public WaterTextureAttributeU(final long type, final TextureDescriptor textureDescription, float offsetU, + public WaterTextureAttribute(final long type, final TextureDescriptor textureDescription, float offsetU, float offsetV, float scaleU, float scaleV, int uvIndex) { this(type, textureDescription); this.offsetU = offsetU; @@ -68,22 +68,22 @@ public WaterTextureAttributeU(final long type, final Texture this.uvIndex = uvIndex; } - public WaterTextureAttributeU(final long type, final TextureDescriptor textureDescription, float offsetU, + public WaterTextureAttribute(final long type, final TextureDescriptor textureDescription, float offsetU, float offsetV, float scaleU, float scaleV) { this(type, textureDescription, offsetU, offsetV, scaleU, scaleV, 0); } - public WaterTextureAttributeU(final long type, final Texture texture) { + public WaterTextureAttribute(final long type, final Texture texture) { this(type); textureDescription.texture = texture; } - public WaterTextureAttributeU(final long type, final TextureRegion region) { + public WaterTextureAttribute(final long type, final TextureRegion region) { this(type); set(region); } - public WaterTextureAttributeU(final WaterTextureAttributeU copyFrom) { + public WaterTextureAttribute(final WaterTextureAttribute copyFrom) { this(copyFrom.type, copyFrom.textureDescription, copyFrom.offsetU, copyFrom.offsetV, copyFrom.scaleU, copyFrom.scaleV, copyFrom.uvIndex); } @@ -98,7 +98,7 @@ public void set (final TextureRegion region) { @Override public MundusAttribute copy () { - return new WaterTextureAttributeU(this); + return new WaterTextureAttribute(this); } @Override @@ -116,7 +116,7 @@ public int hashCode () { @Override public int compareTo (MundusAttribute o) { if (type != o.type) return type < o.type ? -1 : 1; - WaterTextureAttributeU other = (WaterTextureAttributeU)o; + WaterTextureAttribute other = (WaterTextureAttribute)o; final int c = textureDescription.compareTo(other.textureDescription); if (c != 0) return c; if (uvIndex != other.uvIndex) return uvIndex - other.uvIndex; diff --git a/editor/src/main/com/mbrlabs/mundus/editor/assets/EditorAssetManager.kt b/editor/src/main/com/mbrlabs/mundus/editor/assets/EditorAssetManager.kt index 14bc912c2..432a75123 100644 --- a/editor/src/main/com/mbrlabs/mundus/editor/assets/EditorAssetManager.kt +++ b/editor/src/main/com/mbrlabs/mundus/editor/assets/EditorAssetManager.kt @@ -40,7 +40,7 @@ import com.mbrlabs.mundus.commons.assets.meta.MetaTerrain import com.mbrlabs.mundus.commons.scene3d.GameObject import com.mbrlabs.mundus.commons.scene3d.components.AssetUsage import com.mbrlabs.mundus.commons.utils.FileFormatUtils -import com.mbrlabs.mundus.commons.water.attributes.WaterFloatAttributeU +import com.mbrlabs.mundus.commons.water.attributes.WaterFloatAttribute import com.mbrlabs.mundus.editor.Mundus.postEvent import com.mbrlabs.mundus.editor.core.project.ProjectManager import com.mbrlabs.mundus.editor.events.LogEvent @@ -753,18 +753,18 @@ class EditorAssetManager(assetsRoot: FileHandle) : AssetManager(assetsRoot) { props.setProperty(WaterAsset.PROP_DUDV, asset.dudvTexture.id) props.setProperty(WaterAsset.PROP_NORMAL_MAP, asset.normalMapTexture.id) - props.setProperty(WaterAsset.PROP_TILING, asset.water.getFloatAttribute(WaterFloatAttributeU.Tiling).toString()) - props.setProperty(WaterAsset.PROP_WAVE_STRENGTH, asset.water.getFloatAttribute(WaterFloatAttributeU.WaveStrength).toString()) - props.setProperty(WaterAsset.PROP_WAVE_SPEED, asset.water.getFloatAttribute(WaterFloatAttributeU.WaveSpeed).toString()) + props.setProperty(WaterAsset.PROP_TILING, asset.water.getFloatAttribute(WaterFloatAttribute.Tiling).toString()) + props.setProperty(WaterAsset.PROP_WAVE_STRENGTH, asset.water.getFloatAttribute(WaterFloatAttribute.WaveStrength).toString()) + props.setProperty(WaterAsset.PROP_WAVE_SPEED, asset.water.getFloatAttribute(WaterFloatAttribute.WaveSpeed).toString()) - props.setProperty(WaterAsset.PROP_FOAM_SCALE, asset.water.getFloatAttribute(WaterFloatAttributeU.FoamPatternScale).toString()) - props.setProperty(WaterAsset.PROP_FOAM_EDGE_BIAS, asset.water.getFloatAttribute(WaterFloatAttributeU.FoamEdgeBias).toString()) - props.setProperty(WaterAsset.PROP_FOAM_EDGE_DISTANCE, asset.water.getFloatAttribute(WaterFloatAttributeU.FoamEdgeDistance).toString()) - props.setProperty(WaterAsset.PROP_FOAM_FALL_OFF_DISTANCE, asset.water.getFloatAttribute(WaterFloatAttributeU.FoamFallOffDistance).toString()) - props.setProperty(WaterAsset.PROP_FOAM_FALL_SCROLL_SPEED, asset.water.getFloatAttribute(WaterFloatAttributeU.FoamScrollSpeed).toString()) + props.setProperty(WaterAsset.PROP_FOAM_SCALE, asset.water.getFloatAttribute(WaterFloatAttribute.FoamPatternScale).toString()) + props.setProperty(WaterAsset.PROP_FOAM_EDGE_BIAS, asset.water.getFloatAttribute(WaterFloatAttribute.FoamEdgeBias).toString()) + props.setProperty(WaterAsset.PROP_FOAM_EDGE_DISTANCE, asset.water.getFloatAttribute(WaterFloatAttribute.FoamEdgeDistance).toString()) + props.setProperty(WaterAsset.PROP_FOAM_FALL_OFF_DISTANCE, asset.water.getFloatAttribute(WaterFloatAttribute.FoamFallOffDistance).toString()) + props.setProperty(WaterAsset.PROP_FOAM_FALL_SCROLL_SPEED, asset.water.getFloatAttribute(WaterFloatAttribute.FoamScrollSpeed).toString()) - props.setProperty(WaterAsset.PROP_REFLECTIVITY, asset.water.getFloatAttribute(WaterFloatAttributeU.Reflectivity).toString()) - props.setProperty(WaterAsset.PROP_SHINE_DAMPER, asset.water.getFloatAttribute(WaterFloatAttributeU.ShineDamper).toString()) + props.setProperty(WaterAsset.PROP_REFLECTIVITY, asset.water.getFloatAttribute(WaterFloatAttribute.Reflectivity).toString()) + props.setProperty(WaterAsset.PROP_SHINE_DAMPER, asset.water.getFloatAttribute(WaterFloatAttribute.ShineDamper).toString()) val fileOutputStream = FileOutputStream(asset.file.file()) props.store(fileOutputStream, null) diff --git a/editor/src/main/com/mbrlabs/mundus/editor/ui/widgets/WaterWidget.kt b/editor/src/main/com/mbrlabs/mundus/editor/ui/widgets/WaterWidget.kt index cc7264976..f806898b3 100644 --- a/editor/src/main/com/mbrlabs/mundus/editor/ui/widgets/WaterWidget.kt +++ b/editor/src/main/com/mbrlabs/mundus/editor/ui/widgets/WaterWidget.kt @@ -14,7 +14,7 @@ import com.kotcrab.vis.ui.widget.VisTextField import com.mbrlabs.mundus.commons.scene3d.components.WaterComponent import com.mbrlabs.mundus.commons.water.Water import com.mbrlabs.mundus.commons.water.WaterResolution -import com.mbrlabs.mundus.commons.water.attributes.WaterFloatAttributeU +import com.mbrlabs.mundus.commons.water.attributes.WaterFloatAttribute import com.mbrlabs.mundus.editor.Mundus import com.mbrlabs.mundus.editor.core.project.ProjectManager import com.mbrlabs.mundus.editor.events.LogEvent @@ -127,16 +127,16 @@ class WaterWidget(val waterComponent: WaterComponent) : VisTable() { add(resetDefaults).padTop(10f).growX().row() // Register listeners for the float fields - registerFloatFieldListener(tilingField, WaterFloatAttributeU.Tiling) - registerFloatFieldListener(waveStrength, WaterFloatAttributeU.WaveStrength) - registerFloatFieldListener(waveSpeed, WaterFloatAttributeU.WaveSpeed) - registerFloatFieldListener(foamPatternScale, WaterFloatAttributeU.FoamPatternScale) - registerFloatFieldListener(foamEdgeBias, WaterFloatAttributeU.FoamEdgeBias) - registerFloatFieldListener(foamScrollSpeedFactor, WaterFloatAttributeU.FoamScrollSpeed) - registerFloatFieldListener(foamEdgeDistance, WaterFloatAttributeU.FoamEdgeDistance) - registerFloatFieldListener(foamFallOffDistance, WaterFloatAttributeU.FoamFallOffDistance) - registerFloatFieldListener(reflectivity, WaterFloatAttributeU.Reflectivity) - registerFloatFieldListener(shineDamper, WaterFloatAttributeU.ShineDamper) + registerFloatFieldListener(tilingField, WaterFloatAttribute.Tiling) + registerFloatFieldListener(waveStrength, WaterFloatAttribute.WaveStrength) + registerFloatFieldListener(waveSpeed, WaterFloatAttribute.WaveSpeed) + registerFloatFieldListener(foamPatternScale, WaterFloatAttribute.FoamPatternScale) + registerFloatFieldListener(foamEdgeBias, WaterFloatAttribute.FoamEdgeBias) + registerFloatFieldListener(foamScrollSpeedFactor, WaterFloatAttribute.FoamScrollSpeed) + registerFloatFieldListener(foamEdgeDistance, WaterFloatAttribute.FoamEdgeDistance) + registerFloatFieldListener(foamFallOffDistance, WaterFloatAttribute.FoamFallOffDistance) + registerFloatFieldListener(reflectivity, WaterFloatAttribute.Reflectivity) + registerFloatFieldListener(shineDamper, WaterFloatAttribute.ShineDamper) // resolution selectBox.addListener(object : ChangeListener() { @@ -148,16 +148,16 @@ class WaterWidget(val waterComponent: WaterComponent) : VisTable() { resetDefaults.addListener(object : ClickListener() { override fun clicked(event: InputEvent?, x: Float, y: Float) { - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.Tiling, Water.DEFAULT_TILING) - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.WaveStrength, Water.DEFAULT_WAVE_STRENGTH) - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.WaveSpeed, Water.DEFAULT_WAVE_SPEED) - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.Reflectivity, Water.DEFAULT_REFLECTIVITY) - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.ShineDamper, Water.DEFAULT_SHINE_DAMPER) - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.FoamPatternScale, Water.DEFAULT_FOAM_SCALE) - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.FoamScrollSpeed, Water.DEFAULT_FOAM_SCROLL_SPEED) - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.FoamEdgeDistance, Water.DEFAULT_FOAM_EDGE_DISTANCE) - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.FoamEdgeBias, Water.DEFAULT_FOAM_EDGE_BIAS) - waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttributeU.FoamFallOffDistance, Water.DEFAULT_FOAM_FALL_OFF_DISTANCE) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.Tiling, Water.DEFAULT_TILING) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.WaveStrength, Water.DEFAULT_WAVE_STRENGTH) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.WaveSpeed, Water.DEFAULT_WAVE_SPEED) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.Reflectivity, Water.DEFAULT_REFLECTIVITY) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.ShineDamper, Water.DEFAULT_SHINE_DAMPER) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.FoamPatternScale, Water.DEFAULT_FOAM_SCALE) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.FoamScrollSpeed, Water.DEFAULT_FOAM_SCROLL_SPEED) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.FoamEdgeDistance, Water.DEFAULT_FOAM_EDGE_DISTANCE) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.FoamEdgeBias, Water.DEFAULT_FOAM_EDGE_BIAS) + waterComponent.waterAsset.water.setFloatAttribute(WaterFloatAttribute.FoamFallOffDistance, Water.DEFAULT_FOAM_FALL_OFF_DISTANCE) projectManager.current().currScene.settings.waterResolution = WaterResolution.DEFAULT_WATER_RESOLUTION projectManager.current().assetManager.addModifiedAsset(waterComponent.waterAsset) @@ -186,16 +186,16 @@ class WaterWidget(val waterComponent: WaterComponent) : VisTable() { } fun setFieldsToCurrentValues() { - tilingField.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.Tiling).toString() - waveStrength.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.WaveStrength).toString() - waveSpeed.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.WaveSpeed).toString() - reflectivity.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.Reflectivity).toString() - shineDamper.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.ShineDamper).toString() - foamPatternScale.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.FoamPatternScale).toString() - foamEdgeBias.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.FoamEdgeBias).toString() - foamScrollSpeedFactor.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.FoamScrollSpeed).toString() - foamFallOffDistance.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.FoamFallOffDistance).toString() - foamEdgeDistance.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttributeU.FoamEdgeDistance).toString() + tilingField.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.Tiling).toString() + waveStrength.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.WaveStrength).toString() + waveSpeed.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.WaveSpeed).toString() + reflectivity.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.Reflectivity).toString() + shineDamper.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.ShineDamper).toString() + foamPatternScale.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.FoamPatternScale).toString() + foamEdgeBias.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.FoamEdgeBias).toString() + foamScrollSpeedFactor.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.FoamScrollSpeed).toString() + foamFallOffDistance.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.FoamFallOffDistance).toString() + foamEdgeDistance.text = waterComponent.waterAsset.water.getFloatAttribute(WaterFloatAttribute.FoamEdgeDistance).toString() if (!selectBox.items.contains(projectManager.current().currScene.settings.waterResolution.value)) { selectBox.selected = WaterResolution.DEFAULT_WATER_RESOLUTION.value From 061b38dcedece60fdf203caddb5a781d3df27f08 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 17 Oct 2022 08:45:33 -0400 Subject: [PATCH 4/4] Add new water shader for GWT --- gdx-runtime/src/com/mbrlabs/mundus.gwt.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gdx-runtime/src/com/mbrlabs/mundus.gwt.xml b/gdx-runtime/src/com/mbrlabs/mundus.gwt.xml index e267d56a1..962370ee4 100644 --- a/gdx-runtime/src/com/mbrlabs/mundus.gwt.xml +++ b/gdx-runtime/src/com/mbrlabs/mundus.gwt.xml @@ -8,8 +8,8 @@ - - + +