Build Soul from plane intersections
This commit is contained in:
parent
fcdd5c41c2
commit
ea5252d148
2 changed files with 119 additions and 88 deletions
|
|
@ -6,15 +6,13 @@ static const int SDF_INDEX = 6;
|
|||
struct SoulDomain
|
||||
{
|
||||
float3 local;
|
||||
float3 octant;
|
||||
float3 bary;
|
||||
float3 facetNormal;
|
||||
float scale;
|
||||
float baseBody;
|
||||
float body;
|
||||
float outerEdge;
|
||||
float panelEdge;
|
||||
float findingEdge;
|
||||
float riskEdge;
|
||||
float edge;
|
||||
float finding;
|
||||
float risk;
|
||||
float fracture;
|
||||
float chamber;
|
||||
float frost;
|
||||
|
|
@ -25,68 +23,106 @@ float soulMin3(float3 value)
|
|||
return min(value.x, min(value.y, value.z));
|
||||
}
|
||||
|
||||
float soulMedian3(float3 value)
|
||||
{
|
||||
return value.x + value.y + value.z - soulMin3(value) - max(value.x, max(value.y, value.z));
|
||||
}
|
||||
|
||||
float soulVLine(float distanceToLine, float width)
|
||||
float soulLine(float distanceToLine, float width)
|
||||
{
|
||||
return saturate(1.0 - distanceToLine / max(width, 0.0001));
|
||||
}
|
||||
|
||||
float3 soulFacetNormal(float3 local)
|
||||
float soulEdgeDistance(float firstPlane, float secondPlane, float dominantPlane)
|
||||
{
|
||||
float3 side = float3(local.x < 0.0 ? -1.0 : 1.0, local.y < 0.0 ? -1.0 : 1.0, local.z < 0.0 ? -1.0 : 1.0);
|
||||
return normalize(side);
|
||||
return max(abs(firstPlane - secondPlane), dominantPlane - max(firstPlane, secondPlane));
|
||||
}
|
||||
|
||||
void soulSelectPlane(inout float dominantPlane, inout float3 facetNormal, float candidatePlane, float3 candidateNormal)
|
||||
{
|
||||
if (candidatePlane > dominantPlane)
|
||||
{
|
||||
dominantPlane = candidatePlane;
|
||||
facetNormal = candidateNormal;
|
||||
}
|
||||
}
|
||||
|
||||
SoulDomain soulDomain(float3 local, SdfObject sdfObject)
|
||||
{
|
||||
float confidence = saturate(sdfObject.state.y);
|
||||
float risk = saturate(sdfObject.state.z * 1.55 + (1.0 - confidence) * 0.35);
|
||||
float scale = lerp(0.405, 0.455, confidence) - risk * 0.014;
|
||||
float bevel = lerp(0.018, 0.006, confidence) + risk * 0.004;
|
||||
|
||||
float3 n0 = normalize(float3(1.00, 0.92, 1.08));
|
||||
float3 n1 = normalize(float3(-0.96, 1.04, 0.98));
|
||||
float3 n2 = normalize(float3(1.08, -0.88, 0.96));
|
||||
float3 n3 = normalize(float3(0.94, 1.10, -0.90));
|
||||
float3 n4 = normalize(float3(-1.02, -0.94, 1.04));
|
||||
float3 n5 = normalize(float3(-0.90, 1.02, -1.08));
|
||||
float3 n6 = normalize(float3(1.06, -1.00, -0.92));
|
||||
float3 n7 = normalize(float3(-1.00, -0.96, -1.02));
|
||||
|
||||
float p0 = dot(local, n0) - scale * 1.00;
|
||||
float p1 = dot(local, n1) - scale * 0.99;
|
||||
float p2 = dot(local, n2) - scale * 1.01;
|
||||
float p3 = dot(local, n3) - scale * 0.98;
|
||||
float p4 = dot(local, n4) - scale * 1.02;
|
||||
float p5 = dot(local, n5) - scale * 1.00;
|
||||
float p6 = dot(local, n6) - scale * 0.99;
|
||||
float p7 = dot(local, n7) - scale * 1.01;
|
||||
|
||||
float dominant = p0;
|
||||
float3 facetNormal = n0;
|
||||
soulSelectPlane(dominant, facetNormal, p1, n1);
|
||||
soulSelectPlane(dominant, facetNormal, p2, n2);
|
||||
soulSelectPlane(dominant, facetNormal, p3, n3);
|
||||
soulSelectPlane(dominant, facetNormal, p4, n4);
|
||||
soulSelectPlane(dominant, facetNormal, p5, n5);
|
||||
soulSelectPlane(dominant, facetNormal, p6, n6);
|
||||
soulSelectPlane(dominant, facetNormal, p7, n7);
|
||||
|
||||
float e01 = soulEdgeDistance(p0, p1, dominant);
|
||||
float e02 = soulEdgeDistance(p0, p2, dominant);
|
||||
float e03 = soulEdgeDistance(p0, p3, dominant);
|
||||
float e14 = soulEdgeDistance(p1, p4, dominant);
|
||||
float e15 = soulEdgeDistance(p1, p5, dominant);
|
||||
float e24 = soulEdgeDistance(p2, p4, dominant);
|
||||
float e26 = soulEdgeDistance(p2, p6, dominant);
|
||||
float e35 = soulEdgeDistance(p3, p5, dominant);
|
||||
float e36 = soulEdgeDistance(p3, p6, dominant);
|
||||
float e47 = soulEdgeDistance(p4, p7, dominant);
|
||||
float e57 = soulEdgeDistance(p5, p7, dominant);
|
||||
float e67 = soulEdgeDistance(p6, p7, dominant);
|
||||
float edge = min(min(min(e01, e02), min(e03, e14)), min(min(e15, e24), min(min(e26, e35), min(min(e36, e47), min(e57, e67)))));
|
||||
|
||||
float finding = min(min(e02, e35), e67);
|
||||
float riskGate = abs(dot(local, normalize(float3(0.18, 0.96, -0.24)))) * 0.16 - (0.030 + risk * 0.050);
|
||||
float riskEdge = min(min(e03, e47), e15);
|
||||
float riskSeam = max(riskEdge, riskGate);
|
||||
float fracture = max(min(e24, e57), abs(dot(local, normalize(float3(-0.72, 0.36, 0.60)))) * 0.13 - (0.022 + risk * 0.030));
|
||||
|
||||
float surfaceBand = 1.0 - smoothstep(0.010, 0.090, abs(dominant - bevel));
|
||||
float faceInterior = smoothstep(0.030, 0.115, edge);
|
||||
float equatorLift = 1.0 - smoothstep(0.10, 0.58, abs(local.y));
|
||||
float edgeGroove = soulLine(edge, 0.010) * 0.004;
|
||||
float findingGroove = soulLine(finding, lerp(0.005, 0.010, confidence)) * (0.010 + confidence * 0.006);
|
||||
float riskGroove = soulLine(riskSeam, lerp(0.007, 0.018, risk)) * risk * (0.018 + risk * 0.020);
|
||||
float fractureGroove = soulLine(fracture, lerp(0.004, 0.010, risk)) * risk * (0.012 + risk * 0.014);
|
||||
float faceLift = (0.006 + confidence * 0.007 + risk * 0.004) * equatorLift * faceInterior;
|
||||
float relief = surfaceBand * (faceLift - edgeGroove - findingGroove - riskGroove - fractureGroove);
|
||||
float baseBody = dominant - bevel;
|
||||
|
||||
float3 octant = abs(local);
|
||||
float scale = lerp(0.70, 0.78, confidence) - risk * 0.030;
|
||||
float bevel = lerp(0.040, 0.018, confidence) + risk * 0.006;
|
||||
float baseBody = (dot(octant, float3(1.0, 1.0, 1.0)) - scale) * 0.57735027 - bevel;
|
||||
float invSum = rcp(max(dot(octant, float3(1.0, 1.0, 1.0)), 0.001));
|
||||
float3 bary = octant * invSum;
|
||||
|
||||
float outerEdge = soulMin3(bary);
|
||||
float panelEdge = min(abs(bary.x - bary.y), min(abs(bary.y - bary.z), abs(bary.z - bary.x)));
|
||||
float findingSelector = abs(dot(local, normalize(float3(-0.38, 0.72, 0.58)))) * 0.22;
|
||||
float findingEdge = max(abs(bary.x - bary.z) * 0.58, findingSelector - (0.040 + confidence * 0.040));
|
||||
|
||||
float riskSelector = abs(dot(local, normalize(float3(0.22, 0.93, -0.30)))) * 0.24;
|
||||
float riskEdge = max(min(outerEdge, abs(bary.y - bary.z) * 0.48), riskSelector - (0.045 + risk * 0.070));
|
||||
float fracture = max(min(abs(bary.x - 0.18), abs(bary.y - bary.z) * 0.42), riskSelector - (0.030 + risk * 0.035));
|
||||
|
||||
float surfaceBand = 1.0 - smoothstep(0.014, 0.130, abs(baseBody));
|
||||
float equatorLift = 1.0 - smoothstep(0.12, 0.58, abs(local.y));
|
||||
float panelLift = smoothstep(0.035, 0.150, outerEdge);
|
||||
float findingCut = soulVLine(findingEdge, lerp(0.006, 0.011, confidence));
|
||||
float riskCut = soulVLine(riskEdge, lerp(0.010, 0.024, risk)) * risk;
|
||||
float fractureCut = soulVLine(fracture, lerp(0.006, 0.014, risk)) * risk;
|
||||
float lift = (0.002 + confidence * 0.004 + risk * 0.003) * equatorLift * panelLift;
|
||||
float cut = findingCut * (0.006 + confidence * 0.004)
|
||||
+ riskCut * (0.014 + risk * 0.018)
|
||||
+ fractureCut * (0.010 + risk * 0.014);
|
||||
float relief = surfaceBand * (lift - cut);
|
||||
float3 bary = octant / max(dot(octant, float3(1.0, 1.0, 1.0)), 0.001);
|
||||
|
||||
SoulDomain domain;
|
||||
domain.local = local;
|
||||
domain.octant = octant;
|
||||
domain.bary = bary;
|
||||
domain.facetNormal = facetNormal;
|
||||
domain.scale = scale;
|
||||
domain.baseBody = baseBody;
|
||||
domain.body = baseBody - relief;
|
||||
domain.outerEdge = outerEdge;
|
||||
domain.panelEdge = panelEdge;
|
||||
domain.findingEdge = findingEdge;
|
||||
domain.riskEdge = riskEdge;
|
||||
domain.edge = edge;
|
||||
domain.finding = finding;
|
||||
domain.risk = riskSeam;
|
||||
domain.fracture = fracture;
|
||||
domain.chamber = saturate(1.0 - length(local) * 1.16);
|
||||
domain.frost = sin(bary.x * 63.0 + local.z * 13.0) * sin(bary.y * 47.0 - local.x * 11.0);
|
||||
domain.chamber = saturate(1.0 - length(local) * 1.18);
|
||||
domain.frost = sin(bary.x * 53.0 + local.z * 9.0) * sin(bary.y * 41.0 - local.x * 7.0);
|
||||
return domain;
|
||||
}
|
||||
|
||||
|
|
@ -107,26 +143,26 @@ SdfSurface sdfSurface(float3 p, int sdfIndex)
|
|||
float confidence = saturate(sdfObject.state.y);
|
||||
float risk = saturate(sdfObject.state.z * 1.55 + (1.0 - confidence) * 0.35);
|
||||
|
||||
float riskMask = soulVLine(domain.riskEdge, 0.018) * risk;
|
||||
float fractureMask = (1.0 - riskMask) * soulVLine(domain.fracture, 0.010) * risk;
|
||||
float findingMask = (1.0 - riskMask) * (1.0 - fractureMask) * soulVLine(domain.findingEdge, 0.010);
|
||||
float edgeMask = (1.0 - riskMask) * soulVLine(domain.outerEdge, 0.020);
|
||||
float riskMask = soulLine(domain.risk, 0.014) * risk;
|
||||
float fractureMask = (1.0 - riskMask) * soulLine(domain.fracture, 0.008) * risk;
|
||||
float findingMask = (1.0 - riskMask) * (1.0 - fractureMask) * soulLine(domain.finding, 0.008);
|
||||
float edgeMask = (1.0 - riskMask) * soulLine(domain.edge, 0.010);
|
||||
float facetMask = saturate(1.0 - riskMask - fractureMask - findingMask - edgeMask);
|
||||
|
||||
float frost = lerp(0.82, 1.14, 0.5 + 0.5 * domain.frost);
|
||||
float3 facetColor = lerp(float3(0.025, 0.038, 0.072), float3(0.22, 0.34, 0.56), confidence) * frost;
|
||||
float3 edgeColor = lerp(float3(0.16, 0.38, 0.70), float3(0.56, 0.84, 1.0), confidence);
|
||||
float3 findingColor = lerp(float3(0.08, 0.24, 0.62), float3(0.52, 0.82, 1.0), confidence);
|
||||
float3 riskColor = lerp(float3(0.28, 0.018, 0.030), float3(1.0, 0.055, 0.045), risk);
|
||||
float frost = lerp(0.84, 1.12, 0.5 + 0.5 * domain.frost);
|
||||
float3 facetColor = lerp(float3(0.020, 0.032, 0.064), float3(0.20, 0.32, 0.56), confidence) * frost;
|
||||
float3 edgeColor = lerp(float3(0.14, 0.34, 0.70), float3(0.56, 0.86, 1.0), confidence);
|
||||
float3 findingColor = lerp(float3(0.06, 0.22, 0.62), float3(0.46, 0.80, 1.0), confidence);
|
||||
float3 riskColor = lerp(float3(0.26, 0.012, 0.026), float3(1.0, 0.050, 0.040), risk);
|
||||
|
||||
SdfSurface surface;
|
||||
surface.baseColor = facetColor * facetMask + edgeColor * edgeMask + findingColor * findingMask + riskColor * saturate(riskMask + fractureMask);
|
||||
surface.metallic = 0.0;
|
||||
surface.roughness = 0.070 * facetMask + 0.052 * edgeMask + 0.065 * findingMask + 0.120 * saturate(riskMask + fractureMask);
|
||||
surface.emission = edgeColor * edgeMask * (0.10 + confidence * 0.26)
|
||||
+ findingColor * findingMask * (0.24 + confidence * 0.56)
|
||||
+ riskColor * riskMask * (0.30 + risk * 0.90)
|
||||
+ riskColor * fractureMask * (0.18 + risk * 0.62);
|
||||
surface.roughness = 0.055 * facetMask + 0.045 * edgeMask + 0.060 * findingMask + 0.105 * saturate(riskMask + fractureMask);
|
||||
surface.emission = edgeColor * edgeMask * (0.08 + confidence * 0.18)
|
||||
+ findingColor * findingMask * (0.24 + confidence * 0.50)
|
||||
+ riskColor * riskMask * (0.36 + risk * 0.95)
|
||||
+ riskColor * fractureMask * (0.18 + risk * 0.58);
|
||||
return surface;
|
||||
}
|
||||
|
||||
|
|
@ -138,40 +174,34 @@ float3 soulCrystalShade(float3 p, float3 normal, int sdfIndex, SdfSurface surfac
|
|||
float confidence = saturate(sdfObject.state.y);
|
||||
float risk = saturate(sdfObject.state.z * 1.55 + (1.0 - confidence) * 0.35);
|
||||
SoulDomain domain = soulDomain(local, sdfObject);
|
||||
float seamInfluence = saturate(
|
||||
soulVLine(domain.outerEdge, 0.026)
|
||||
+ soulVLine(domain.findingEdge, 0.014)
|
||||
+ soulVLine(domain.riskEdge, 0.018) * risk
|
||||
+ soulVLine(domain.fracture, 0.010) * risk);
|
||||
float3 facetNormal = soulFacetNormal(local);
|
||||
float3 shadeNormal = normalize(lerp(facetNormal, normal, 0.10 + seamInfluence * 0.22));
|
||||
|
||||
float cutInfluence = saturate(soulLine(domain.edge, 0.014) + soulLine(domain.finding, 0.010) + soulLine(domain.risk, 0.014) * risk + soulLine(domain.fracture, 0.008) * risk);
|
||||
float3 shadeNormal = normalize(lerp(domain.facetNormal, normal, cutInfluence * 0.18));
|
||||
float3 viewDirection = normalize(cameraPosition - p);
|
||||
float ndv = saturate(dot(shadeNormal, viewDirection));
|
||||
float3 reflected = reflect(-viewDirection, shadeNormal);
|
||||
float3 refracted = refract(-viewDirection, shadeNormal, 0.67);
|
||||
float refractionValid = dot(refracted, refracted) > 0.001 ? 1.0 : 0.0;
|
||||
float3 glassDirection = normalize(lerp(reflected, refracted, refractionValid));
|
||||
float3 envRefract = studioPmremSample(glassDirection, 0.24);
|
||||
float3 envReflect = studioPmremSample(reflected, 0.56);
|
||||
float3 envRefract = studioPmremSample(glassDirection, 0.22);
|
||||
float3 envReflect = studioPmremSample(reflected, 0.46);
|
||||
|
||||
float fresnel = pow(1.0 - ndv, 4.8);
|
||||
float thickness = saturate((domain.scale - dot(domain.octant, float3(0.45, 0.45, 0.45))) * 1.8);
|
||||
float3 glassTint = lerp(float3(0.34, 0.50, 0.84), float3(0.78, 0.90, 1.0), confidence);
|
||||
float3 transmission = envRefract * glassTint * (0.18 + thickness * 0.42);
|
||||
float3 reflection = envReflect * (0.22 + fresnel * 0.72);
|
||||
float fresnel = pow(1.0 - ndv, 4.6);
|
||||
float thickness = saturate((domain.scale - length(local) * 0.42) * 1.9);
|
||||
float3 glassTint = lerp(float3(0.30, 0.46, 0.82), float3(0.76, 0.90, 1.0), confidence);
|
||||
float3 transmission = envRefract * glassTint * (0.16 + thickness * 0.38);
|
||||
float3 reflection = envReflect * (0.24 + fresnel * 0.72);
|
||||
|
||||
float innerCore = exp(-dot(local, local) * 5.8);
|
||||
float chamberGlow = domain.chamber * domain.chamber * (0.35 + confidence * 0.85);
|
||||
float edgeLine = soulVLine(domain.outerEdge, 0.028);
|
||||
float findingLine = soulVLine(domain.findingEdge, 0.011);
|
||||
float riskLine = soulVLine(domain.riskEdge, 0.018) * risk;
|
||||
float fractureLine = soulVLine(domain.fracture, 0.010) * risk;
|
||||
float paneFlash = soulVLine(domain.panelEdge, 0.006) * (0.25 + 0.25 * sin(domain.bary.x * 31.0 + domain.bary.y * 19.0 + timeSeconds * 0.17));
|
||||
float innerCore = exp(-dot(local, local) * 5.6);
|
||||
float chamberGlow = domain.chamber * domain.chamber * (0.35 + confidence * 0.82);
|
||||
float edgeLine = soulLine(domain.edge, 0.016);
|
||||
float findingLine = soulLine(domain.finding, 0.010);
|
||||
float riskLine = soulLine(domain.risk, 0.014) * risk;
|
||||
float fractureLine = soulLine(domain.fracture, 0.008) * risk;
|
||||
|
||||
float3 oathLight = float3(1.0, 0.96, 0.82) * (innerCore * (1.9 + confidence * 1.7) + chamberGlow * 0.42);
|
||||
float3 blueCaustic = float3(0.36, 0.70, 1.0) * (edgeLine * 0.58 + findingLine * 0.72 + paneFlash * 0.22 + fresnel * 0.36) * (0.75 + confidence * 0.9);
|
||||
float3 redFault = float3(1.0, 0.075, 0.045) * (riskLine * 1.10 + fractureLine * 0.84);
|
||||
float3 oathLight = float3(1.0, 0.96, 0.82) * (innerCore * (1.9 + confidence * 1.7) + chamberGlow * 0.36);
|
||||
float3 blueCaustic = float3(0.34, 0.70, 1.0) * (edgeLine * 0.42 + findingLine * 0.88 + fresnel * 0.36) * (0.76 + confidence * 0.86);
|
||||
float3 redFault = float3(1.0, 0.070, 0.045) * (riskLine * 1.20 + fractureLine * 0.82);
|
||||
|
||||
return shadeSdfPbr(p, shadeNormal, surface) * 0.18
|
||||
+ transmission
|
||||
|
|
|
|||
|
|
@ -91,3 +91,4 @@
|
|||
{"timestamp":"2026-05-13T19:12:00+01:00","topic":"soul-edge-graph-selectivity","lesson":"Soul facet-edge seams need both active-face gating and restraint. A pairwise face equality is not a crystal edge unless both faces are jointly dominant at the surface; otherwise inactive planes create a wireframe lattice across faces. Promote only a small role-bearing subset of the active edge graph, and keep seam masks narrow so relief reads as crisp cut crystal rather than gummy tubing.","files":["src/Aquarium.Epiphany/Shaders/D3D12SoulAgent.hlsl","state/evidence.jsonl"],"source":"user screenshot showed all-over gummy seam lattice after edge snapping"}
|
||||
{"timestamp":"2026-05-13T19:34:00+01:00","topic":"soul-crystal-domain-reset","lesson":"When Soul starts reading as warped packaging or a seam lattice, delete the clever cut-field tangle. The live model is a balanced faceted oath crystal: octahedral half-space silhouette, barycentric face coordinates for restrained relief, a small set of role-bearing seams, and local glass shading with transmission/reflection/inner oath light. Expressiveness belongs in face-domain relief and material, not in uncontrolled silhouette ownership.","files":["src/Aquarium.Epiphany/Shaders/D3D12SoulAgent.hlsl","state/evidence.jsonl"],"source":"user compared Soul against reference art and called the current code a lesson rather than sacred"}
|
||||
{"timestamp":"2026-05-13T19:45:00+01:00","topic":"soul-facet-normal-authority","lesson":"Soul must shade like cut crystal, not thermoformed plastic. If relief participates in ray distance, do not let the finite-difference relief normal dominate broad facets; shade from the governing facet normal and blend the traced normal only near cuts. Transmission should support dark glass depth and inner oath light, not wash every face into milky white.","files":["src/Aquarium.Epiphany/Shaders/D3D12SoulAgent.hlsl","state/evidence.jsonl"],"source":"user screenshot showed Soul still reading as vacuum-formed packaging after domain reset"}
|
||||
{"timestamp":"2026-05-13T20:00:00+01:00","topic":"soul-plane-intersection-crystal","lesson":"Soul seams are not unreasonable as geometry: build the crystal from explicit signed half-space planes, derive edges from adjacent active plane intersections, then extrude face interiors and cut narrow V-grooves on selected edge chains. Auxiliary gates may choose which edges glow, but the edge itself must come from the plane intersection graph. Broad shading uses the active plane normal; cut normals are secondary.","files":["src/Aquarium.Epiphany/Shaders/D3D12SoulAgent.hlsl","state/evidence.jsonl"],"source":"user asked for organic plane intersections with extruded faces and glowing groove centers"}
|
||||
|
|
|
|||
Loading…
Reference in a new issue