瀏覽代碼

kong + metal test

luboslenco 5 月之前
父節點
當前提交
ee9ec10f7b

+ 6 - 6
armorpaint/shaders/dilate_pass.kong

@@ -1,4 +1,10 @@
 
+#[set(everything)]
+const constants: {
+	dilate_radius: float;
+	tex_size: float2;
+};
+
 #[set(everything)]
 const tex: tex2d;
 
@@ -11,12 +17,6 @@ const texdilate: tex2d;
 #[set(everything)]
 const texdilate_sampler: sampler;
 
-#[set(everything)]
-const constants: {
-	dilate_radius: float;
-	tex_size: float2;
-};
-
 // const offsets: float2[8] = {
 // 	float2(-1.0,  0.0), float2( 1.0,  0.0), float2( 0.0,  1.0), float2( 0.0, -1.0),
 // 	float2(-1.0,  1.0), float2( 1.0,  1.0), float2( 1.0, -1.0), float2(-1.0, -1.0)

+ 5 - 5
armorpaint/shaders/layer_invert.kong

@@ -1,14 +1,14 @@
 
 #[set(everything)]
-const tex: tex2d;
+const constants: {
+	P: float4x4;
+};
 
 #[set(everything)]
-const tex_sampler: sampler;
+const tex: tex2d;
 
 #[set(everything)]
