#define SHADOWS
#define REFRACTION
#define MAX_DIST 1e10
#define RADIUS 0.3
#define NORMAL_SMOOTHNESS 0.0
#define FOV 2.5
mat3 getCamera(vec2 angles)
{
mat3 theta_rot = mat3(1, 0, 0,
0, cos(angles.y), -sin(angles.y),
0, sin(angles.y), cos(angles.y));
mat3 phi_rot = mat3(cos(angles.x), sin(angles.x), 0.,
-sin(angles.x), cos(angles.x), 0.,
0., 0., 1.);
return theta_rot*phi_rot;
}
vec3 getRay(vec2 angles, vec2 pos)
{
mat3 camera = getCamera(angles);
return normalize(transpose(camera) * vec3(FOV * pos.x, 1., FOV * pos.y));
}
vec2 iBox( in vec3 ro, in vec3 rd, in vec3 boxSize )
{
vec3 m = sign(rd)/max(abs(rd), 1e-8);
vec3 n = m*ro;
vec3 k = abs(m)*boxSize;
vec3 t1 = -n - k;
vec3 t2 = -n + k;
float tN = max( max( t1.x, t1.y ), t1.z );
float tF = min( min( t2.x, t2.y ), t2.z );
if (tN > tF || tF <= 0.) {
return vec2(MAX_DIST);
} else {
return vec2(tN, tF);
}
}
vec2 SCALE;
vec3 size3d;
#define ar vec2(1.0,0.5)
#define R iResolution.xy
#define PI 3.1415926535
void InitGrid(vec2 iR)
{
SCALE = floor(ar * pow(iR.x * iR.y,0.1666666));
size3d = vec3(floor(iR.xy/SCALE), SCALE.x*SCALE.y);
}
void mainImage( out vec4 col, in vec2 fragCoord )
{
InitGrid(iResolution.xy);
vec2 uv = (fragCoord - 0.5*R)/max(R.x, R.y);
vec2 angles = vec2(2.*PI, PI)*(iMouse.xy/iResolution.xy - 0.5);
if(iMouse.z <= 0.)
{
angles = vec2(0.04, -0.5);
}
vec3 rd = getRay(angles, uv);
vec3 center_rd = getRay(angles, vec2(0.));
float d = sqrt(dot(vec3(size3d), vec3(size3d)))*0.5;
vec3 ro = vec3(size3d)*0.5 - center_rd*d*1.5;//The position of camera
vec2 tdBox = iBox(ro - vec3(size3d)*0.5 , rd, vec3(size3d)*0.5);
//vec2 tdBox = iBox(ro, rd, vec3(size3d));
col.xyz = vec3(0.,0.,0);
if(tdBox.x < MAX_DIST)
{
vec3 p = ro + rd*tdBox.x;
col.xyz = clamp(p, 0.0, 1.0);
}
}
above is shadertoy codes, how move it to cesium and meanwhile keep the Box exactly the same with shadertoy? You can run directly in Shadertoy.
Edited for formatting