Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float length(float2 v){
- return sqrt(v.x * v.x + v.y * v.y)
- }
- float signedDstToCircle(float2 p, float2 centre, float radius){
- return length(centre - p) - radius;
- }
- float signedDstToBox(float2 p, float2 centre, float2 size){
- float2 offset = abs(p - centre) - size;
- float unsignedDst = length(max(offset, 0));
- float dstInsideBox = max(min(offset, 0));
- return unsignedDist + dstInsideBox;
- }
- float signedDstToScene(float2 p){
- float dstToScene = maxDst;
- for(int i = 0; i < numCircles; i++){
- float dstToCircle = signedDstToCircle(p, circles[i].centre, circles[i].radius);
- dstToScene = min(dstToCircle, dstToScene);
- }
- for(int i = 0; i < numBoxes; i++) {
- float dstToBox = signedDstToBox(p, boxes[i].centre, boxes[i].size);
- dstToScene = min(dstToBox, dstToScene);
- }
- return dstToScene;
- }
- float signedDstToScene (float3 p) {
- float dstToCube = CubeDistance(p, cube.centre, cube.size);
- float dstToSphere = SphereDistance(p, sphere.centre, sphere.radius);
- return max(dstToCube, dstToSphere * -1);
- }
- float smoothMin(float dstA, float dstB, float k){
- float h = max(k - abs(dstA - dstB), 0) / k;
- return min(dstA, dstB) - h * h * h * k * 1/6.0;
- }
- float signedDstToScene(float3 p){
- float dstA = dot(sin(p * paramA), 1);
- float dstB = dot(p % paramB, 1);
- return lerp(dstA, dstB, t);
- }
- float mandelbulb(float3 position){
- float3 z = position;
- float dr = 1;
- float r;
- for(int i = 0; i < 15; i++){
- r = length(z);
- if(r > 2)
- break;
- float theta = acos(z.z / r) * power;
- float phi = atan2(z.y, z.x) * power;
- float zr = pow(r, power - 1) * power * dr + 1;
- z = zr * float3(sin(theta) * cos(phi), sin(phi) * sin(theta), cos(theta));
- z += position;
- }
- return 0.5 * log(r) * r / dr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement