M lib/tukan/isosurface.sc +5 -2
@@ 30,7 30,10 @@ fn tetlerp (a b)
where
a + (b-a)*x = 0
let d = (b - a)
- ? ((abs d) < 1e-12) 0.5 (-a / d)
+ #? ((abs d) < 1e-12) 0.5 (-a / d)
+ #clamp (-a / d) 0.0 1.0
+ ? (d == 0) 0.5 (-a / d)
+ #-a / (d + 1e-5)
fn tetfaces (d)
""""u32 uvec4 <- vec4
@@ 39,7 42,7 @@ fn tetfaces (d)
returns 0 if no triangle is to be generated
1 if the result is a tri (interpolate edges x-y x-z x-w)
2 if the result is a quad (interpolate edges x-z x-w y-w y-z)
- let bits = (? (d > 0.0) (uvec4 2:u32 4:u32 8:u32 16:u32) (uvec4 0:u32))
+ let bits = (? (d >= 0.0) (uvec4 2:u32 4:u32 8:u32 16:u32) (uvec4 0:u32))
let k = ((bits.x | bits.y) | (bits.z | bits.w))
_ ((tetbits_q >> k) & 3:u32) ((tetbits >> k) & 3:u32)
M lib/tukan/normal.sc +1 -2
@@ 6,8 6,7 @@ using import glm
fn oct_wrap (v)
*
1.0 - (abs v.yx)
- sign v
- #vec2
+ vec2
? (v.x >= 0.0) 1.0 -1.0
? (v.y >= 0.0) 1.0 -1.0
M testing/test_cascade_dmc_cc.sc +37 -27
@@ 297,7 297,9 @@ fn matmapf (p)
elseif 1
#p := p * 0.2
let d =
- ((triquad-noise3 p) * 2.0 - 1.0) - 0.05
+ static-if USE_COMPLEX_SURFACE
+ ((triquad-noise3 p) * 2.0 - 1.0) - 0.05
+ else -inf
#let d =
min d
@@ 525,28 527,31 @@ fn tet-feature-vertex-normal (cd)
inline tf (i0 i1)
mix (p @ i0) (p @ i1) (tetlerp (d @ i0) (d @ i1))
- if (c == 1:u32)
- p0 := (tf i.x i.y)
- p1 := (tf i.x i.z)
- p2 := (tf i.x i.w)
- pc := ((p0 + p1 + p2) / 3)
- A := (triangle-area p0 p1 p2)
- outv += (vec4 pc 1) * A
- elseif (c == 2:u32)
- p0 := (tf i.x i.z)
- p1 := (tf i.x i.w)
- p2 := (tf i.y i.w)
- p3 := (tf i.y i.z)
- pc := ((p0 + p1 + p2 + p3) / 4)
- A :=
- +
- (triangle-area pc p0 p1)
- (triangle-area pc p1 p2)
- (triangle-area pc p2 p3)
- (triangle-area pc p3 p0)
- outv += (vec4 pc 1) * A
- #outv.xyz / (max 1.0 outv.w)
- outv.xyz / outv.w
+ fn triangle-area (A B C)
+ # removed factor 1/2
+ length (cross (B - A) (C - A))
+
+ let pc A =
+ if (c == 1:u32)
+ p0 := (tf i.x i.y)
+ p1 := (tf i.x i.z)
+ p2 := (tf i.x i.w)
+ pc := ((p0 + p1 + p2) / 3)
+ A := (triangle-area p0 p1 p2)
+ _ pc A
+ else # elseif (c == 2:u32)
+ p0 := (tf i.x i.z)
+ p1 := (tf i.x i.w)
+ p2 := (tf i.y i.w)
+ p3 := (tf i.y i.z)
+ pc := ((p0 + p1 + p2 + p3) / 4)
+ A :=
+ +
+ (triangle-area p0 p1 p2)
+ (triangle-area p0 p3 p2)
+ _ pc A
+ outv += (vec4 pc 1) * (max 1e-5 A)
+ ? (outv.w == 0) (vec3 0) (outv.xyz / outv.w)
fn feature-vertex-normal (v)
let c000 c001 c010 c011 c100 c101 c110 c111 =
@@ 565,7 570,7 @@ fn feature-vertex-normal (v)
g11 := (c011 - c100)
# normal vector (gradient)
g :=
- normalize
+ do #normalize
+
g00 * n00
g01 * n01
@@ 973,8 978,10 @@ NATIVE_LANE_WIDTH := 64
fn normal (v1 v2 v3)
cross
- normalize ((v3 - v1) . xyz)
- normalize ((v2 - v1) . xyz)
+ normalize
+ (v3 - v1) . xyz
+ normalize
+ (v2 - v1) . xyz
inline swapnormal (v n)
Vertex v.pos (vec4 n 0)
@@ 997,6 1004,7 @@ fn generate-quad (v00 v01 v10 v11)
static-if USE_FLAT_SHADING
n0 := (normal v00.pos v10.pos v11.pos)
n1 := (normal v11.pos v01.pos v00.pos)
+ #n1 := (normal v00.pos v11.pos v01.pos)
entries @ (ofs + 0) = (swapnormal v00 n0)
entries @ (ofs + 1) = (swapnormal v10 n0)
@@ 1412,6 1420,7 @@ fn rasterize-vert ()
fn pack-surfel-data (normal depth color matdata)
let normal =
bitcast (packSnorm2x16 (pack_normal_snorm normal)) f32
+ #bitcast (packSnorm4x8 (vec4 (normalize normal) 0)) f32
let color =
bitcast (packUnorm4x8 color) f32
let matdata =
@@ 1421,6 1430,7 @@ fn pack-surfel-data (normal depth color
fn unpack-surfel-data (frag)
let normal =
unpack_normal_snorm (unpackSnorm2x16 (bitcast frag.x u32))
+ #vec3 ((unpackSnorm4x8 (bitcast frag.x u32)) . xyz)
let matdata =
unpackUnorm4x8 (bitcast frag.y u32)
let color =
@@ 1436,7 1446,7 @@ out out_Color : vec4
fn rasterize-frag ()
out_Color =
pack-surfel-data
- normalize (deref normal.in)
+ deref normal.in
deref depthval.in
deref albedo.in
deref matdata.in