более унифицированные имена юниформов

This commit is contained in:
DBotThePony 2023-02-21 12:58:15 +07:00
parent 9d41380c16
commit 2a7a62e6ed
Signed by: DBot
GPG Key ID: DCC23B5715498507
18 changed files with 144 additions and 126 deletions

View File

@ -301,7 +301,7 @@ class ClientChunk(world: ClientWorld, pos: ChunkPos) : Chunk<ClientWorld, Client
renderOrigin.y * CHUNK_SIZEf + (geometry.y + 1) * SHADOW_GEOMETRY_SQUARE_SIZE)
) {
if (!setOnce) {
program.localToWorldTransform.value =
program.localToWorldTransform =
Matrix4f.IDENTITY.translateWithMultiplication(
Vector3f(x = renderOrigin.x * CHUNK_SIZEf,
y = renderOrigin.y * CHUNK_SIZEf))
@ -337,7 +337,7 @@ class ClientChunk(world: ClientWorld, pos: ChunkPos) : Chunk<ClientWorld, Client
renderOrigin.y * CHUNK_SIZEf + (geometry.y + 1) * SHADOW_GEOMETRY_SQUARE_SIZE)
) {
if (!setOnce) {
program.localToWorldTransform.value =
program.localToWorldTransform =
Matrix4f.IDENTITY.translateWithMultiplication(
Vector3f(x = renderOrigin.x * CHUNK_SIZEf,
y = renderOrigin.y * CHUNK_SIZEf))
@ -393,7 +393,7 @@ class ClientChunk(world: ClientWorld, pos: ChunkPos) : Chunk<ClientWorld, Client
val program = state.programs.liquid
program.use()
program.transform.value = it.last
program.transform = it.last
val builder = program.builder
@ -410,7 +410,7 @@ class ClientChunk(world: ClientWorld, pos: ChunkPos) : Chunk<ClientWorld, Client
}
}
program.baselineColor.value = type.color
program.baselineColor = type.color
builder.upload()
builder.draw()

View File

