Lucas Stadler лет назад: 10
Родитель
Сommit
79aaac32ec
1 измененных файлов с 7 добавлено и 5 удалено
  1. 7 5
      glsl/raymarching.js

+ 7 - 5
glsl/raymarching.js

71
float trace(vec3 from, vec3 direction) {
71
float trace(vec3 from, vec3 direction) {
72
	float totalDistance = 0.0;
72
	float totalDistance = 0.0;
73
  int stepsDone = 0;
73
  int stepsDone = 0;
74
	for (int steps=0; steps < MaximumRaySteps; steps++) {
74
	for (int steps = 0; steps < MaximumRaySteps; steps++) {
75
		vec3 p = from + totalDistance * direction;
75
		vec3 p = from + totalDistance * direction;
76
		float distance = DistanceEstimator(p);
76
		float distance = DistanceEstimator(p);
77
		totalDistance += distance;
77
		totalDistance += distance;
85
  return length(pos) - 1.0;
85
  return length(pos) - 1.0;
86
}
86
}
87
87
88
/*uniform int MaxIterations; //#slider[1,50,200]
88
const float bailout = 4.0;
89
const float bailout = 4.0;
89
const int MaxIterations = 50;
90
const float power = 8.0;
90
const float power = 8.0;
91
const float phaseX = 0.0;
91
const float phaseX = 0.0;
92
const float phaseY = 0.0;
92
const float phaseY = 0.0;
93
93
94
/*float DistanceEstimator(vec3 z0) {
94
float DistanceEstimator(vec3 z0) {
95
	vec3 c = z0;
95
	vec3 c = z0;
96
	vec3 z = z0;
96
	vec3 z = z0;
97
	float pd = power - 1.0; // power for derivative
97
	float pd = power - 1.0; // power for derivative
151
}
151
}
152
152
153
uniform vec3 origin; //#slider[(-10.0,1.0,10.0),(-10.0,2.0,10.0),(-10.0,-1.0,10.0)]
153
uniform vec3 origin; //#slider[(-10.0,1.0,10.0),(-10.0,2.0,10.0),(-10.0,-1.0,10.0)]
154
uniform vec3 angle; //#slider[(-3.0,0.0,3.0),(-3.0,0.0,3.0),(-3.0,0.0,3.0)]
154
uniform vec3 color; //#slider[(0.0, 1.0, 1.0),(0.0,0.0,1.0),(0.0,0.0,1.0)]
155
uniform vec3 color; //#slider[(0.0, 1.0, 1.0),(0.0,0.0,1.0),(0.0,0.0,1.0)]
156
uniform float colorMix; //#slider[0.0,0.9,1.0]
155
157
156
void main() {
158
void main() {
157
  vec2 q = gl_FragCoord.xy / iResolution.xy;
159
  vec2 q = gl_FragCoord.xy / iResolution.xy;
164
  // camera	
166
  // camera	
165
  //vec3 ro = vec3(1.0, 2.0, -1.0); //vec3( -0.5+3.2*cos(0.1*time + 6.0*mo.x), 1.0 + 2.0*mo.y, 0.5 + 3.2*sin(0.1*time + 6.0*mo.x) );
167
  //vec3 ro = vec3(1.0, 2.0, -1.0); //vec3( -0.5+3.2*cos(0.1*time + 6.0*mo.x), 1.0 + 2.0*mo.y, 0.5 + 3.2*sin(0.1*time + 6.0*mo.x) );
166
  vec3 ro = origin;
168
  vec3 ro = origin;
167
  vec3 ta = vec3(0.0); //vec3( -0.5, -0.4, 0.5 );
169
  vec3 ta = angle; //vec3(0.0); //vec3( -0.5, -0.4, 0.5 );
168
170
169
  // camera-to-world transformation
171
  // camera-to-world transformation
170
  mat3 ca = setCamera( ro, ta, 0.0 );
172
  mat3 ca = setCamera( ro, ta, 0.0 );
176
  float dist = trace(ro, rd);
178
  float dist = trace(ro, rd);
177
  vec3 col = vec3(dist, dist, dist);
179
  vec3 col = vec3(dist, dist, dist);
178
180
179
  col = mix(color, col, 0.9);
181
  col = mix(color, col, colorMix);
180
  //col = pow( col, vec3(0.4545));
182
  //col = pow( col, vec3(0.4545));
181
183
182
  gl_FragColor = vec4( col, 1.0 );
184
  gl_FragColor = vec4( col, 1.0 );