mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
shader: includes
This commit is contained in:
parent
2fdad3dbce
commit
75aeb48fdb
@ -40,6 +40,8 @@ class World : BiomeAccessor {
|
|||||||
val worldLightAccessor = WorldLightAccessor(this)
|
val worldLightAccessor = WorldLightAccessor(this)
|
||||||
var hashedSeed = 0L
|
var hashedSeed = 0L
|
||||||
var biomeAccessor: BiomeAccessor = NullBiomeAccessor
|
var biomeAccessor: BiomeAccessor = NullBiomeAccessor
|
||||||
|
var time = 0L
|
||||||
|
var age = 0L
|
||||||
|
|
||||||
fun getBlockState(blockPosition: Vec3i): BlockState? {
|
fun getBlockState(blockPosition: Vec3i): BlockState? {
|
||||||
val chunkLocation = blockPosition.chunkPosition
|
val chunkLocation = blockPosition.chunkPosition
|
||||||
|
@ -44,7 +44,7 @@ class Shader(
|
|||||||
|
|
||||||
fun load(assetsManager: AssetsManager = Minosoft.MINOSOFT_ASSETS_MANAGER): Int {
|
fun load(assetsManager: AssetsManager = Minosoft.MINOSOFT_ASSETS_MANAGER): Int {
|
||||||
val uniforms: MutableList<String> = mutableListOf()
|
val uniforms: MutableList<String> = mutableListOf()
|
||||||
val pathPrefix = resourceLocation.namespace + ":rendering/shader/" + resourceLocation.path + "/" + resourceLocation.path.replace("/", "_")
|
val pathPrefix = """${resourceLocation.namespace}:rendering/shader/${resourceLocation.path}/${resourceLocation.path.replace("/", "_")}"""
|
||||||
val vertexShader = createShader(assetsManager, ResourceLocation("$pathPrefix.vsh"), GL_VERTEX_SHADER_ARB, defines, uniforms)!!
|
val vertexShader = createShader(assetsManager, ResourceLocation("$pathPrefix.vsh"), GL_VERTEX_SHADER_ARB, defines, uniforms)!!
|
||||||
val geometryShader = createShader(assetsManager, ResourceLocation("$pathPrefix.gsh"), GL_GEOMETRY_SHADER_ARB, defines, uniforms)
|
val geometryShader = createShader(assetsManager, ResourceLocation("$pathPrefix.gsh"), GL_GEOMETRY_SHADER_ARB, defines, uniforms)
|
||||||
val fragmentShader = createShader(assetsManager, ResourceLocation("$pathPrefix.fsh"), GL_FRAGMENT_SHADER_ARB, defines, uniforms)!!
|
val fragmentShader = createShader(assetsManager, ResourceLocation("$pathPrefix.fsh"), GL_FRAGMENT_SHADER_ARB, defines, uniforms)!!
|
||||||
@ -165,9 +165,25 @@ class Shader(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (line in lines) {
|
for (line in lines) {
|
||||||
|
val reader = CommandStringReader(line)
|
||||||
|
when {
|
||||||
|
line.startsWith("#include ") -> {
|
||||||
|
val includeResourceLocation = ResourceLocation(line.removePrefix("#include ").removePrefix("\"").removeSuffix("\"").replace("\\\"", "\""))
|
||||||
|
total.append("\n")
|
||||||
|
total.append(assetsManager.readStringAsset(if (includeResourceLocation.path.contains(".glsl")) {
|
||||||
|
includeResourceLocation
|
||||||
|
} else {
|
||||||
|
ResourceLocation(includeResourceLocation.namespace, "rendering/shader/includes/${includeResourceLocation.path}.glsl")
|
||||||
|
}))
|
||||||
|
|
||||||
|
total.append("\n")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
total.append(line)
|
total.append(line)
|
||||||
total.append('\n')
|
total.append('\n')
|
||||||
val reader = CommandStringReader(line)
|
|
||||||
when {
|
when {
|
||||||
line.startsWith("#version") -> {
|
line.startsWith("#version") -> {
|
||||||
// add all defines
|
// add all defines
|
||||||
|
@ -28,8 +28,8 @@ public class TimeChangeEvent extends CancelableEvent {
|
|||||||
|
|
||||||
public TimeChangeEvent(PlayConnection connection, WorldTimeSetS2CP pkg) {
|
public TimeChangeEvent(PlayConnection connection, WorldTimeSetS2CP pkg) {
|
||||||
super(connection);
|
super(connection);
|
||||||
this.worldAge = pkg.getWorldAge();
|
this.worldAge = pkg.getAge();
|
||||||
this.timeOfDay = pkg.getTimeOfDay();
|
this.timeOfDay = pkg.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getWorldAge() {
|
public long getWorldAge() {
|
||||||
|
@ -21,17 +21,19 @@ import de.bixilon.minosoft.util.logging.LogLevels
|
|||||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||||
|
|
||||||
class WorldTimeSetS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
class WorldTimeSetS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
||||||
val worldAge: Long = buffer.readLong()
|
val age = buffer.readLong()
|
||||||
val timeOfDay: Long = buffer.readLong()
|
val time = buffer.readLong()
|
||||||
|
|
||||||
override fun handle(connection: PlayConnection) {
|
override fun handle(connection: PlayConnection) {
|
||||||
if (connection.fireEvent(TimeChangeEvent(connection, this))) {
|
if (connection.fireEvent(TimeChangeEvent(connection, this))) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
connection.world.age = age
|
||||||
|
connection.world.time = time
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun log() {
|
override fun log() {
|
||||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "World time set (worldAge=$worldAge, timeOfDay=$timeOfDay)" }
|
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "World time set (age=$age, time=$time)" }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,20 +23,7 @@ in float passInterpolateBetweenTextures;
|
|||||||
|
|
||||||
in vec4 passTintColor;
|
in vec4 passTintColor;
|
||||||
|
|
||||||
uniform sampler2DArray textureArray[7];
|
#include "minosoft:texture"
|
||||||
|
|
||||||
vec4 getTexture(uint textureId, vec3 textureCoordinates){
|
|
||||||
switch (textureId){
|
|
||||||
case 0u : return texture(textureArray[0], textureCoordinates);
|
|
||||||
case 1u: return texture(textureArray[1], textureCoordinates);
|
|
||||||
case 2u: return texture(textureArray[2], textureCoordinates);
|
|
||||||
case 3u: return texture(textureArray[3], textureCoordinates);
|
|
||||||
case 4u: return texture(textureArray[4], textureCoordinates);
|
|
||||||
case 5u: return texture(textureArray[5], textureCoordinates);
|
|
||||||
case 6u: return texture(textureArray[6], textureCoordinates);
|
|
||||||
}
|
|
||||||
return texture(textureArray[0], textureCoordinates);
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 firstTexelColor = getTexture(passFirstTextureIdIndex, passFirstTextureCoordinates);
|
vec4 firstTexelColor = getTexture(passFirstTextureIdIndex, passFirstTextureCoordinates);
|
||||||
|
@ -19,23 +19,7 @@ flat in uint passTextureIdIndex;
|
|||||||
in vec3 passTextureCoordinates;
|
in vec3 passTextureCoordinates;
|
||||||
in vec4 passTintColor;
|
in vec4 passTintColor;
|
||||||
|
|
||||||
|
#include "minosoft:texture"
|
||||||
uniform sampler2DArray textureArray[7];
|
|
||||||
|
|
||||||
|
|
||||||
vec4 getTexture(uint textureId, vec3 textureCoordinates) { // ToDo: This method is just stupid, @see chunk_fragment.glsl
|
|
||||||
switch (textureId){
|
|
||||||
case 0u : return texture(textureArray[0], textureCoordinates);
|
|
||||||
case 1u: return texture(textureArray[1], textureCoordinates);
|
|
||||||
case 2u: return texture(textureArray[2], textureCoordinates);
|
|
||||||
case 3u: return texture(textureArray[3], textureCoordinates);
|
|
||||||
case 4u: return texture(textureArray[4], textureCoordinates);
|
|
||||||
case 5u: return texture(textureArray[5], textureCoordinates);
|
|
||||||
case 6u: return texture(textureArray[6], textureCoordinates);
|
|
||||||
}
|
|
||||||
return texture(textureArray[0], textureCoordinates);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 texelColor = getTexture(passTextureIdIndex, passTextureCoordinates);
|
vec4 texelColor = getTexture(passTextureIdIndex, passTextureCoordinates);
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
uniform sampler2DArray textureArray[7];
|
||||||
|
|
||||||
|
vec4 getTexture(uint textureId, vec3 textureCoordinates) { // ToDo: This method is just stupid and workarounds a opengl crash with mesa drivers
|
||||||
|
switch (textureId){
|
||||||
|
case 0u : return texture(textureArray[0], textureCoordinates);
|
||||||
|
case 1u: return texture(textureArray[1], textureCoordinates);
|
||||||
|
case 2u: return texture(textureArray[2], textureCoordinates);
|
||||||
|
case 3u: return texture(textureArray[3], textureCoordinates);
|
||||||
|
case 4u: return texture(textureArray[4], textureCoordinates);
|
||||||
|
case 5u: return texture(textureArray[5], textureCoordinates);
|
||||||
|
case 6u: return texture(textureArray[6], textureCoordinates);
|
||||||
|
}
|
||||||
|
return texture(textureArray[0], textureCoordinates);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user