maven


Raymarching tetrahedron fractal visual artifacts


I've been working with some basic ray marching stuff lately and I've encountered some issues with visual artifacts for a tetrahedron fractal. These artifacts occur whenever objects seem to get close to one another. The issue is most certainly within the surface distance function I am using and not my ray marching engine.
http://i.imgur.com/FmyRetV.png
http://i.imgur.com/TFKA6sV.png
Code:
float sdTet4(vec3 p, int iterations, float scale) {
//in cube from p(-1,-1,-1) to p(1,1,1)
//equilateral triangle (sorta lol)
float sideLength = 0.0; //side length
float radius = 0.0; //inscribed circle radius
float radius2 = 0.0; //circumscribed circle radius
float sphereRadius = 0.0; //radius of sphere for sd function
vec3 z = p;
for (int i = 0; i < iterations; i++) {
sideLength = scale/pow(2.0, float(i+1));
radius = sideLength*0.2886751346; //sqrt(3.0)/6.0 = 0.2886751346
radius2 = radius*2.0;
float height = sideLength*0.8164965809; //sqrt(6.0)/3.0 = 0.8164965809
sphereRadius = sideLength;
vec3 z1 = z - vec3(0.0, height, 0.0); //top center
vec3 z2 = z - vec3(0.0, -height, -height); //bottom back
vec3 z3 = z - vec3(-sideLength, -height, height); //bottom front left
vec3 z4 = z - vec3(sideLength, -height, height); //bottom front right
float d1 = sdSphere(z1, sphereRadius*2.0);
float d2 = sdSphere(z2, sphereRadius*2.0);
float d3 = sdSphere(z3, sphereRadius*2.0);
float d4 = sdSphere(z4, sphereRadius*2.0);
z = z1;
float d = d1;
if (d2 < d) { d = d2; z = z2; }
if (d3 < d) { d = d3; z = z3; }
if (d4 < d) { d = d4; z = z4; }
}
return sdSphere(z, sphereRadius);
}
Alternative code that somehow works:
float sdTet4(vec3 p, int iterations, float scale) {
vec3 a1 = vec3(1.0, 1.0, 1.0);
vec3 a2 = vec3(-1.0, -1.0, 1.0);
vec3 a3 = vec3(1.0, -1.0, -1.0);
vec3 a4 = vec3(-1.0, 1.0, -1.0);
iterations = 7;
int n = 0;
float dist = 0.0;
float d = 0.0;
vec3 z = p;
vec3 c = vec3(0.0);
//scale = 1.0;
float iterationScale = 0.0;
while (n < iterations) {
iterationScale = scale/pow(2.0, float(n));
c = a1; dist = length(z-a1);
d = length(z-a2); if (d < dist) { c = a2; dist = d; }
d = length(z-a3); if (d < dist) { c = a3; dist = d; }
d = length(z-a4); if (d < dist) { c = a4; dist = d; }
z -= c*iterationScale;
n++;
}
return sdSphere(z, iterationScale);
}
Thanks for the tips!
Edit: So why does the alternative code that I found work and not the original code? Something in the original code causes the visual artifacts but I don't know what.

Related Links

How to restore artifacts in Jenkins multibranch job?
How to get the currently processed dependencys artefactid during process-resources
how do I get maven to tell me what jar it would build without building it?
1.0.0-SNAPSHOT in two Nexus repositories of one group
Failure to find org.jenkins-ci.plugins:plugin:pom:2.11 in https://repo.maven.apache.org/maven2
Cobertura wrong coverage reporting issues
Configuration of Maven profile to connect with SonarQube which is using LDAP
docker, maven start failed: Connection is still allocated
Build Failure while while building the Apache Zeppelin
Use EndptEnabler with maven
What is the final dependency scope when different scopes are specified for one JAR?
Maven and JavaFX project in IntelliJ IDEA
Nexus directory storage/repositoryName/.nexus/attributes - What is it for?
Gradle Support for GCP Dataflow Templates?
OWASP Dependency check : Adding modelVersion version to dependency check report
How to integrate maven with Protractor for CI/CD

Categories

HOME
maven
listview
image-processing
server
youtube-dl
yarn
graphql
rdf
c#-2.0
jxls
blueprintjs
fancybox
wheelnav.js
imacros
apache-cayenne
spring-tool-suite
visual-studio-2005
ups
netflix
clearcase-ucm
seaborn
tostring
finite-automata
lucene.net
grails3
ehcache
wkwebview
format-specifiers
php-openssl
pepper
selectedindexchanged
facebook-access-token
traffic
publish
primitive
bluestacks
junit5
pim
perlin-noise
framemaker
protovis
plsql-psp
suricata
bitbucket-pipelines
espeak
code-search-engine
leading-zero
grid.mvc
spring-security-kerberos
nxlog
slick-3.0
outlook-2013
smartcontracts
pnotify
togetherjs
sqlclient
pg-dump
r-forge
gcsfuse
titanium-android
sonarlint-vs
root-framework
xcb
visual-c++-2008
elements
file-writing
websitepanel
hill-climbing
kendonumerictextbox
rtbkit
cartesian-product
t4mvc
comobject
jqgrid-formatter
pundit
dukescript
ideamart
sysinternals
event-bubbling
key-management
lustre
c++03
website-monitoring
angularjs-ng-click
has-many-through
xceed-datagrid
monomac
prettify
listings
batterylevel
yui-compressor
robotics-studio
pvrtc
bitsharp
first-responder
armcc
javaspaces
hosts-file
wse3.0
punbb
boost-filesystem
xmemcached
locationlistener
imac
mysql-error-1005
gamequery
nsviewanimation
user-friendly
adrotator
pascal-fc
zune

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App