<commit_before>module Shaders.ColorFragment exposing (colorFragment, noiseColorFragment)

import Math.Vector2 exposing (Vec2)
import Math.Vector3 exposing (Vec3)
import Math.Vector4 exposing (Vec4)
import WebGL exposing (..)


colorFragment : Shader {} u { elm_FragColor : Vec3, elm_FragCoord : Vec2 }
colorFragment =
    [glsl|

precision mediump float;

varying vec3 elm_FragColor;
varying vec2 elm_FragCoord;

void main () {
    gl_FragColor = vec4(elm_FragColor, 1.0);
}

|]



-- TODO: Configure
--  * size of fractal detail (multiplier on elm_FragCoord)
--  * speed of motion (multiplier on iGlobalTime): can be motionless for solid objects
--  * swaying in the breeze (oscillate with sin)
-- TODO: make surface2D tile seamlessly


noiseColorFragment : Shader {} { u | iResolution : Vec3, iGlobalTime : Float, iHMD : Float, iDetail : Float } { elm_FragColor : Vec4, elm_FragCoord : Vec2, worldPosition : Vec4, iTextureScale : Float, iTimeScale : Float, iSmoothing : Float }
noiseColorFragment =
    [glsl|

precision mediump float;
uniform vec3 iResolution;
uniform float iGlobalTime;
uniform float iHMD;
uniform float iDetail;

varying vec4 elm_FragColor;
varying vec2 elm_FragCoord;
varying vec4 worldPosition;
varying float iTextureScale;
varying float iTimeScale;
varying float iSmoothing;


const vec2 LeftLensCenter = vec2(0.2863248, 0.5);
const vec2 RightLensCenter = vec2(0.7136753, 0.5);
const vec2 LeftScreenCenter = vec2(0.25, 0.5);
const vec2 RightScreenCenter = vec2(0.75, 0.5);
const vec2 Scale = vec2(0.1469278, 0.2350845);
//const vec2 Scale = vec2(0.1469278, 0.2350845);
const vec2 ScaleIn = vec2(3, 2.5);
//const vec2 ScaleIn = vec2(2.5, 1.5);
const vec4 HmdWarpParam   = vec4(1, 0.22, 0.24, 0);

// Scales input texture coordinates for distortion.
vec2 HmdWarp(vec2 in01, vec2 LensCenter)
{
	vec2 theta = (in01 - LensCenter) * ScaleIn; // Scales to [-1, 1]
	float rSq = theta.x * theta.x + theta.y * theta.y;
	vec2 rvector = theta * (HmdWarpParam.x + HmdWarpParam.y * rSq +
		HmdWarpParam.z * rSq * rSq +
		HmdWarpParam.w * rSq * rSq * rSq);
	return LensCenter + Scale * rvector;
}


// by @301z

float rand(vec2 n) {
	return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
}

float noise(vec2 n) {
	const vec2 d = vec2(0.0, 1.0);
	vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));
	return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
}

float fbm(vec2 n) {
	float total = 0.0, amplitude = 1.0;
        int detail = int(iDetail);
	for (int i = 0; i < 7; i++) {
                if (i > detail) break;
		total += noise(n) * amplitude;
		n += n;
		amplitude *= 0.5;
	}
	return total;
}


void texture(vec2 tc) {
	vec3 c1 = vec3(elm_FragColor);
	vec3 c2 = c1 * vec3(0.7, 0.7, 0.7);
	vec3 c3 = c1 * vec3(0.6, 0.6, 0.6);
	vec3 c4 = c1 * vec3(0.9, 0.9, 0.9);
	vec3 c5 = vec3(0.10);
	vec3 c6 = vec3(0.50);

	//vec2 p = elm_FragCoord.xy * iTextureScale;
	vec2 p = tc.xy * iTextureScale;

        float scaledTime = iGlobalTime * iTimeScale;
        float q;
        vec2 r;
        vec3 c;

        int detail = int(iDetail);

        if (detail > 5) {
		q = fbm(p - scaledTime * 0.1);
		r = vec2(fbm(p + q + scaledTime * 0.7 - p.x - p.y), fbm(p + q - scaledTime * 0.4));
		c = mix(c1, c2, fbm(p + r)) + mix(c3, c4, r.x) - mix(c5, c6, r.y);
	} else if (detail > 2) {
		q = fbm(p - scaledTime * 0.1);
		r = vec2(fbm(p + q + scaledTime * 0.7 - p.x - p.y), fbm(p + q - scaledTime * 0.4));
		c = mix(c1, c2, fbm(p + r));
        } else {
		q = fbm(p);
		c = mix(c1, c2, q);
        }

	vec4 fractalTexture = vec4(c * cos(1.57 * gl_FragCoord.y / iResolution.y), elm_FragColor.a);
        vec4 flatTexture = elm_FragColor;
        //gl_FragColor = mix(fractalTexture, flatTexture, iSmoothing);
        float lightenDistance = clamp (0.9, 1.0, 1.0 - (float(worldPosition.w)/100.0));
        gl_FragColor = mix(fractalTexture, flatTexture, iSmoothing) * lightenDistance;
}