@ -9,7 +9,6 @@ import ru.dbotthepony.kstarbound.client.freetype.FreeType
import ru.dbotthepony.kstarbound.client.freetype.InvalidArgumentException
import ru.dbotthepony.kstarbound.client.gl.shader.GLPrograms
import ru.dbotthepony.kstarbound.client.gl.shader.GLShaderProgram
import ru.dbotthepony.kstarbound.client.gl.shader.GLTransformableProgram
import ru.dbotthepony.kstarbound.client.gl.shader.ShaderCompilationException
import ru.dbotthepony.kstarbound.client.gl.vertex.GLAttributeList
import ru.dbotthepony.kstarbound.client.gl.vertex.StreamVertexBuilder
@ -19,6 +18,7 @@ import ru.dbotthepony.kstarbound.client.render.Box2DRenderer
import ru.dbotthepony.kstarbound.client.render.Font
import ru.dbotthepony.kvector.api.IStruct4f
import ru.dbotthepony.kvector.matrix.Matrix4fStack
import ru.dbotthepony.kvector.matrix.nfloat.Matrix4f
import ru.dbotthepony.kvector.util2d.AABB
import ru.dbotthepony.kvector.vector.Color
import java.io.File
@ -454,13 +454,24 @@ class GLStateTracker(val locator: ISBFileLocator) {
val shaderVertexTexture: TexturedProgram
val shaderVertexTextureColor: TexturedColoredProgram
inner class TexturedProgram(shaders: Iterable<Shader>) : GLTransformableProgram(this@GLStateTracker, shaders) {
val texture = IUniform("_texture")
inner class TexturedProgram(shaders: Iterable<Shader>) : GLShaderProgram(this@GLStateTracker, shaders) {
var transform by F4x4Uniform("transform")
var texture by IUniform("texture0")
init {
transform = Matrix4f.IDENTITY
}
}
inner class TexturedColoredProgram(shaders: Iterable<Shader>) : GLTransformableProgram(this@GLStateTracker, shaders) {
val texture = IUniform("_texture")
val color = F4Uniform("_color")
inner class TexturedColoredProgram(shaders: Iterable<Shader>) : GLShaderProgram(this@GLStateTracker, shaders) {
var transform by F4x4Uniform("transform")
var texture by IUniform("texture0")
var color by F4Uniform("color")
init {
transform = Matrix4f.IDENTITY
color = Color.WHITE
}
}
init {
@ -492,8 +503,8 @@ class GLStateTracker(val locator: ISBFileLocator) {
builder.upload()
programs.flat.use()
programs.flat.color.value = color
programs.flat.transform.value = matrixStack.last
programs.flat.color = color
programs.flat.transform = matrixStack.last
builder.draw(GL_LINES)
}
@ -506,7 +517,7 @@ class GLStateTracker(val locator: ISBFileLocator) {
builder.upload()
programs.flatColor.use()
programs.flatColor.transform.value = matrixStack.last
programs.flatColor.transform = matrixStack.last
builder.draw(GL_TRIANGLES)
}

View File

@ -23,25 +23,9 @@ private fun GLStateTracker.gshaders(name: String): List<GLStateTracker.Shader> {
)
}
open class GLTransformableProgram(state: GLStateTracker, shaders: Iterable<GLStateTracker.Shader>) : GLShaderProgram(state, shaders) {
val transform = F4x4Uniform("_transform")
init {
transform.value = Matrix4f.IDENTITY
}
}
open class GLTransformableColorableProgram(state: GLStateTracker, shaders: Iterable<GLStateTracker.Shader>) : GLTransformableProgram(state, shaders) {
val color = F4Uniform("_color")
init {
color.value = Color.WHITE
}
}
class GLLiquidProgram(state: GLStateTracker) : GLShaderProgram(state, state.shaders("liquid")) {
val baselineColor = F4Uniform("baselineColor")
val transform = F4x4Uniform("transform")
var baselineColor by F4Uniform("baselineColor")
var transform by F4x4Uniform("transform")
val builder by lazy {
StreamVertexBuilder(state, FORMAT, GeometryType.QUADS, 16384)
@ -53,8 +37,8 @@ class GLLiquidProgram(state: GLStateTracker) : GLShaderProgram(state, state.shad
}
class GLLightProgram(state: GLStateTracker) : GLShaderProgram(state, state.shaders("light")) {
val baselineColor = F4Uniform("baselineColor")
val transform = F4x4Uniform("transform")
var baselineColor by F4Uniform("baselineColor")
var transform by F4x4Uniform("transform")
val builder by lazy {
StreamVertexBuilder(state, FORMAT, GeometryType.QUADS, 32)
@ -66,10 +50,10 @@ class GLLightProgram(state: GLStateTracker) : GLShaderProgram(state, state.shade
}
class GLHardLightGeometryProgram(state: GLStateTracker) : GLShaderProgram(state, state.gshaders("hard_light_geometry")) {
val transform = F4x4Uniform("transform")
val localToWorldTransform = F4x4Uniform("localToWorldTransform")
val lightPosition = F2Uniform("lightPosition")
val lightPenetration = FUniform("lightPenetration")
var transform by F4x4Uniform("transform")
var localToWorldTransform by F4x4Uniform("localToWorldTransform")
var lightPosition by F2Uniform("lightPosition")
var lightPenetration by FUniform("lightPenetration")
val builder by lazy {
StreamVertexBuilder(state, GPULightRenderer.SHADOW_FORMAT, GeometryType.QUADS_AS_LINES, 32)
@ -77,14 +61,14 @@ class GLHardLightGeometryProgram(state: GLStateTracker) : GLShaderProgram(state,
}
class GLSoftLightGeometryProgram(state: GLStateTracker) : GLShaderProgram(state, state.shaders("soft_light_geometry2")) {
val transform = F4x4Uniform("transform")
val lightPenetration = FUniform("lightPenetration")
val localToWorldTransform = F4x4Uniform("localToWorldTransform")
var transform by F4x4Uniform("transform")
var lightPenetration by FUniform("lightPenetration")
var localToWorldTransform by F4x4Uniform("localToWorldTransform")
/**
* Vector3f(x, y, size)
*/
val lightPositionAndSize = F3Uniform("lightPositionAndSize")
var lightPositionAndSize by F3Uniform("lightPositionAndSize")
val builder by lazy {
StreamVertexBuilder(state, GPULightRenderer.SHADOW_FORMAT_SOFT, GeometryType.QUADS_AS_LINES, 32)
@ -92,7 +76,7 @@ class GLSoftLightGeometryProgram(state: GLStateTracker) : GLShaderProgram(state,
}
class GLColorQuadProgram(state: GLStateTracker) : GLShaderProgram(state, state.shaders("screen_quad")) {
val color = F4Uniform("color")
var color by F4Uniform("color")
private val builder by lazy {
val builder = StreamVertexBuilder(state, FORMAT, GeometryType.QUADS, 1)
@ -107,7 +91,7 @@ class GLColorQuadProgram(state: GLStateTracker) : GLShaderProgram(state, state.s
fun clearAlpha() {
use()
color.value = ALPHA
color = ALPHA
val old = state.blend
val oldFunc = state.blendFunc
@ -122,7 +106,7 @@ class GLColorQuadProgram(state: GLStateTracker) : GLShaderProgram(state, state.s
fun clearColor(color: Color = Color.WHITE) {
use()
this.color.value = color
this.color = color
val old = state.blend
@ -138,7 +122,7 @@ class GLColorQuadProgram(state: GLStateTracker) : GLShaderProgram(state, state.s
}
class GLTextureQuadProgram(state: GLStateTracker) : GLShaderProgram(state, state.shaders("screen_quad_tex")) {
val texture = IUniform("texture0")
var texture by IUniform("texture0")
private val builder by lazy {
val builder = StreamVertexBuilder(state, FORMAT, GeometryType.QUADS, 1)
@ -152,7 +136,7 @@ class GLTextureQuadProgram(state: GLStateTracker) : GLShaderProgram(state, state
fun run(texture: Int = 0) {
use()
this.texture.value = texture
this.texture = texture
builder.draw()
}
@ -162,7 +146,7 @@ class GLTextureQuadProgram(state: GLStateTracker) : GLShaderProgram(state, state
}
class GLTextureBlurredQuadProgram(state: GLStateTracker) : GLShaderProgram(state, state.shaders("screen_quad_tex_blur")) {
val texture = IUniform("texture0")
var texture by IUniform("texture0")
private val builder by lazy {
val builder = StreamVertexBuilder(state, FORMAT, GeometryType.QUADS, 1)
@ -176,7 +160,7 @@ class GLTextureBlurredQuadProgram(state: GLStateTracker) : GLShaderProgram(state
fun run(texture: Int = 0) {
use()
this.texture.value = texture
this.texture = texture
builder.draw()
}
@ -186,7 +170,7 @@ class GLTextureBlurredQuadProgram(state: GLStateTracker) : GLShaderProgram(state
}
class GLFlatColorProgram(state: GLStateTracker) : GLShaderProgram(state, state.shaders("flat_color")) {
val transform = F4x4Uniform("transform")
var transform by F4x4Uniform("transform")
val builder by lazy {
StreamVertexBuilder(state, FORMAT, GeometryType.QUADS, 16384)
@ -197,18 +181,41 @@ class GLFlatColorProgram(state: GLStateTracker) : GLShaderProgram(state, state.s
}
}
class GLTileProgram(state: GLStateTracker) : GLTransformableColorableProgram(state, state.shaders("tile")) {
var texture by IUniform("_texture")
class GLTileProgram(state: GLStateTracker) : GLShaderProgram(state, state.shaders("tile")) {
var transform by F4x4Uniform("transform")
var color by F4Uniform("color")
var texture by IUniform("texture0")
init {
transform = Matrix4f.IDENTITY
color = Color.WHITE
}
}
class GLFontProgram(state: GLStateTracker) : GLTransformableColorableProgram(state, state.shaders("font")) {
var texture by IUniform("_texture")
class GLFontProgram(state: GLStateTracker) : GLShaderProgram(state, state.shaders("font")) {
var transform by F4x4Uniform("transform")
var color by F4Uniform("color")
var texture by IUniform("texture0")
init {
transform = Matrix4f.IDENTITY
color = Color.WHITE
}
}
class GLFlatProgram(state: GLStateTracker) : GLShaderProgram(state, state.shaders("flat")) {
var transform by F4x4Uniform("transform")
var color by F4Uniform("color")
init {
color = Color.WHITE
}
}
class GLPrograms(val state: GLStateTracker) {
val tile by lazy { GLTileProgram(state) }
val font by lazy { GLFontProgram(state) }
val flat by lazy { GLTransformableColorableProgram(state, state.shaders("flat")) }
val flat by lazy { GLFlatProgram(state) }
val flatColor by lazy { GLFlatColorProgram(state) }
val liquid by lazy { GLLiquidProgram(state) }
val light by lazy { GLLightProgram(state) }

View File

@ -34,8 +34,8 @@ class Box2DRenderer(val state: GLStateTracker) : IDebugDraw {
builder.upload()
state.programs.flat.use()
state.programs.flat.color.value = color
state.programs.flat.transform.value = state.matrixStack.last
state.programs.flat.color = color
state.programs.flat.transform = state.matrixStack.last
builder.draw(GL_LINES)
}
@ -60,8 +60,8 @@ class Box2DRenderer(val state: GLStateTracker) : IDebugDraw {
builder.upload()
state.programs.flat.use()
state.programs.flat.color.value = color
state.programs.flat.transform.value = state.matrixStack.last
state.programs.flat.color = color
state.programs.flat.transform = state.matrixStack.last
builder.draw(GL_TRIANGLES)
}

View File

@ -22,7 +22,7 @@ import ru.dbotthepony.kvector.matrix.Matrix4fStack
open class ConfiguredShaderProgram<T : GLShaderProgram>(
val program: T,
) {
private val transformLocation = program.getUniform("_transform") as? GLShaderProgram.F4x4Uniform
private val transformLocation = program.getUniform("transform") as? GLShaderProgram.F4x4Uniform
open fun setTransform(value: IMatrix4f<*>) {
transformLocation?.value = value

View File

@ -113,7 +113,7 @@ class Font(
stack.scale(x = scale, y = scale)
state.programs.font.use()
state.programs.font.color.value = color
state.programs.font.color = color
state.activeTexture = 0
val space = getGlyph(' ')
@ -343,7 +343,7 @@ class Font(
stack.translateWithMultiplication(bearingX, -bearingY)
texture!!.bind()
state.programs.font.transform.value = stack.last
state.programs.font.transform = stack.last
glDrawElements(GL_TRIANGLES, indexCount, elementIndexType, 0L)
checkForGLError()

View File

@ -164,9 +164,9 @@ class GPULightRenderer(val state: GLStateTracker) {
state.clearColor = old
state.programs.hardLightGeometry.use()
state.programs.hardLightGeometry.transform.value = (stack.last)
state.programs.hardLightGeometry.lightPosition.value = (position)
state.programs.hardLightGeometry.lightPenetration.value = (1f - lightPenetration)
state.programs.hardLightGeometry.transform = (stack.last)
state.programs.hardLightGeometry.lightPosition = (position)
state.programs.hardLightGeometry.lightPenetration = (1f - lightPenetration)
state.blendFunc = BlendFunc.ONLY_BLEND_ALPHA
@ -175,8 +175,8 @@ class GPULightRenderer(val state: GLStateTracker) {
}
state.programs.light.use()
state.programs.light.transform.value = (stack.last)
state.programs.light.baselineColor.value = (color)
state.programs.light.transform = (stack.last)
state.programs.light.baselineColor = (color)
// Свет
val builder = state.programs.light.builder
@ -225,9 +225,9 @@ class GPULightRenderer(val state: GLStateTracker) {
state.clearColor = old
state.programs.softLightGeometry.use()
state.programs.softLightGeometry.transform.value = (stack.last)
state.programs.softLightGeometry.lightPositionAndSize.value = (Vector3f(position, innerRadius))
state.programs.softLightGeometry.lightPenetration.value = (lightPenetration)
state.programs.softLightGeometry.transform = (stack.last)
state.programs.softLightGeometry.lightPositionAndSize = (Vector3f(position, innerRadius))
state.programs.softLightGeometry.lightPenetration = (lightPenetration)
state.blendFunc = BlendFunc.ONLY_BLEND_ALPHA
@ -241,8 +241,8 @@ class GPULightRenderer(val state: GLStateTracker) {
state.cull = false
state.programs.light.use()
state.programs.light.transform.value = (stack.last)
state.programs.light.baselineColor.value = (color)
state.programs.light.transform = (stack.last)
state.programs.light.baselineColor = (color)
// Свет
val builder = state.programs.light.builder

View File

@ -94,7 +94,7 @@ class TileRenderers(val client: StarboundClient) {
texture.textureMagFilter = GL_NEAREST
texture.textureMinFilter = GL_NEAREST
program.color.value = FOREGROUND_COLOR
program.color = FOREGROUND_COLOR
}
override fun equals(other: Any?): Boolean {
@ -124,7 +124,7 @@ class TileRenderers(val client: StarboundClient) {
texture.textureMagFilter = GL_NEAREST
texture.textureMinFilter = GL_NEAREST
program.color.value = BACKGROUND_COLOR
program.color = BACKGROUND_COLOR
}
override fun equals(other: Any?): Boolean {

View File

@ -16,9 +16,9 @@ class ItemRenderer(state: GLStateTracker, entity: ItemEntity, chunk: ClientChunk
return
state.shaderVertexTexture.use()
state.shaderVertexTexture.transform.value = (stack.last)
state.shaderVertexTexture.transform = stack.last
state.activeTexture = 0
state.shaderVertexTexture.texture.value = 0
state.shaderVertexTexture.texture = 0
for (texture in textures) {
texture.bind()

View File

@ -1,9 +1,9 @@
#version 460
uniform vec4 _color;
out vec4 _color_out;
uniform vec4 color;
out vec4 color_out;
void main() {
_color_out = _color;
color_out = color;
}

View File

@ -1,9 +1,9 @@
#version 460
layout (location = 0) in vec2 _pos;
uniform mat4 _transform;
layout (location = 0) in vec2 pos;
uniform mat4 transform;
void main() {
gl_Position = _transform * vec4(_pos, 0.5, 1.0);
gl_Position = transform * vec4(pos, 0.5, 1.0);
}

View File

@ -1,12 +1,12 @@
#version 460
in vec2 _uv_out;
out vec4 _color_out;
in vec2 uv_out;
out vec4 color_out;
uniform sampler2D _texture;
uniform vec4 _color;
uniform sampler2D texture0;
uniform vec4 color;
void main() {
_color_out = _color * texture(_texture, _uv_out).r;
color_out = color * texture(texture0, uv_out).r;
}

View File

@ -1,14 +1,14 @@
#version 460
layout (location = 0) in vec2 _pos;
layout (location = 1) in vec2 _uv_in;
layout (location = 0) in vec2 pos;
layout (location = 1) in vec2 uv_in;
out vec2 _uv_out;
out vec2 uv_out;
uniform mat4 _transform;
uniform mat4 transform;
void main() {
_uv_out = _uv_in;
gl_Position = _transform * vec4(_pos, 0.0, 1.0);
uv_out = uv_in;
gl_Position = transform * vec4(pos, 0.0, 1.0);
}

View File

@ -1,13 +1,13 @@
#version 460
uniform sampler2D _texture;
uniform sampler2D texture0;
in vec2 _uv_out;
in vec2 uv_out;
out vec4 _color_out;
out vec4 color_out;
void main() {
vec4 texel = texture(_texture, _uv_out);
_color_out = texel;
vec4 texel = texture(texture0, uv_out);
color_out = texel;
}

View File

@ -1,13 +1,13 @@
#version 460
uniform sampler2D _texture;
uniform vec4 _color;
uniform sampler2D texture0;
uniform vec4 color;
in vec2 _uv_out;
out vec4 _color_out;
in vec2 uv_out;
out vec4 color_out;
void main() {
vec4 texel = texture(_texture, _uv_out);
_color_out = texel * _color;
vec4 texel = texture(texture0, uv_out);
color_out = texel * color;
}

View File

@ -1,12 +1,12 @@
#version 460
uniform sampler2D _texture;
uniform vec4 _color;
uniform sampler2D texture0;
uniform vec4 color;
in vec2 _uv_out;
in float _hsv_vertex;
out vec4 _color_out;
in vec2 uv_out;
in float hsv_vertex;
out vec4 color_out;
// https://gist.github.com/983/e170a24ae8eba2cd174f
vec3 rgb2hsv(vec3 c)
@ -28,11 +28,11 @@ vec3 hsv2rgb(vec3 c)
}
void main() {
vec4 texel = texture(_texture, _uv_out);
vec4 texel = texture(texture0, uv_out);
vec3 hsv2 = rgb2hsv(vec3(texel[0], texel[1], texel[2]));
hsv2[0] += _hsv_vertex / 360;
hsv2[0] += hsv_vertex / 360;
vec4 rgb2 = vec4(hsv2rgb(hsv2), texel[3]);
_color_out = _color * rgb2;
color_out = color * rgb2;
}

View File

@ -1,16 +1,16 @@
#version 460
layout (location = 0) in vec3 _pos;
layout (location = 1) in vec2 _uv_in;
layout (location = 2) in float _hsv_in;
layout (location = 0) in vec3 pos;
layout (location = 1) in vec2 uv_in;
layout (location = 2) in float hsv_in;
out vec2 _uv_out;
out float _hsv_vertex;
uniform mat4 _transform;
out vec2 uv_out;
out float hsv_vertex;
uniform mat4 transform;
void main() {
_uv_out = _uv_in;
_hsv_vertex = _hsv_in;
gl_Position = _transform * vec4(_pos, 1.0);
uv_out = uv_in;
hsv_vertex = hsv_in;
gl_Position = transform * vec4(pos, 1.0);
}

View File

@ -1,13 +1,13 @@
#version 460
layout (location = 0) in vec3 _pos;
layout (location = 1) in vec2 _uv_in;
layout (location = 0) in vec3 pos;
layout (location = 1) in vec2 uv_in;
out vec2 _uv_out;
uniform mat4 _transform;
out vec2 uv_out;
uniform mat4 transform;
void main() {
_uv_out = _uv_in;
gl_Position = _transform * vec4(_pos, 1.0);
uv_out = uv_in;
gl_Position = transform * vec4(pos, 1.0);
}