Skip to content

Commit

Permalink
Add fake sss
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Jan 9, 2025
1 parent ecff0d1 commit 96d7fda
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
12 changes: 4 additions & 8 deletions armorpaint/sources/make_paint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,8 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad
// Height used for the first time, also rebuild vertex shader
return make_paint_run(data, matcon);
}
if (emis != "0.0" && emis != "0") {
make_material_emis_used = true;
}
if (subs != "0.0" && subs != "0") {
make_material_subs_used = true;
}
make_material_emis_used = emis != "0.0" && emis != "0";
make_material_subs_used = subs != "0.0" && subs != "0";
}

if (context_raw.brush_mask_image != null && context_raw.tool == workspace_tool_t.DECAL) {
Expand Down Expand Up @@ -391,13 +387,13 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad
node_shader_write(frag, "float matid = " + matid_string + ";");

// matid % 3 == 0 - normal, 1 - emission, 2 - subsurface
if (context_raw.material.paint_emis) {
if (context_raw.material.paint_emis && make_material_emis_used) {
node_shader_write(frag, "if (emis > 0.0) {");
node_shader_write(frag, " matid += 1.0 / 255.0;");
node_shader_write(frag, " if (str == 0.0) discard;");
node_shader_write(frag, "}");
}
else if (context_raw.material.paint_subs) {
else if (context_raw.material.paint_subs && make_material_subs_used) {
node_shader_write(frag, "if (subs > 0.0) {");
node_shader_write(frag, " matid += 2.0 / 255.0;");
node_shader_write(frag, " if (str == 0.0) discard;");
Expand Down
Binary file modified base/shaders/raytrace/raytrace_brute_forge_full.spirv
Binary file not shown.
Binary file modified base/shaders/raytrace/raytrace_brute_full.spirv
Binary file not shown.
18 changes: 12 additions & 6 deletions base/shaders/raytrace/src/raytrace_brute.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#define _EMISSION
#define _SUBSURFACE
#define _TRANSLUCENCY
#define _ROULETTE
#define _TRANSPARENCY
#define _ROULETTE
// #define _FRESNEL
#endif
// #define _RENDER
Expand Down Expand Up @@ -97,11 +97,11 @@ void raygeneration() {
}
#endif

#ifdef _SUBSURFACE
TraceRay(scene, RAY_FLAG_FORCE_OPAQUE | RAY_FLAG_CULL_BACK_FACING_TRIANGLES, ~0, 0, 1, 0, ray, payload);
#else
// #ifdef _SUBSURFACE
// TraceRay(scene, RAY_FLAG_FORCE_OPAQUE | RAY_FLAG_CULL_BACK_FACING_TRIANGLES, ~0, 0, 1, 0, ray, payload);
// #else
TraceRay(scene, RAY_FLAG_FORCE_OPAQUE, ~0, 0, 1, 0, ray, payload);
#endif
// #endif

#ifdef _EMISSION
if (payload.color.a == -3) {
Expand Down Expand Up @@ -278,7 +278,13 @@ void closesthit(inout RayPayload payload, in BuiltInTriangleIntersectionAttribut

#ifdef _SUBSURFACE
if (int(texpaint1.a * 255.0f) % 3 == 2) {
payload.ray_origin += WorldRayDirection() * f;
// Thickness
float d = min(1.0 / min(RayTCurrent() * 2.0, 1.0) / 10.0, 0.5);
payload.color.xyz += payload.color.xyz * d;
// Fake scatter
if (f < 0.5) {
payload.ray_origin += WorldRayDirection() * f * 0.001;
}
}
#endif
}
Expand Down

0 comments on commit 96d7fda

Please sign in to comment.