Skip to content

Commit

Permalink
Merge branch 'alpha'
Browse files Browse the repository at this point in the history
  • Loading branch information
jakedowns committed Jan 17, 2024
2 parents 5fe93b4 + e986aa2 commit df2367c
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 21 deletions.
54 changes: 47 additions & 7 deletions public/pixel-mixer.html
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ <h1>Pixel Mixer Demo</h1>
vec2MouseWheelRaw.x,
vec2MouseWheelRaw.y
);
material.uniforms.numLights = window.settings.numLights;
};

setUniforms(window.outputMaterialA);
Expand Down Expand Up @@ -769,7 +770,10 @@ <h1>Pixel Mixer Demo</h1>
iResolution: { value: new THREE.Vector3(0) },
iMouse: { value: window.mouseLerping },
iMouseRaw: { value: window.mouseRaw },
iMouseWheel: { value: window.iMouseWheel }
iMouseWheel: { value: window.iMouseWheel },
numLights: {
value: 1
}
},
vertexShader: `
void main() {
Expand All @@ -791,6 +795,7 @@ <h1>Pixel Mixer Demo</h1>
iMouse: { value: window.mouseLerping },
iMouseRaw: { value: window.mouseRaw },
iMouseWheel: { value: window.iMouseWheel },
numLights: { value: 1 }
},
vertexShader: `
void main() {
Expand Down Expand Up @@ -946,16 +951,43 @@ <h1>Pixel Mixer Demo</h1>
return;
}

if(key === 'numLights'){
//console.log('setting numLights',uniforms[key])
material.uniforms.numLights.value = parseFloat(uniforms[key]);
return;
}

// if it's a float, just set it
if(typeof uniforms[key] === 'number'){
material.uniforms[key].value = uniforms[key];
return;
}
if(key === 'iChannel0' || key === 'iChannel1' || key === 'iChannel2' || key === 'iChannel3'){
//console.warn('setting channel',key,uniforms[key])
material.uniforms[key].value = uniforms[key].texture;
return;
}


if(typeof uniforms[key].value === 'object'){
let value = uniforms[key].value;
if('w' in value){
material.uniforms[key].value.set(value.x, value.y, value.z, value.w);
} else if('z' in value){
material.uniforms[key].value.set(value.x, value.y, value.z);
} else if('y' in value){
material.uniforms[key].value.set(value.x, value.y);
} else if('x' in value){
material.uniforms[key].value.set(value.x);
}
return;
}

// if(typeof uniforms[key].value === 'object' && 'x' in uniforms[key].value && 'y' in uniforms[key].value && 'z' in uniforms[key].value && 'w' in uniforms[key].value){
// // console.warn('passing object with x, y, z, w', {key}, uniforms[key], 'to', material.uniforms[key].value)
// material.uniforms[key].value.set(uniforms[key].value.x, uniforms[key].value.y, uniforms[key].value.z, uniforms[key].value.w);
// }else{


console.warn('unknown uniform type',key,uniforms[key])

//else{
// // console.warn('passing single argument', {key}, uniforms[key], 'to', material.uniforms[key].value)
// // console.warn({
// // a: typeof material.uniforms[key],
Expand Down Expand Up @@ -1377,6 +1409,7 @@ <h1>Pixel Mixer Demo</h1>
pixel_density: 1,
useDoubleBuffer: true,
ambientLightColor: "#ff00ffff",
numLights: 3,
}

window.onSettingsChanged = function(){
Expand Down Expand Up @@ -1414,7 +1447,8 @@ <h1>Pixel Mixer Demo</h1>
iResolution: new THREE.Vector3(safePXDims.x, safePXDims.y, 1.0),
iMouse: window.mouseLerping,
iMouseRaw: window.mouseRaw,
iMouseWheel: window.iMouseWheel
iMouseWheel: window.iMouseWheel,
numLights: settings.numLights
});
updateMaterialUniforms(window.outputMaterialB, {
iChannel0: window.outputTextureA,
Expand All @@ -1423,7 +1457,8 @@ <h1>Pixel Mixer Demo</h1>
iResolution: new THREE.Vector3(safePXDims.x, safePXDims.y, 1.0),
iMouse: window.mouseLerping,
iMouseRaw: window.mouseRaw,
iMouseWheel: window.iMouseWheel
iMouseWheel: window.iMouseWheel,
numLights: settings.numLights
});


Expand Down Expand Up @@ -1502,6 +1537,10 @@ <h1>Pixel Mixer Demo</h1>
.name( 'Pixel Density' )
.onChange( window.resizeCanvas );

panel.add(settings, 'numLights', 1, 3, 1)
.name( 'Num Lights #️⃣💡' )
//.onChange( )

