#include using namespace metal; struct Camera { float4x4 view_proj; float3 position; }; struct Lighting { float3 direction; float3 color; float intensity; }; struct VertexOutput { float4 position [[position]]; float2 uv [[user(locn0)]]; }; struct FragmentOutput { float4 color [[user(locn0)]]; }; fragment FragmentOutput fs_main(VertexOutput input [[stage_in]], constant Lighting& lighting [[buffer(0)]], texture2d diffuse_tex_tex [[texture(0)]], sampler diffuse_tex_samp [[sampler(0)]], texture2d normal_tex_tex [[texture(1)]], sampler normal_tex_samp [[sampler(1)]]) { FragmentOutput __luma_output; float4 diffuse = diffuse_tex_tex.sample(diffuse_tex_samp, input.uv); float4 normal_sample = normal_tex_tex.sample(normal_tex_samp, input.uv); float3 n = normalize(((normal_sample.xyz * 2.0) - float3(1.0, 1.0, 1.0))); float3 l = normalize(lighting.direction); float ndotl = max(dot(n, l), 0.0); float3 lit = (((diffuse.rgb * lighting.color) * ndotl) * lighting.intensity); __luma_output.color = float4(lit, diffuse.a); return __luma_output; }