use floats for instance colour memory

This commit is contained in:
a dinosaur 2024-08-19 07:59:36 +10:00
parent f203bcc7c1
commit 8904db24a5
4 changed files with 7 additions and 3 deletions

View File

@ -89,6 +89,10 @@ public extension Color where T: BinaryFloatingPoint {
self.init(r: newR, g: newG, b: newB, a: Self.one)
}
init<U: BinaryFloatingPoint>(_ other: Color<U>) {
self._values = SIMD4<T>(other._values)
}
init<U: BinaryInteger>(_ other: Color<U>) {
let mul = 1 / T(0xFF)
self.init(

View File

@ -380,7 +380,7 @@ public class Renderer {
.scale(instance.scale)
data[i] = VertexShaderInstance(
model: model, normalModel: model.inverse.transpose,
color: SIMD4(Color<UInt8>(instance.color)))
color: SIMD4(Color<Float>(instance.color)))
}
}
instanceBuffer.didModifyRange(0..<instancesBytes)

View File

@ -23,7 +23,7 @@ vertex FragmentInput vertexMain(
FragmentInput out;
out.position = u.projView * world;
out.world = world.xyz;
out.color = half4(i[instanceID].color) / 255.0;
out.color = half4(i[instanceID].color);
out.normal = (i[instanceID].normalModel * vtx[vertexID].normal).xyz;
out.texCoord = vtx[vertexID].texCoord;
return out;

View File

@ -25,7 +25,7 @@ typedef struct {
typedef struct {
matrix_float4x4 model;
matrix_float4x4 normalModel;
vector_uchar4 color;
vector_float4 color;
} VertexShaderInstance;
typedef struct {