mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 19:14:05 +09:00
new lighting wip
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user