.
This commit is contained in:
1 parent
a0b7e4c0d8
commit
6883d103ff
36 files changed
+2736
-1428
No files matched your search
@@ -0,0 +1,9 @@
|
||||
StructuredBuffer<float> input_buffer;
|
||||
RWStructuredBuffer<float> output_buffer;
|
||||
|
||||
[shader("compute")]
|
||||
[numthreads(32,1,1)]
|
||||
void main(uint3 thread_id : SV_DispatchThreadID)
|
||||
{
|
||||
output_buffer[thread_id.x] = 2.0 * input_buffer[thread_id.x];
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#include <metal_stdlib>
|
||||
#include <vertex_data.h>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
struct Vertex {
|
||||
float2 pos;
|
||||
float2 uv;
|
||||
};
|
||||
|
||||
constant Vertex vertices[6] = {
|
||||
{{-0.5, 0.5}, {0.0, 1.0}},
|
||||
{{-0.5, -0.5}, {0.0, 0.0}},
|
||||
{{ 0.5, 0.5}, {1.0, 1.0}},
|
||||
|
||||
{{ 0.5, 0.5}, {1.0, 1.0}},
|
||||
{{-0.5, -0.5}, {0.0, 0.0}},
|
||||
{{ 0.5, -0.5}, {1.0, 0.0}},
|
||||
};
|
||||
|
||||
struct VertexOut {
|
||||
float4 pos [[position]];
|
||||
float2 uv;
|
||||
float4 color;
|
||||
};
|
||||
|
||||
vertex VertexOut vertex_main(
|
||||
uint vertexID [[vertex_id]],
|
||||
constant vertex_p2_s2_uv2_c4_a1* in,
|
||||
constant simd::float4x4 *ortho)
|
||||
{
|
||||
Vertex v = vertices[vertexID % 6];
|
||||
|
||||
VertexOut out;
|
||||
out.pos = (*ortho) * (float4((v.pos * in[vertexID].scale) + in[vertexID].pos, 0.0, 1.0));
|
||||
out.uv = v.uv;
|
||||
out.color = in[vertexID].color;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
fragment float4 fragment_main(VertexOut in [[stage_in]], texture2d<float> colorTexture [[texture(0)]]) {
|
||||
constexpr sampler textureSampler (mag_filter::linear, min_filter::linear);
|
||||
|
||||
// Sample the texture to obtain a color
|
||||
const float4 colorSample = colorTexture.sample(textureSampler, in.uv);
|
||||
//float2 srgbOut = select(1.292 * in.uv,
|
||||
// 1.055 * pow(in.uv, 1.0/2.4) - 0.055,
|
||||
// in.uv > 0.0031308);
|
||||
return colorSample;
|
||||
//return float4(srgbOut, 0.0, in.color.a);
|
||||
}
|
||||
+16
-10
@@ -3,8 +3,7 @@ struct VSInput {
|
||||
float2 scale;
|
||||
float2 uv;
|
||||
float4 color;
|
||||
float alpha;
|
||||
uint32_t textureID;
|
||||
float alpha;
|
||||
|
||||
uint vertex_index : SV_VertexID;
|
||||
};
|
||||
@@ -14,10 +13,17 @@ struct VSOutput {
|
||||
float2 uv;
|
||||
float4 color;
|
||||
float alpha;
|
||||
uint32_t tex_id;
|
||||
//uint32_t tex_id;
|
||||
};
|
||||
|
||||
Sampler2D textures[];
|
||||
struct Uniforms {
|
||||
float4x4 proj;
|
||||
};
|
||||
|
||||
ConstantBuffer<Uniforms> uniforms : register(b1);
|
||||
|
||||
Texture2D colorTexture : register(t0);
|
||||
SamplerState samplerState;
|
||||
|
||||
static const float2 square[6] = {
|
||||
float2(-0.5, -0.5), // Top-left
|
||||
@@ -30,23 +36,23 @@ static const float2 square[6] = {
|
||||
};
|
||||
|
||||
[shader ("vertex")]
|
||||
VSOutput main(VSInput input, uniform float4x4 proj) {
|
||||
VSOutput vs_main(VSInput input) {
|
||||
VSOutput output;
|
||||
|
||||
float2 vertex_pos = square[input.vertex_index % 6];
|
||||
float2 final_pos = (vertex_pos * input.scale) + input.pos;
|
||||
|
||||
output.pos = mul(proj, float4(final_pos, 0.0, 1.0));
|
||||
output.pos = mul(uniforms.proj, float4(final_pos, 0.0, 1.0));
|
||||
output.uv = input.uv;
|
||||
output.color = input.color;
|
||||
output.alpha = input.alpha;
|
||||
output.tex_id = input.textureID;
|
||||
//output.tex_id = input.textureID;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
[shader("fragment")]
|
||||
float4 main(VSOutput input) {
|
||||
|
||||
return float4(input.color.rgb, input.alpha);
|
||||
float4 fs_main(VSOutput input) {
|
||||
float4 texColor = colorTexture.Sample(samplerState, input.uv);
|
||||
return texColor * float4(input.color.rgb, input.alpha);
|
||||
}
|
||||
Reference in new issue
Block a user