-const constants: {
-	P: float4x4;
-};
+const tex_sampler: sampler;
 
 struct vert_in {
 	pos: float3;

+ 7 - 7
armorpaint/shaders/layer_merge.kong

@@ -1,4 +1,11 @@
 
+#[set(everything)]
+const constants: {
+	opac: float;
+	blending: int;
+	tex1w: float;
+};
+
 #[set(everything)]
 const tex0: tex2d;
 
@@ -23,13 +30,6 @@ const texa: tex2d;
 #[set(everything)]
 const texa_sampler: sampler;
 
-#[set(everything)]
-const constants: {
-	opac: float;
-	blending: int;
-	tex1w: float;
-};
-
 struct vert_in {
 	pos: float2;
 }

+ 6 - 6
armorpaint/shaders/layer_view.kong

@@ -1,16 +1,16 @@
 
-#[set(everything)]
-const tex: tex2d;
-
-#[set(everything)]
-const tex_sampler: sampler;
-
 #[set(everything)]
 const constants: {
 	P: float4x4;
 	channel: int;
 };
 
+#[set(everything)]
+const tex: tex2d;
+
+#[set(everything)]
+const tex_sampler: sampler;
+
 struct vert_in {
 	pos: float3;
 	tex: float2;

+ 6 - 6
armorpaint/shaders/mask_merge.kong

@@ -1,4 +1,10 @@
 
+#[set(everything)]
+const constants: {
+	opac: float;
+	blending: int;
+};
+
 #[set(everything)]
 const tex0: tex2d;
 
@@ -11,12 +17,6 @@ const texa: tex2d;
 #[set(everything)]
 const texa_sampler: sampler;
 
-#[set(everything)]
-const constants: {
-	opac: float;
-	blending: int;
-};
-
 struct vert_in {
 	pos: float2;
 }

+ 6 - 6
base/shaders/bloom_downsample_pass.kong

@@ -1,16 +1,16 @@
 
-#[set(everything)]
-const tex: tex2d;
-
-#[set(everything)]
-const tex_sampler: sampler;
-
 #[set(everything)]
 const constants: {
 	screen_size_inv: float2;
 	current_mip_level: int;
 };
 
+#[set(everything)]
+const tex: tex2d;
+
+#[set(everything)]
+const tex_sampler: sampler;
+
 struct vert_in {
 	pos: float2;
 }

+ 6 - 6
base/shaders/bloom_upsample_pass.kong

@@ -1,10 +1,4 @@
 
-#[set(everything)]
-const tex: tex2d;
-
-#[set(everything)]
-const tex_sampler: sampler;
-
 #[set(everything)]
 const constants: {
 	screen_size_inv: float2;
@@ -12,6 +6,12 @@ const constants: {
 	sample_scale: float;
 };
 
+#[set(everything)]
+const tex: tex2d;
+
+#[set(everything)]
+const tex_sampler: sampler;
+
 struct vert_in {
 	pos: float2;
 }

+ 6 - 6
base/shaders/compositor_pass.kong

@@ -1,4 +1,10 @@
 
+#[set(everything)]
+const constants: {
+	vignette_strength: float;
+	grain_strength: float;
+};
+
 #[set(everything)]
 const tex: tex2d;
 
@@ -11,12 +17,6 @@ const tex_sampler: sampler;
 // #[set(everything)]
 // const histogram_sampler: sampler;
 
-#[set(everything)]
-const constants: {
-	vignette_strength: float;
-	grain_strength: float;
-};
-
 struct vert_in {
 	pos: float2;
 }

+ 17 - 17
base/shaders/deferred_light.kong

@@ -1,4 +1,21 @@
 
+#[set(everything)]
+const constants: {
+	invVP: float4x4;
+	eye: float3;
+	envmap_data: float4; // angle, sin(angle), cos(angle), strength
+	envmap_num_mipmaps: int;
+	camera_proj: float2;
+	eye_look: float3;
+	shirr0: float4;
+	shirr1: float4;
+	shirr2: float4;
+	shirr3: float4;
+	shirr4: float4;
+	shirr5: float4;
+	shirr6: float4;
+};
+
 #[set(everything)]
 const gbufferD: tex2d;
 
@@ -35,23 +52,6 @@ const ssaotex: tex2d;
 #[set(everything)]
 const ssaotex_sampler: sampler;
 
-#[set(everything)]
-const constants: {
-	invVP: float4x4;
-	eye: float3;
-	envmap_data: float4; // angle, sin(angle), cos(angle), strength
-	envmap_num_mipmaps: int;
-	camera_proj: float2;
-	eye_look: float3;
-	shirr0: float4;
-	shirr1: float4;
-	shirr2: float4;
-	shirr3: float4;
-	shirr4: float4;
-	shirr5: float4;
-	shirr6: float4;
-};
-
 const PI: float = 3.14159265358979;
 const PI2: float = 6.28318530718;
 

+ 5 - 5
base/shaders/layer_copy.kong

@@ -1,14 +1,14 @@
 
 #[set(everything)]
-const tex: tex2d;
+const constants: {
+	P: float4x4;
+};
 
 #[set(everything)]
-const tex_sampler: sampler;
+const tex: tex2d;
 
 #[set(everything)]
-const constants: {
-	P: float4x4;
-};
+const tex_sampler: sampler;
 
 struct vert_in {
 	pos: float3;

+ 5 - 5
base/shaders/layer_copy_bgra.kong

@@ -1,14 +1,14 @@
 
 #[set(everything)]
-const tex: tex2d;
+const constants: {
+	P: float4x4;
+};
 
 #[set(everything)]
-const tex_sampler: sampler;
+const tex: tex2d;
 
 #[set(everything)]
-const constants: {
-	P: float4x4;
-};
+const tex_sampler: sampler;
 
 struct vert_in {
 	pos: float3;

+ 5 - 5
base/shaders/prefilter_envmap.kong

@@ -1,14 +1,14 @@
 
 #[set(everything)]
-const radiance: tex2d;
+const constants: {
+	params: float4;
+};
 
 #[set(everything)]
-const radiance_sampler: sampler;
+const radiance: tex2d;
 
 #[set(everything)]
-const constants: {
-	params: float4;
-};
+const radiance_sampler: sampler;
 
 const PI: float = 3.14159265358979;
 const PI2: float = 6.28318530718;

+ 5 - 5
base/shaders/ssao_blur_pass.kong

@@ -1,4 +1,9 @@
 
+#[set(everything)]
+const constants: {
+	dir_inv: float2;
+};
+
 #[set(everything)]
 const tex: tex2d;
 
@@ -11,11 +16,6 @@ const gbuffer0: tex2d;
 #[set(everything)]
 const gbuffer0_sampler: sampler;
 
-#[set(everything)]
-const constants: {
-	dir_inv: float2;
-};
-
 // const blur_weights: float[] = {
 // 	0.132572, 0.125472, 0.106373, 0.08078, 0.05495, 0.033482, 0.018275, 0.008934, 0.003912, 0.001535
 // };

+ 8 - 8
base/shaders/ssao_pass.kong

@@ -1,4 +1,12 @@
 
+#[set(everything)]
+const constants: {
+	invP: float4x4;
+	P: float4x4;
+	V3: float3x3;
+	camera_proj: float2;
+};
+
 #[set(everything)]
 const gbufferD: tex2d;
 
@@ -11,14 +19,6 @@ const gbuffer0: tex2d;
 #[set(everything)]
 const gbuffer0_sampler: sampler;
 
-#[set(everything)]
-const constants: {
-	invP: float4x4;
-	P: float4x4;
-	V3: float3x3;
-	camera_proj: float2;
-};
-
 const max_steps: float = 32;
 const ray_step: float = 0.001;
 

+ 5 - 5
base/shaders/supersample_resolve.kong

@@ -1,14 +1,14 @@
 
 #[set(everything)]
-const tex: tex2d;
+const constants: {
+	screen_size_inv: float2;
+};
 
 #[set(everything)]
-const tex_sampler: sampler;
+const tex: tex2d;
 
 #[set(everything)]
-const constants: {
-	screen_size_inv: float2;
-};
+const tex_sampler: sampler;
 
 struct vert_in {
 	pos: float2;

+ 5 - 5
base/shaders/taa_pass.kong

@@ -1,4 +1,9 @@
 
+#[set(everything)]
+const constants: {
+	taa_blend: float;
+};
+
 #[set(everything)]
 const tex: tex2d;
 
@@ -11,11 +16,6 @@ const tex2: tex2d;
 #[set(everything)]
 const tex2_sampler: sampler;
 
-#[set(everything)]
-const constants: {
-	taa_blend: float;
-};
-
 struct vert_in {
 	pos: float2;
 }

+ 1 - 1
base/sources/backends/metal_gpu.m

@@ -464,7 +464,7 @@ void iron_gpu_command_list_set_vertex_constant_buffer(iron_gpu_command_list_t *l
 void iron_gpu_command_list_set_fragment_constant_buffer(iron_gpu_command_list_t *list, struct iron_gpu_buffer *buffer, int offset, size_t size) {
 	id<MTLBuffer> buf = (__bridge id<MTLBuffer>)buffer->impl._buffer;
 	id<MTLRenderCommandEncoder> encoder = getMetalEncoder();
-	[encoder setFragmentBuffer:buf offset:offset atIndex:0];
+	[encoder setFragmentBuffer:buf offset:offset atIndex:1];
 }
 
 void iron_gpu_command_list_render_target_to_texture_barrier(iron_gpu_command_list_t *list, struct iron_gpu_texture *renderTarget) {

+ 8 - 8
base/sources/ts/node_shader.ts

@@ -195,14 +195,6 @@ function node_shader_get(raw: node_shader_t): string {
 	}
 	s += "}\n\n";
 
-	for (let i: i32 = 0; i < raw.textures.length; ++i) {
-		let a: string = raw.textures[i];
-		s += "#[set(everything)]\n";
-		s += "const " + a + ": tex2d;\n";
-		s += "#[set(everything)]\n";
-		s += "const " + a + "_sampler: sampler;\n\n";
-	}
-
 	if (raw.constants.length > 0) {
 		s += "#[set(everything)]\n";
 		s += "const constants: {\n";
@@ -213,6 +205,14 @@ function node_shader_get(raw: node_shader_t): string {
 		s += "};\n\n";
 	}
 
+	for (let i: i32 = 0; i < raw.textures.length; ++i) {
+		let a: string = raw.textures[i];
+		s += "#[set(everything)]\n";
+		s += "const " + a + ": tex2d;\n";
+		s += "#[set(everything)]\n";
+		s += "const " + a + "_sampler: sampler;\n\n";
+	}
+
 	for (let i: i32 = 0; i < raw.shared_samplers.length; ++i) {
 		let a: string = raw.shared_samplers[i];
 		s += "#[set(everything)]\n";