|
 |
On 23.09.2025 14:53, ingo wrote:
> Ilya Razmanov <ily### [at] gmail com> wrote:
>> Greeting,
>
> Interesting what you do with the sharp transitions.
Oh, it's all pretty simple (remember that I started it for my own use,
and not a science project).
I was disappointed with the way POV-Ray treats bitmapped heighfield, and
decided to try some heighfiled to mesh conversion on my own. Initial
idea was simple: lets assume we have 2x2 pixel area of source image,
numbering pixels according to Soviet Army "snail" rule:
1 2
4 3
those values (brightness) we name v1 - v4.
Simplest way to make triangles would be two triangles, 1-2-4 and 2-3-4,
forming a square, folded along 2-4 diagonal. It works, but not too cool,
so instead of 2 triangle fold I tried 4 triangle pyramid, involving
interpolated point 0, having v0 = (v1 + v2 + v3 +v4) / 4. So four
triangles looked like 1-2-0, 2-3-0, 3-4-0 and 4-1-0. This looked
definitely better than POV-Ray heighfield; I also tried to compare it
with patches and found to be similar). However I don't like artifacts
like peaks it produces for cone gradients. But spontaneously I though
that fold structure above is a case of pyramid structure with v0 = (v2 +
v4) /2, so combining two geometries is only a matter of setting v0 to
average of either two or four pixels. So I did this; decision is based
on simple criterion:
# ↓ Switch between geometry №1 and №3.
# Threshold set ad hoc and is subject to change
if abs(v1 - v3) > threshold or abs(v2 - v4) > threshold:
# ↓ Geometry №1, better sharp diagonals handling
if abs(v1 - v3) > abs(v2 - v4):
v0 = (v2 + v4) / 2 # Fold along 2 - 4 diagonal
else:
v0 = (v1 + v3) / 2 # Fold along 1 - 3 diagonal
else:
# ↓ Geometry №3, better for smooth areas
v0 = (v1 + v2 + v3 + v4) / 4
Note that it includes two folding directions, 2-4 and 1-3, for / and \
diagonals.
So, now I have only one problem: choosing threshold. Surely I used
common sense (I have vast supplies of common sense, "hot' lozhkoy zhuy")
and added some experiments to it before setting defaults, but it's still
a matter to discuss.
> 1. First calculate the face normal
As we are talking of source image areas like 2x2 pixels, I see no sense
in calculating normal and other wise and complicated stuff. I think I
can make decisions regarding local source contrast based on simple
arithmetics like difference and stuff.
--
Ilyich the Toad
https://dnyarri.github.io/
Post a reply to this message
|
 |