// ambientLightColor
panel.addColor(settings, 'ambientLightColor', true)
.name('Ambient Light Color')
Expand Down Expand Up @@ -1566,6 +1605,7 @@ <h1>Pixel Mixer Demo</h1>
uniform vec4 iMouse;
uniform vec4 iMouseRaw;
uniform vec4 iMouseWheel;
uniform int numLights;
vec3 hsv2rgb(vec3 c) {
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
Expand Down
58 changes: 44 additions & 14 deletions shaders/fresh.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ uniform vec3 iResolution;
uniform vec4 iMouse;
uniform vec4 iMouseRaw;
uniform vec4 iMouseWheel;
uniform float numLights;
// define PI
const float PI = 3.1415926535897932384626433832795;
// End shadertoy global uniforms
Expand Down Expand Up @@ -55,27 +56,56 @@ void main() {
}

float radius = 0.01 * (abs(iMouseWheel.y) * 0.1 + 1.0);

// Quaternion-based rotation
float angleX = mod(iTime * 10.0, 360.0); // Rotation angle around X-axis
float angleY = mod(iTime * 80.0, 360.0); // Rotation angle around Y-axis
vec4 quatX = quat_from_axis_angle(vec3(1, 0, 0), radians(angleX));
vec4 quatY = quat_from_axis_angle(vec3(0, 1, 0), radians(angleY));
vec4 quatRot = quat_multiply(quatX, quatY);

vec3 lightPos = rotate_by_quaternion(vec3(1, 0, 0), quatRot);
float angleX = mod(iTime * 100.0, 360.0); // Rotation angle around X-axis
float angleY = mod(iTime * -100.0, 360.0); // Rotation angle around Y-axis

// First light
vec4 quatX1 = quat_from_axis_angle(vec3(1, 0, 0), radians(angleX));
vec4 quatY1 = quat_from_axis_angle(vec3(0, 1, 0), radians(angleY));
vec4 quatRot1 = quat_multiply(quatX1, quatY1);
vec3 sphereCenter = vec3(uv, 0.0);
vec3 toLight = normalize(lightPos - sphereCenter);

vec3 sphereNormal = normalize(vec3(uv - mouse, fastsqrt(radius*radius - dot(uv - mouse, uv - mouse))));

float diff = max(dot(sphereNormal, toLight), 0.0);

vec3 colorUV = diff * vec3(0.62, 0.33, 0.15);
vec3 lightPos1 = rotate_by_quaternion(vec3(1, 0, 0), quatRot1);
vec3 toLight1 = normalize(lightPos1 - sphereCenter);
float diff = max(dot(sphereNormal, toLight1), 0.0);
vec3 colorUV1 = diff * vec3(0.62, 0.33, 0.15); // First light color

// Second light
vec4 quatX2 = quat_from_axis_angle(vec3(1, 0, 0), radians(angleX + 90.0)); // Change rotation for second light
vec4 quatY2 = quat_from_axis_angle(vec3(0, 1, 0), radians(angleY + 90.0)); // Change rotation for second light
vec4 quatRot2 = quat_multiply(quatX2, quatY2);

vec3 lightPos2 = rotate_by_quaternion(vec3(1, 0, 0), quatRot2);
vec3 toLight2 = normalize(lightPos2 - sphereCenter);
diff = max(dot(sphereNormal, toLight2), 0.0);
vec3 colorUV2 = diff * vec3(0.15, 0.33, 0.62); // Second light color

// Third light
vec4 quatX3 = quat_from_axis_angle(vec3(1, 0, 0), radians(angleX + 180.0)); // Change rotation for third light
vec4 quatY3 = quat_from_axis_angle(vec3(0, 1, 0), radians(angleY + 180.0)); // Change rotation for third light
vec4 quatRot3 = quat_multiply(quatX3, quatY3);

vec3 lightPos3 = rotate_by_quaternion(vec3(1, 0, 0), quatRot3);
vec3 toLight3 = normalize(lightPos3 - sphereCenter);
diff = max(dot(sphereNormal, toLight3), 0.0);
vec3 colorUV3 = diff * vec3(0.15, 0.62, 0.33); // Third light color

// Combine the three lights
vec3 colorUV;
// if (numLights <= 2.0) {
// colorUV = colorUV1;
// } else if (numLights <= 3.0) {
// colorUV = colorUV1 + colorUV2;
// } else {
colorUV = colorUV1 + colorUV2 + colorUV3;
// }
// vec3 colorUV = diff * vec3(0.27, 0.15, 0.62);

if(length(uv - mouse) < radius){
gl_FragColor = vec4(colorUV, 1.0);
gl_FragColor.a = ((gl_FragColor.r * .4) + (gl_FragColor.g * 1.3) + (gl_FragColor.b * .9)) / 3.0;
gl_FragColor.a = 1.0;// ((gl_FragColor.r * .4) + (gl_FragColor.g * 1.3) + (gl_FragColor.b * .9)) / 3.0;
return;
}

Expand Down

0 comments on commit df2367c

Please sign in to comment.