-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
791 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
common/src/main/java/dev/ultreon/mcgdx/impl/BlockEntityShader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package dev.ultreon.mcgdx.impl; | ||
|
||
import com.badlogic.gdx.graphics.GL20; | ||
import com.badlogic.gdx.graphics.GLTexture; | ||
import com.badlogic.gdx.graphics.g3d.Attributes; | ||
import com.badlogic.gdx.graphics.g3d.Renderable; | ||
import com.badlogic.gdx.graphics.g3d.shaders.BaseShader; | ||
import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader; | ||
import com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor; | ||
import com.badlogic.gdx.graphics.glutils.ShaderProgram; | ||
import com.sun.jna.platform.win32.GL; | ||
import dev.ultreon.mcgdx.mixin.accessors.LightTextureAccessor; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.renderer.LightTexture; | ||
import net.minecraft.client.renderer.texture.DynamicTexture; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import static dev.ultreon.mcgdx.impl.MinecraftRendererContext.packedLight; | ||
|
||
public class BlockEntityShader extends DefaultShader { | ||
private final int u_mcLight; | ||
private final int u_mcLightTexture; | ||
|
||
public BlockEntityShader(final Renderable renderable) { | ||
this(renderable, new Config()); | ||
} | ||
|
||
public BlockEntityShader(final Renderable renderable, final Config config) { | ||
this(renderable, config, createPrefix(renderable, config)); | ||
} | ||
|
||
public BlockEntityShader(final Renderable renderable, final Config config, final String prefix) { | ||
this(renderable, config, prefix, config.vertexShader != null ? config.vertexShader : getDefaultVertexShader(), | ||
config.fragmentShader != null ? config.fragmentShader : getDefaultFragmentShader()); | ||
} | ||
|
||
public BlockEntityShader(final Renderable renderable, final Config config, final String prefix, final String vertexShader, | ||
final String fragmentShader) { | ||
this(renderable, config, new ShaderProgram(prefix + vertexShader, prefix + fragmentShader)); | ||
} | ||
|
||
public BlockEntityShader(Renderable renderable, Config config, ShaderProgram shaderProgram) { | ||
super(renderable, config, shaderProgram); | ||
|
||
LightTexture lightTexture = Minecraft.getInstance().gameRenderer.lightTexture(); | ||
GLTexture glTexture = getGlTexture((LightTextureAccessor) lightTexture); | ||
|
||
this.u_mcLight = register(new Uniform("u_mcLight"), new LocalSetter() { | ||
@Override | ||
public void set(BaseShader shader, int inputID, Renderable renderable, Attributes combinedAttributes) { | ||
shader.set(inputID, (float) LightTexture.block(packedLight), (float) LightTexture.sky(packedLight)); | ||
} | ||
}); | ||
|
||
this.u_mcLightTexture = register(new Uniform("u_mcLightTexture"), new GlobalSetter() { | ||
@Override | ||
public void set(BaseShader shader, int inputID, Renderable renderable, Attributes combinedAttributes) { | ||
shader.set(inputID, glTexture); | ||
} | ||
}); | ||
} | ||
|
||
private static @NotNull GLTexture getGlTexture(LightTextureAccessor lightTexture) { | ||
LightTextureAccessor accessor = lightTexture; | ||
DynamicTexture dynamicTexture = accessor.getLightTexture(); | ||
|
||
int id = dynamicTexture.getId(); | ||
// Unreloadable | ||
return new GLTexture(GL20.GL_TEXTURE_2D, id) { | ||
@Override | ||
public int getWidth() { | ||
return 16; | ||
} | ||
|
||
@Override | ||
public int getHeight() { | ||
return 16; | ||
} | ||
|
||
@Override | ||
public int getDepth() { | ||
return 32; | ||
} | ||
|
||
@Override | ||
public boolean isManaged() { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected void reload() { | ||
// Unreloadable | ||
} | ||
}; | ||
} | ||
|
||
public static String createPrefix(final Renderable renderable, final Config config) { | ||
return "#version 150\n" + DefaultShader.createPrefix(renderable, config); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
common/src/main/java/dev/ultreon/mcgdx/impl/BlockEntityShaderProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/******************************************************************************* | ||
* 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 dev.ultreon.mcgdx.impl; | ||
|
||
import com.badlogic.gdx.files.FileHandle; | ||
import com.badlogic.gdx.graphics.g3d.Renderable; | ||
import com.badlogic.gdx.graphics.g3d.Shader; | ||
import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader; | ||
import com.badlogic.gdx.graphics.g3d.utils.BaseShaderProvider; | ||
|
||
public class BlockEntityShaderProvider extends BaseShaderProvider { | ||
public final DefaultShader.Config config; | ||
|
||
public BlockEntityShaderProvider(final DefaultShader.Config config) { | ||
this.config = (config == null) ? new DefaultShader.Config() : config; | ||
} | ||
|
||
public BlockEntityShaderProvider(final String vertexShader, final String fragmentShader) { | ||
this(new DefaultShader.Config(vertexShader, fragmentShader)); | ||
} | ||
|
||
public BlockEntityShaderProvider(final FileHandle vertexShader, final FileHandle fragmentShader) { | ||
this(vertexShader.readString(), fragmentShader.readString()); | ||
} | ||
|
||
public BlockEntityShaderProvider() { | ||
this(null); | ||
} | ||
|
||
@Override | ||
protected Shader createShader (final Renderable renderable) { | ||
return new BlockEntityShader(renderable, config); | ||
} | ||
} |
Oops, something went wrong.