new lighting wip

This commit is contained in:
minjaesong
2022-10-04 22:01:28 +09:00
parent 9091e6af00
commit aff64f6a8e
4 changed files with 39 additions and 56 deletions

View File

@@ -89,7 +89,7 @@ class Cvec {
* - 2: B
* - 3: A
*/
fun getElem(index: Int) = when(index) {
fun lane(index: Int) = when(index) {
0 -> r
1 -> g
2 -> b
@@ -419,6 +419,20 @@ class Cvec {
return Cvec(this)
}
/**
* Creates a new Cvec that this Cvec transformed by the given function.
*
* @param transformation a function with two parameters: (`this.lane(i)`, `i`) and returns a float value
*/
fun lanewise(transformation: (Float, Int) -> Float): Cvec {
return Cvec(
transformation(this.r, 0),
transformation(this.g, 1),
transformation(this.b, 2),
transformation(this.a, 3)
)
}
companion object {
val WHITE = Cvec(1f, 1f, 1f, 1f)

View File

@@ -95,7 +95,7 @@ internal class UnsafeCvecArray(val width: Int, val height: Int) {
fun forAllMulAssign(vector: Cvec) {
for (i in 0 until TOTAL_SIZE_IN_BYTES / 4 step 4) {
for (k in 0 until 4) {
array.setFloat(i + 4*k, array.getFloat(i + k) * vector.getElem(k))
array.setFloat(i + 4*k, array.getFloat(i + k) * vector.lane(k))
}
}
}