Skip to content

Commit 48ab7bc

Browse files
committed
pass type everywhere explicitly
1 parent 4b23d06 commit 48ab7bc

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

korge-core/src/korlibs/graphics/shader/shaders.kt

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,8 @@ data class Program(val vertex: VertexShader, val fragment: FragmentShader, val n
496496

497497
fun asin(x: Operand): Operand = Func("asin", x, type = x.type)
498498
fun acos(x: Operand): Operand = Func("acos", x, type = x.type)
499-
fun atan(yOverX: Operand): Operand = Func("atan", yOverX)
500-
fun atan(y: Operand, x: Operand): Operand = Func("atan", y, x)
499+
fun atan(yOverX: Operand): Operand = Func("atan", yOverX, type = yOverX.type)
500+
fun atan(y: Operand, x: Operand): Operand = Func("atan", y, x, type = y.type)
501501

502502
fun sinh(x: Operand): Operand = Func("sinh", x, type = x.type)
503503
fun cosh(x: Operand): Operand = Func("cosh", x, type = x.type)
@@ -514,15 +514,15 @@ data class Program(val vertex: VertexShader, val fragment: FragmentShader, val n
514514

515515
// Sampling
516516
fun texture2D(sampler: Operand, coord: Operand): Operand = Func("texture2D", sampler, coord, type = VarType.Float4)
517-
fun texture(sampler: Operand, P: Operand): Operand = Func("texture", sampler, P)
517+
fun texture(sampler: Operand, P: Operand): Operand = Func("texture", sampler, P, type = VarType.Float4) // @TODO: calculate correct result type based on operand types
518518

519-
fun func(name: String, vararg args: Operand): Operand = Func(name, *args.map { it }.toTypedArray())
519+
fun func(name: String, vararg args: Operand, type: VarType = VarType.Float1): Operand = Func(name, *args.map { it }.toTypedArray(), type = type)
520520

521521
fun TERNARY(cond: Operand, otrue: Operand, ofalse: Operand): Operand = Ternary(cond, otrue, ofalse)
522522

523523
// CAST
524-
fun int(v: Operand): Operand = Func("int", v)
525-
fun float(v: Operand): Operand = Func("float", v)
524+
fun int(v: Operand): Operand = Func("int", v, type = VarType.Int1)
525+
fun float(v: Operand): Operand = Func("float", v, type = VarType.Float1)
526526

527527
fun pow(b: Operand, e: Operand): Operand = Func("pow", b, e, type = b.type)
528528
fun exp(v: Operand): Operand = Func("exp", v, type = v.type)
@@ -551,9 +551,9 @@ data class Program(val vertex: VertexShader, val fragment: FragmentShader, val n
551551
// https://learnwebgl.brown37.net/12_shader_language/documents/webgl-reference-card-1_0.pdf
552552
// #extension GL_OES_standard_derivatives : enable
553553
// https://stackoverflow.com/questions/68573364/enable-extension-and-fwidth-in-glsl
554-
fun fwidth(a: Operand): Operand = Func("fwidth", a)
555-
fun dFdx(a: Operand): Operand = Func("dFdx", a)
556-
fun dFdy(a: Operand): Operand = Func("dFdy", a)
554+
fun fwidth(a: Operand): Operand = Func("fwidth", a, type = a.type)
555+
fun dFdx(a: Operand): Operand = Func("dFdx", a, type = a.type)
556+
fun dFdy(a: Operand): Operand = Func("dFdy", a, type = a.type)
557557

558558
//lessThan
559559

@@ -566,16 +566,17 @@ data class Program(val vertex: VertexShader, val fragment: FragmentShader, val n
566566
fun smoothstep(a: Operand, b: Operand, c: Operand): Operand =
567567
Func("smoothstep", a, b, c, type = a.type)
568568

569-
fun length(a: Operand): Operand = Func("length", a)
570-
fun distance(a: Operand, b: Operand): Operand = Func("distance", a, b)
571-
fun dot(a: Operand, b: Operand): Operand = Func("dot", a, b)
572-
fun cross(a: Operand, b: Operand): Operand = Func("cross", a, b)
573-
fun normalize(a: Operand): Operand = Func("normalize", a)
569+
fun length(a: Operand): Operand = Func("length", a, type = VarType.Float1)
570+
fun distance(a: Operand, b: Operand): Operand = Func("distance", a, b, type = VarType.Float1)
571+
fun dot(a: Operand, b: Operand): Operand = Func("dot", a, b, type = VarType.Float1)
572+
fun cross(a: Operand, b: Operand): Operand = Func("cross", a, b, type = VarType.Float3)
573+
fun normalize(a: Operand): Operand = Func("normalize", a, type = a.type)
574574
fun faceforward(a: Operand, b: Operand, c: Operand): Operand =
575-
Func("faceforward", a, b, c)
576-
fun reflect(a: Operand, b: Operand): Operand = Func("reflect", a, b)
575+
Func("faceforward", a, b, c, type = a.type)
576+
fun reflect(a: Operand, b: Operand): Operand =
577+
Func("reflect", a, b, type = a.type)
577578
fun refract(a: Operand, b: Operand, c: Operand): Operand =
578-
Func("refract", a, b, c)
579+
Func("refract", a, b, c, type = a.type)
579580

580581
val Int.lit: IntLiteral get() = IntLiteral(this)
581582
@Deprecated("", ReplaceWith("this.toFloat().lit"))

0 commit comments

Comments
 (0)