Тёмный

Transparency attempt with oscillating RayMarch iteration limit 

nutzeeer
Подписаться 27
Просмотров 70
50% 1

you need to replace [] with the pointy kind as soutube descriptions dont like them.
//
// HelloShader.fsh
//
precision highp float;
// Width and height of the shader
uniform vec2 u_resolution;
// Time elapsed
uniform float u_time;
uniform float u_rotationx;
uniform float u_rotationy;
uniform float u_rotationz;
float spheredist(vec3 p,vec3 mov) {
float spd = length((sin(p)) - mov) - 0.5;
return spd;
}
float cubedist(vec3 p){
vec3 size = vec3(0.4);
vec3 d = abs(p) - size;
float cube = length(max(d, 0.0)) + min(max(d.x, max(d.y, d.z)),-0.0);
//length(max(sin(p.x) - 0.5), max(abs(p.y) - 0.5), max(abs(p.z) - 0.5));
return cube;
}
float map(vec3 p) { //object map providing size and position
float sph= spheredist(p,vec3(0.0,0.0,0.0));
float cube = cubedist(p);
return min(sph, cube);
}
float mapIgnoreFirstObject(vec3 p, float firstObjectDist) {
// Define the same objects but ignore the one detected in the first pass
float sphereDist = spheredist(p,vec3(0.0,0.0,0.0));
float cubeDist = cubedist(p);
float dist = min(sphereDist, cubeDist);
if (cos(dist - firstObjectDist) [ 0.01) {
return max(sphereDist, cubeDist); // Ignore the first object
}
return dist;
}
vec3 getNormal(vec3 p) {
float eps = 0.001;
vec3 n;
n.x = map(p + vec3(eps, 0.0, 0.0)) - map(p - vec3(eps, 0.0, 0.0));
n.y = map(p + vec3(0.0, eps, 0.0)) - map(p - vec3(0.0, eps, 0.0));
n.z = map(p + vec3(0.0, 0.0, eps)) - map(p - vec3(0.0, 0.0, eps));
return normalize(n);
}
vec3 rayMarch(vec3 ro, vec3 rd, out float dist1, out float dist2) {
float maxDist = 100.0;
float minDist = 0.001;
float totalDist = 0.0;
vec3 col = vec3(0.0);
// First pass
for (int i = 0; i [ 64; i++) {
vec3 p = ro + rd * totalDist;
float d = map(p);
if (d [ minDist || totalDist ] maxDist) break;
totalDist += d;
}
dist1 = totalDist;
// Reset for second pass
totalDist = 0.0;
//oscillating transparency iteration limit
// Define start and end iterations
float startstep = 1.0; // Red
float endstep = 256.0; // Blue
// Interpolate raymarching steps
int maxSteps = int(((endstep-startstep)/2.0)*0.99*sin(0.5*u_time)+((endstep-startstep)/2.0));
// Second pass
for (int i = 0; i [ maxSteps; i++) {
vec3 p = ro + rd * totalDist;
float d = mapIgnoreFirstObject(p, dist1);
if (d [ minDist || totalDist ] maxDist) break;
totalDist += d;
}
dist2 = totalDist;
// Blend the distances
float blendedDist = mix(dist1, dist2, 0.5);
vec3 p = ro + rd * blendedDist;
vec3 normal = getNormal(p);
col = normal * 0.5 + 0.5;
return col;
}
void main() {
vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / u_resolution.y;
vec3 ro = vec3(0.0+1.0*cos(0.5*u_time), 0.0+sin(0.5*u_time), 5.0);
vec3 rd = normalize(vec3(uv, -1.0));
float dist1, dist2;
vec3 color = rayMarch(ro, rd, dist1, dist2);
gl_FragColor = vec4(color, 1.0);
}

Опубликовано:

 

3 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии    
Далее
The most amazing physics simulations right now #2
10:10
The Midpoint Circle Algorithm Explained Step by Step
13:33
Are Desktop PCs Actually Dying?
7:05
Просмотров 1 млн
Every Weird Geometry Paradox Explained
11:33
Просмотров 16 тыс.
History of Denuvo - the DRM for DRMs
20:14
Просмотров 278 тыс.
This is the dumbest thing I've ever done...
11:40
Просмотров 2,2 млн