Metal raytracing fixes

This commit is contained in:
luboslenco
2023-07-10 18:17:03 +02:00
parent aee49e4d56
commit bdf1b9bef2
10 changed files with 27 additions and 17 deletions
+1 -1
View File
@@ -149,7 +149,7 @@ class MakeMesh {
var color = Context.raw.viewportShader(frag);
frag.write('fragColor[1] = vec4($color, 1.0);');
}
else if (Context.raw.renderMode == RenderForward) {
else if (Context.raw.renderMode == RenderForward && Context.raw.viewportMode != ViewPathTrace) {
frag.wposition = true;
frag.write('vec3 albedo = mix(basecol, vec3(0.0, 0.0, 0.0), metallic);');
frag.write('vec3 f0 = mix(vec3(0.04, 0.04, 0.04), basecol, metallic);');
+1 -1
View File
@@ -344,7 +344,7 @@ class MakeMesh {
var color = Context.raw.viewportShader(frag);
frag.write('fragColor[1] = vec4($color, 1.0);');
}
else if (Context.raw.renderMode == RenderForward) {
else if (Context.raw.renderMode == RenderForward && Context.raw.viewportMode != ViewPathTrace) {
frag.wposition = true;
frag.write('vec3 albedo = mix(basecol, vec3(0.0, 0.0, 0.0), metallic);');
frag.write('vec3 f0 = mix(vec3(0.04, 0.04, 0.04), basecol, metallic);');
+1 -1
View File
@@ -23,7 +23,7 @@ struct RayPayload {
float3 ray_dir;
};
constant int SAMPLES = 64;
constant int SAMPLES = 4;//64;
float rand(int pixel_i, int pixel_j, int sampleIndex, int sampleDimension, int frame, texture2d<float, access::read> sobol, texture2d<float, access::read> scramble, texture2d<float, access::read> rank) {
pixel_i += frame * 9;
@@ -23,7 +23,7 @@ struct RayPayload {
float3 ray_dir;
};
constant int SAMPLES = 64;
constant int SAMPLES = 4;//64;
float rand(int pixel_i, int pixel_j, int sampleIndex, int sampleDimension, int frame, texture2d<float, access::read> sobol, texture2d<float, access::read> scramble, texture2d<float, access::read> rank) {
pixel_i += frame * 9;
@@ -23,7 +23,7 @@ struct RayPayload {
float3 ray_dir;
};
constant int SAMPLES = 64;
constant int SAMPLES = 4;//64;
float2 equirect(float3 normal, float angle) {
const float PI = 3.1415926535;
@@ -23,7 +23,7 @@ struct RayPayload {
float3 ray_dir;
};
constant int SAMPLES = 64;
constant int SAMPLES = 4;//64;
float rand(int pixel_i, int pixel_j, int sampleIndex, int sampleDimension, int frame, texture2d<float, access::read> sobol, texture2d<float, access::read> scramble, texture2d<float, access::read> rank) {
pixel_i += frame * 9;
@@ -4,7 +4,7 @@
#define _SUBSURFACE
#define _TRANSLUCENCY
#endif
// #define _RENDER
#define _RENDER
// #define _ROULETTE
// #define _TRANSPARENCY
@@ -30,11 +30,11 @@ struct RayPayload {
float3 ray_dir;
};
constant int SAMPLES = 8;//64;
constant int SAMPLES = 2; // 64
#ifdef _TRANSLUCENCY
constant int DEPTH = 6;
#else
constant int DEPTH = 2;//3; // Opaque hits
constant int DEPTH = 3; // Opaque hits
#endif
#ifdef _TRANSPARENCY
constant int DEPTH_TRANSPARENT = 16; // Transparent hits
@@ -355,6 +355,6 @@ kernel void raytracingKernel(
if (constant_buffer.eye.w == 0) {
color = accum.xyz / SAMPLES;
}
render_target.write(float4(mix(color.xyz, accum.xyz / SAMPLES, 1.0 / 4.0), 0.0f), tid);
render_target.write(float4(mix(color.xyz, accum.xyz / SAMPLES, 1.0 / 16.0), 0.0f), tid);
#endif
}
@@ -1,10 +1,10 @@
#define FULL
#define _FULL
#ifdef _FULL
#define _EMISSION
#define _SUBSURFACE
#define _TRANSLUCENCY
#endif
// #define _RENDER
#define _RENDER
// #define _ROULETTE
// #define _TRANSPARENCY
@@ -30,7 +30,7 @@ struct RayPayload {
float3 ray_dir;
};
constant int SAMPLES = 64;
constant int SAMPLES = 2; // 64
#ifdef _TRANSLUCENCY
constant int DEPTH = 6;
#else
@@ -355,6 +355,6 @@ kernel void raytracingKernel(
if (constant_buffer.eye.w == 0) {
color = accum.xyz / SAMPLES;
}
render_target.write(float4(mix(color.xyz, accum.xyz / SAMPLES, 1.0 / 4.0), 0.0f), tid);
render_target.write(float4(mix(color.xyz, accum.xyz / SAMPLES, 1.0 / 16.0), 0.0f), tid);
#endif
}
+12 -1
View File
@@ -68,8 +68,13 @@ class RenderPathRaytrace {
f32[1] = ct.worldy();
f32[2] = ct.worldz();
f32[3] = frame;
#if kha_metal
// frame = (frame % (16)) + 1; // _PAINT
frame = frame + 1; // _RENDER
#else
frame = (frame % 4) + 1; // _PAINT
// frame = frame + 1; // _RENDER
#end
f32[4] = helpMat._00;
f32[5] = helpMat._01;
f32[6] = helpMat._02;
@@ -94,7 +99,13 @@ class RenderPathRaytrace {
var framebuffer = path.renderTargets.get("buf").image;
Krom.raytraceDispatchRays(framebuffer.renderTarget_, f32.buffer);
if (Context.raw.ddirty == 1 || Context.raw.pdirty == 1) Context.raw.rdirty = 4;
if (Context.raw.ddirty == 1 || Context.raw.pdirty == 1) {
#if kha_metal
Context.raw.rdirty = 128;
#else
Context.raw.rdirty = 4;
#end
}
Context.raw.ddirty--;
Context.raw.pdirty--;
Context.raw.rdirty--;
+1 -2
View File
@@ -422,14 +422,13 @@ class BoxPreferences {
arm.render.RenderPathRaytrace.ready = false;
}
#else
#end
var hrendermode = Id.handle({ position: Context.raw.renderMode });
Context.raw.renderMode = ui.combo(hrendermode, [tr("Full"), tr("Mobile")], tr("Renderer"), true);
if (hrendermode.changed) {
Context.setRenderPath();
}
#end
ui.combo(Context.raw.hsupersample, ["0.25x", "0.5x", "1.0x", "1.5x", "2.0x", "4.0x"], tr("Super Sample"), true);
if (Context.raw.hsupersample.changed) Config.applyConfig();