Skip to content

Commit 2c7acdb

Browse files
committed
fix function return types a little along with tests
1 parent 2b8d4b9 commit 2c7acdb

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

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

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -490,20 +490,27 @@ data class Program(val vertex: VertexShader, val fragment: FragmentShader, val n
490490
val out: Output get() = Output
491491
//fun out(to: Operand) = Stm.Set(if (type == ShaderType.VERTEX) out_Position else out_FragColor, to)
492492

493-
fun sin(arg: Operand): Operand = Func("sin", arg)
494-
fun cos(arg: Operand): Operand = Func("cos", arg)
495-
fun tan(arg: Operand): Operand = Func("tan", arg)
493+
fun sin(angle: Operand): Operand = Func("sin", angle, type = angle.type)
494+
fun cos(angle: Operand): Operand = Func("cos", angle, type = angle.type)
495+
fun tan(angle: Operand): Operand = Func("tan", angle, type = angle.type)
496496

497-
fun asin(arg: Operand): Operand = Func("asin", arg)
498-
fun acos(arg: Operand): Operand = Func("acos", arg)
499-
fun atan(y_over_x: Operand): Operand = Func("atan", y_over_x)
497+
fun asin(x: Operand): Operand = Func("asin", x, type = x.type)
498+
fun acos(x: Operand): Operand = Func("acos", x, type = x.type)
499+
fun atan(yOverX: Operand): Operand = Func("atan", yOverX)
500500
fun atan(y: Operand, x: Operand): Operand = Func("atan", y, x)
501501

502+
fun sinh(x: Operand): Operand = Func("sinh", x, type = x.type)
503+
fun cosh(x: Operand): Operand = Func("cosh", x, type = x.type)
504+
fun tanh(x: Operand): Operand = Func("tanh", x, type = x.type)
505+
fun asinh(x: Operand): Operand = Func("asinh", x, type = x.type)
506+
fun acosh(x: Operand): Operand = Func("acosh", x, type = x.type)
507+
fun atanh(x: Operand): Operand = Func("atanh", x, type = x.type)
508+
502509
// @TODO: https://en.wikipedia.org/wiki/Atan2#Definition_and_computation (IF chain)
503510
//fun atan2(a: Operand, b: Operand): Operand = atan(a / b) * 2f.lit
504511

505-
fun radians(arg: Operand): Operand = Func("radians", arg)
506-
fun degrees(arg: Operand): Operand = Func("degrees", arg)
512+
fun radians(degrees: Operand): Operand = Func("radians", degrees, type = degrees.type)
513+
fun degrees(radians: Operand): Operand = Func("degrees", radians, type = radians.type)
507514

508515
// Sampling
509516
fun texture2D(sampler: Operand, coord: Operand): Operand = Func("texture2D", sampler, coord, type = VarType.Float4)
@@ -517,27 +524,27 @@ data class Program(val vertex: VertexShader, val fragment: FragmentShader, val n
517524
fun int(v: Operand): Operand = Func("int", v)
518525
fun float(v: Operand): Operand = Func("float", v)
519526

520-
fun pow(b: Operand, e: Operand): Operand = Func("pow", b, e)
521-
fun exp(v: Operand): Operand = Func("exp", v)
522-
fun exp2(v: Operand): Operand = Func("exp2", v)
523-
fun log(v: Operand): Operand = Func("log", v)
524-
fun log2(v: Operand): Operand = Func("log2", v)
525-
fun sqrt(v: Operand): Operand = Func("sqrt", v)
526-
fun inversesqrt(v: Operand): Operand = Func("inversesqrt", v)
527+
fun pow(b: Operand, e: Operand): Operand = Func("pow", b, e, type = b.type)
528+
fun exp(v: Operand): Operand = Func("exp", v, type = v.type)
529+
fun exp2(v: Operand): Operand = Func("exp2", v, type = v.type)
530+
fun log(v: Operand): Operand = Func("log", v, type = v.type)
531+
fun log2(v: Operand): Operand = Func("log2", v, type = v.type)
532+
fun sqrt(v: Operand): Operand = Func("sqrt", v, type = v.type)
533+
fun inversesqrt(v: Operand): Operand = Func("inversesqrt", v, type = v.type)
527534

528-
fun abs(v: Operand): Operand = Func("abs", v)
529-
fun sign(v: Operand): Operand = Func("sign", v)
530-
fun ceil(v: Operand): Operand = Func("ceil", v)
531-
fun floor(v: Operand): Operand = Func("floor", v)
535+
fun abs(v: Operand): Operand = Func("abs", v, type = v.type)
536+
fun sign(v: Operand): Operand = Func("sign", v, type = v.type)
537+
fun ceil(v: Operand): Operand = Func("ceil", v, type = v.type)
538+
fun floor(v: Operand): Operand = Func("floor", v, type = v.type)
532539

533540
/** The fractional part of v. This is calculated as v - floor(v). */
534-
fun fract(v: Operand): Operand = Func("fract", v)
541+
fun fract(v: Operand): Operand = Func("fract", v, type = v.type)
535542

536543
fun clamp01(v: Operand): Operand = clamp(v, 0f.lit, 1f.lit)
537-
fun clamp(v: Operand, min: Operand, max: Operand): Operand = Func("clamp", v, min, max)
538-
fun min(a: Operand, b: Operand): Operand = Func("min", a, b)
539-
fun max(a: Operand, b: Operand): Operand = Func("max", a, b)
540-
fun mod(a: Operand, b: Operand): Operand = Func("mod", a, b)
544+
fun clamp(v: Operand, min: Operand, max: Operand): Operand = Func("clamp", v, min, max, type = v.type)
545+
fun min(a: Operand, b: Operand): Operand = Func("min", a, b, type = a.type)
546+
fun max(a: Operand, b: Operand): Operand = Func("max", a, b, type = a.type)
547+
fun mod(a: Operand, b: Operand): Operand = Func("mod", a, b, type = a.type)
541548

542549
//fun lerp(a: Operand, b: Operand, c: Operand): Operand = Func("lerp", a, b, c)
543550

@@ -554,10 +561,10 @@ data class Program(val vertex: VertexShader, val fragment: FragmentShader, val n
554561
//@JvmName("modInfix") infix fun Operand.mod(that: Operand): Operand = mod(this, that)
555562

556563
fun mix(a: Operand, b: Operand, step: Operand): Operand =
557-
Func("mix", a, b, step)
558-
fun step(a: Operand, b: Operand): Operand = Func("step", a, b)
564+
Func("mix", a, b, step, type = a.type)
565+
fun step(a: Operand, b: Operand): Operand = Func("step", a, b, type = a.type)
559566
fun smoothstep(a: Operand, b: Operand, c: Operand): Operand =
560-
Func("smoothstep", a, b, c)
567+
Func("smoothstep", a, b, c, type = a.type)
561568

562569
fun length(a: Operand): Operand = Func("length", a)
563570
fun distance(a: Operand, b: Operand): Operand = Func("distance", a, b)

0 commit comments

Comments
 (0)