49 lines
1.6 KiB
GLSL
49 lines
1.6 KiB
GLSL
uniform sampler2D uTexture;
|
|
uniform float uGridSize;
|
|
uniform float uStrength;
|
|
uniform vec2 uViewOffset;
|
|
uniform vec2 uResolution;
|
|
uniform float uTime;
|
|
uniform vec2 uPetSize;
|
|
uniform bool uIsVideo;
|
|
|
|
varying vec2 vUv;
|
|
varying vec3 vWorldPosition;
|
|
|
|
float hash(float value) { return fract(sin(value * 91.7) * 43758.5453); }
|
|
|
|
vec3 srgbToLinear(vec3 value) {
|
|
return mix(value / 12.92, pow((value + 0.055) / 1.055, vec3(2.4)), step(vec3(0.04045), value));
|
|
}
|
|
|
|
vec4 mediaSample(vec2 uv) {
|
|
vec3 background = srgbToLinear(vec3(17.0, 25.0, 35.0) / 255.0);
|
|
if (any(lessThan(uv, vec2(0.0))) || any(greaterThan(uv, vec2(1.0)))) return vec4(background, 1.0);
|
|
vec4 color = texture2D(uTexture, uv);
|
|
if (uIsVideo) color.rgb = srgbToLinear(color.rgb);
|
|
return color;
|
|
}
|
|
|
|
vec2 hitUv(vec3 ray) {
|
|
float rayZ = abs(ray.z) < 0.0001 ? (ray.z < 0.0 ? -0.0001 : 0.0001) : ray.z;
|
|
float signedT = -vWorldPosition.z / rayZ;
|
|
return (vWorldPosition + ray * signedT).xy / uPetSize + 0.5;
|
|
}
|
|
|
|
void main() {
|
|
float ridgeCount = max(1.0, uGridSize * uPetSize.x / uPetSize.y);
|
|
float ridgeCoordinate = vUv.x * ridgeCount;
|
|
float ridgeCell = floor(ridgeCoordinate);
|
|
float phase = fract(ridgeCoordinate) * 6.2831853;
|
|
float ridge = sin(phase + uViewOffset.x * 0.9);
|
|
float ridgeVariation = mix(0.92, 1.08, hash(ridgeCell));
|
|
vec3 normal = normalize(vec3(-ridge * 0.34 * ridgeVariation, 0.0, 1.0));
|
|
vec3 incident = normalize(vWorldPosition - cameraPosition);
|
|
vec3 refracted = refract(incident, normal, 0.75);
|
|
vec2 uv = mix(hitUv(incident), hitUv(refracted), clamp(uStrength, 0.0, 1.0));
|
|
vec4 color = mediaSample(uv);
|
|
color.a = 1.0;
|
|
gl_FragColor = color;
|
|
#include <colorspace_fragment>
|
|
}
|