void hmd() {
        vec2 LensCenter = vec2(0.5, 0.5);<commit_msg>ColorFragment: lengthen lightenDistance<commit_after>module Shaders.ColorFragment exposing (colorFragment, noiseColorFragment)

import Math.Vector2 exposing (Vec2)
import Math.Vector3 exposing (Vec3)
import Math.Vector4 exposing (Vec4)
import WebGL exposing (..)


colorFragment : Shader {} u { elm_FragColor : Vec3, elm_FragCoord : Vec2 }
colorFragment =
    [glsl|

precision mediump float;

varying vec3 elm_FragColor;
varying vec2 elm_FragCoord;

void main () {
    gl_FragColor = vec4(elm_FragColor, 1.0);
}

|]



-- TODO: Configure
--  * size of fractal detail (multiplier on elm_FragCoord)
--  * speed of motion (multiplier on iGlobalTime): can be motionless for solid objects
--  * swaying in the breeze (oscillate with sin)
-- TODO: make surface2D tile seamlessly


noiseColorFragment : Shader {} { u | iResolution : Vec3, iGlobalTime : Float, iHMD : Float, iDetail : Float } { elm_FragColor : Vec4, elm_FragCoord : Vec2, worldPosition : Vec4, iTextureScale : Float, iTimeScale : Float, iSmoothing : Float }
noiseColorFragment =
    [glsl|

precision mediump float;
uniform vec3 iResolution;
uniform float iGlobalTime;
uniform float iHMD;
uniform float iDetail;

varying vec4 elm_FragColor;
varying vec2 elm_FragCoord;
varying vec4 worldPosition;
varying float iTextureScale;
varying float iTimeScale;
varying float iSmoothing;


const vec2 LeftLensCenter = vec2(0.2863248, 0.5);
const vec2 RightLensCenter = vec2(0.7136753, 0.5);
const vec2 LeftScreenCenter = vec2(0.25, 0.5);
const vec2 RightScreenCenter = vec2(0.75, 0.5);
const vec2 Scale = vec2(0.1469278, 0.2350845);
//const vec2 Scale = vec2(0.1469278, 0.2350845);
const vec2 ScaleIn = vec2(3, 2.5);
//const vec2 ScaleIn = vec2(2.5, 1.5);
const vec4 HmdWarpParam   = vec4(1, 0.22, 0.24, 0);

// Scales input texture coordinates for distortion.
vec2 HmdWarp(vec2 in01, vec2 LensCenter)
{
	vec2 theta = (in01 - LensCenter) * ScaleIn; // Scales to [-1, 1]
	float rSq = theta.x * theta.x + theta.y * theta.y;
	vec2 rvector = theta * (HmdWarpParam.x + HmdWarpParam.y * rSq +
		HmdWarpParam.z * rSq * rSq +
		HmdWarpParam.w * rSq * rSq * rSq);
	return LensCenter + Scale * rvector;
}


// by @301z

float rand(vec2 n) {
	return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
}

float noise(vec2 n) {
	const vec2 d = vec2(0.0, 1.0);
	vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));
	return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
}

float fbm(vec2 n) {
	float total = 0.0, amplitude = 1.0;
        int detail = int(iDetail);
	for (int i = 0; i < 7; i++) {
                if (i > detail) break;
		total += noise(n) * amplitude;
		n += n;
		amplitude *= 0.5;
	}
	return total;
}


void texture(vec2 tc) {
	vec3 c1 = vec3(elm_FragColor);
	vec3 c2 = c1 * vec3(0.7, 0.7, 0.7);
	vec3 c3 = c1 * vec3(0.6, 0.6, 0.6);
	vec3 c4 = c1 * vec3(0.9, 0.9, 0.9);
	vec3 c5 = vec3(0.10);
	vec3 c6 = vec3(0.50);

	//vec2 p = elm_FragCoord.xy * iTextureScale;
	vec2 p = tc.xy * iTextureScale;

        float scaledTime = iGlobalTime * iTimeScale;
        float q;
        vec2 r;
        vec3 c;

        int detail = int(iDetail);

        if (detail > 5) {
		q = fbm(p - scaledTime * 0.1);
		r = vec2(fbm(p + q + scaledTime * 0.7 - p.x - p.y), fbm(p + q - scaledTime * 0.4));
		c = mix(c1, c2, fbm(p + r)) + mix(c3, c4, r.x) - mix(c5, c6, r.y);
	} else if (detail > 2) {
		q = fbm(p - scaledTime * 0.1);
		r = vec2(fbm(p + q + scaledTime * 0.7 - p.x - p.y), fbm(p + q - scaledTime * 0.4));
		c = mix(c1, c2, fbm(p + r));
        } else {
		q = fbm(p);
		c = mix(c1, c2, q);
        }

	vec4 fractalTexture = vec4(c * cos(1.57 * gl_FragCoord.y / iResolution.y), elm_FragColor.a);
        vec4 flatTexture = elm_FragColor;
        //gl_FragColor = mix(fractalTexture, flatTexture, iSmoothing);
        float lightenDistance = clamp (0.9, 1.0, 1.0 - (float(worldPosition.w)/200.0));
        gl_FragColor = mix(fractalTexture, flatTexture, iSmoothing) * lightenDistance;
}

void hmd() {
        vec2 LensCenter = vec2(0.5, 0.5);
{'fraction_non_alphanumeric': 0.1448609731876862, 'fraction_numerical': 0.06802383316782522, 'mean_word_length': 3.2472324723247232, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4487153', 'n_tokens_mistral': 3613, 'n_tokens_neox': 3317, 'n_words': 869}