3D河豚鱼—OpenGL着色器(Shader)和GLSL程序

3D河豚鱼—OpenGL着色器(Shader)和GLSL程序

效果图

这里写图片描述

程序代码

#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif

uniform vec3 pointers[1];
uniform vec2 resolution;
uniform float time;
// GLOBALS

// position & direction
vec3 pos_finn, pos_eyes;
vec3 dir_eye;
mat3 dir_mouth;
vec3 dir_light;

// coloring and animation
float heye, weye, beye;
float hmouth, cmouth;
float hfinns, htail;
float ttime;
float puff;
float tim_tail;
float ani_tail, ani_mouth;

// colors
vec3 col_water = vec3(.3, .7, 1.);
vec3 col_fish_1 = vec3(1., 0.4, 0.2);
vec3 col_fish_2 = vec3(1., 0.8, 0.5);
vec3 col_eyes = vec3(0.7, 0.75, 1.);
float t = 20.;

// marching
float maxdist = 5.;
float det = .001;



// USEFUL LITTLE FUNCTIONS

// 2D rotation
mat2 rot2D(float a) {
  a = radians(a);
  float s = sin(a);
  float c = cos(a);
  return mat2(c, s, -s, c);
}

// Align vector
mat3 lookat(vec3 fw, vec3 up) {
  fw = normalize(fw);
  vec3 rt = normalize(cross(fw, normalize(up)));
  return mat3(rt, cross(rt, fw), fw);
}


// Tile fold
float fmod(float p, float c) { return abs(c - mod(p, c * 2.)) / c; }

// Smooth min
float smin(float a, float b, float k) {
  float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0);
  return mix(b, a, h) - k * h * (1.0 - h);
}

// Smooth max
float smax(float a, float b, float k) {
  float h = clamp(0.5 + 0.5 * (a - b) / k, 0.0, 1.0);
  return mix(b, a, h) - k * h * (1.0 - h);
}

// Torus
float sdTorus(vec3 p, vec2 t, vec3 s) {
  p = p.yxz * s;
  vec2 q = vec2(length(p.xz) - t.x, p.y);
  return length(q) - t.y;
}


// PUFFY'S SURFACE DISPLACEMENT FUNCTIONS

float thorns(vec3 p) {
  p.xz*=rot2D(-25.);
  float s1 = smoothstep(.0, .7, -p.x + p.z + .6);
  float s2 = smoothstep(.15, .3, length(p.xy)) * smoothstep(.0, .3, length(p.yz));
  float s3 = smoothstep(.0, .25, abs(p.y));
  p.x = fmod(atan(p.x, p.y), .31459 / 2.);
  p.y = fmod(atan(p.y, p.z), .31459 / 2.);
  p.xz*=rot2D(25.);
  return min(1., exp((-3. - puff*3.) * length(p.xy))) * s1 * s2 * s3;
}

float spiral(vec3 p, vec3 c) {
  p.y = abs(p.y);
  vec3 pos = p;
  p = lookat(c, vec3(0., 1., 0.)) * p;
  float a = length(p.xy) * 35.;
  p.yx *= mat2(sin(a), cos(a), -cos(a), sin(a));
  float s=pow(abs(p.x), 2.) * smoothstep(0.7, 1., max(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值