mirror of
https://github.com/GayPizzaSpecifications/voxelotl-engine.git
synced 2025-08-03 13:11:33 +00:00
instancing
This commit is contained in:
@ -1,25 +1,28 @@
|
||||
#include "shadertypes.h"
|
||||
|
||||
#include <metal_stdlib>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
struct FragmentInput {
|
||||
float4 position [[position]];
|
||||
float4 normal;
|
||||
float2 texCoord;
|
||||
half4 color;
|
||||
};
|
||||
|
||||
vertex FragmentInput vertexMain(
|
||||
uint vertexID [[vertex_id]],
|
||||
uint instanceID [[instance_id]],
|
||||
device const ShaderVertex* vtx [[buffer(ShaderInputIdxVertices)]],
|
||||
device const ShaderInstance* i [[buffer(ShaderInputIdxInstance)]],
|
||||
constant ShaderUniforms& u [[buffer(ShaderInputIdxUniforms)]]
|
||||
) {
|
||||
auto position = vtx[vertexID].position;
|
||||
position = u.projView * u.model * position;
|
||||
auto world = i[instanceID].model * position;
|
||||
auto ndc = u.projView * world;
|
||||
|
||||
FragmentInput out;
|
||||
out.position = position;
|
||||
out.position = ndc;
|
||||
out.color = half4(i[instanceID].color);
|
||||
out.normal = vtx[vertexID].normal;
|
||||
out.texCoord = vtx[vertexID].texCoord;
|
||||
return out;
|
||||
@ -27,10 +30,9 @@ vertex FragmentInput vertexMain(
|
||||
|
||||
fragment half4 fragmentMain(
|
||||
FragmentInput in [[stage_in]],
|
||||
texture2d<half, access::sample> tex [[texture(0)]]
|
||||
metal::texture2d<half, metal::access::sample> texture [[texture(0)]]
|
||||
) {
|
||||
constexpr sampler s(address::repeat, filter::nearest);
|
||||
half4 albedo = tex.sample(s, in.texCoord);
|
||||
|
||||
return half4(albedo.rgb, 1.0);
|
||||
constexpr metal::sampler sampler(metal::address::repeat, metal::filter::nearest);
|
||||
half4 albedo = texture.sample(sampler, in.texCoord);
|
||||
return albedo * in.color;
|
||||
}
|
||||
|
Reference in New Issue
Block a user