optimointeja
This commit is contained in:
@ -89,6 +89,7 @@ float hexDistance(vec2 axial) {
|
|||||||
return max(abs(q), max(abs(r), abs(s)));
|
return max(abs(q), max(abs(r), abs(s)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
float hexPylon(vec3 p, vec2 h) {
|
float hexPylon(vec3 p, vec2 h) {
|
||||||
//vec3 p = vec3(p.x, p.z, p2.y);
|
//vec3 p = vec3(p.x, p.z, p2.y);
|
||||||
vec3 b = vec3(h.x, h.y, h.x);
|
vec3 b = vec3(h.x, h.y, h.x);
|
||||||
@ -100,11 +101,12 @@ float hexPylon(vec3 p, vec2 h) {
|
|||||||
// and larger numbers give a more rounded look.
|
// and larger numbers give a more rounded look.
|
||||||
return lev3(max(abs(p) - b + .15, 0.)) - .15;
|
return lev3(max(abs(p) - b + .15, 0.)) - .15;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
//////////////
|
//////////////
|
||||||
// SCENE //
|
// SCENE //
|
||||||
//////////////
|
//////////////
|
||||||
|
/*
|
||||||
// instructions -> opU( { float to union with } , vec2( {put shape here}, {put material here} ) )
|
// instructions -> opU( { float to union with } , vec2( {put shape here}, {put material here} ) )
|
||||||
vec2 opU(vec2 d1, vec2 d2) {
|
vec2 opU(vec2 d1, vec2 d2) {
|
||||||
return (d1.x < d2.x) ? d1 : d2;
|
return (d1.x < d2.x) ? d1 : d2;
|
||||||
@ -113,6 +115,7 @@ vec2 opU(vec2 d1, vec2 d2) {
|
|||||||
float sdSphere(vec3 p, float r){
|
float sdSphere(vec3 p, float r){
|
||||||
return lev3(p) -r;
|
return lev3(p) -r;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Scene mapping with occlusion-aware SDF blending
|
// Scene mapping with occlusion-aware SDF blending
|
||||||
vec2 mapScene(vec3 p) {
|
vec2 mapScene(vec3 p) {
|
||||||
@ -195,6 +198,7 @@ vec3 castRay(vec3 ro, vec3 rd, inout vec3 pos) {
|
|||||||
////////////////
|
////////////////
|
||||||
// SHADING //
|
// SHADING //
|
||||||
////////////////
|
////////////////
|
||||||
|
/*
|
||||||
float softshadow(in vec3 ro, in vec3 rd, float mint, float maxt, float w) {
|
float softshadow(in vec3 ro, in vec3 rd, float mint, float maxt, float w) {
|
||||||
float res = 1.0;
|
float res = 1.0;
|
||||||
float t = mint;
|
float t = mint;
|
||||||
@ -210,10 +214,11 @@ float softshadow(in vec3 ro, in vec3 rd, float mint, float maxt, float w) {
|
|||||||
res = max(res, -1.0);
|
res = max(res, -1.0);
|
||||||
return 0.25 * (1.0 + res) * (1.0 + res) * (2.0 - res);
|
return 0.25 * (1.0 + res) * (1.0 + res) * (2.0 - res);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
vec3 addPointLight(vec3 lightPos, vec3 lightColor, float intensity, vec3 worldPos, vec3 viewDir, vec3 normal) {
|
vec3 addPointLight(vec3 lightPos, vec3 lightColor, float intensity, vec3 worldPos, vec3 viewDir, vec3 normal) {
|
||||||
// Light vector from surface to light
|
// Light vector from surface to light
|
||||||
float roughness = 1.0;
|
//float roughness = 1.0;
|
||||||
vec3 lightDir = lightPos - worldPos;
|
vec3 lightDir = lightPos - worldPos;
|
||||||
float lightDistance = lev3(lightDir);
|
float lightDistance = lev3(lightDir);
|
||||||
lightDir = no(lightDir);
|
lightDir = no(lightDir);
|
||||||
@ -226,20 +231,21 @@ vec3 addPointLight(vec3 lightPos, vec3 lightColor, float intensity, vec3 worldPo
|
|||||||
vec3 diffuse = lightColor * NdotL * attenuation;
|
vec3 diffuse = lightColor * NdotL * attenuation;
|
||||||
|
|
||||||
// Specular lighting (Blinn-Phong)
|
// Specular lighting (Blinn-Phong)
|
||||||
|
/*
|
||||||
vec3 halfDir = no(lightDir + (-viewDir));
|
vec3 halfDir = no(lightDir + (-viewDir));
|
||||||
float NdotH = max(dot(normal, halfDir), 0.0);
|
float NdotH = max(dot(normal, halfDir), 0.0);
|
||||||
float shininess = mix(128.0, 8.0, roughness); // Convert roughness to shininess
|
float shininess = mix(128.0, 8.0, roughness); // Convert roughness to shininess
|
||||||
vec3 specular = lightColor * pow(NdotH, shininess) * attenuation;
|
*/
|
||||||
|
vec3 specular = lightColor * attenuation;
|
||||||
|
|
||||||
// Fresnel effect
|
// Fresnel effect
|
||||||
vec3 F0 = vec3(0.04); // Base reflectance for dielectrics
|
//vec3 F0 = vec3(0.04); // Base reflectance for dielectrics
|
||||||
vec3 fresnel = F0 + (1.0 - F0) * pow(clamp(1.0 - max(dot(halfDir, lightDir), 0.0), 0.0, 1.0), 5.0);
|
//vec3 fresnel = F0 + (1.0 - F0) * pow(cl(1.0 - max(dot(halfDir, lightDir), 0.0), 0.0, 1.0), 5.0);
|
||||||
|
|
||||||
// Soft shadows
|
|
||||||
float shadow = softshadow(worldPos + normal * 0.01, lightDir, 0.02, lightDistance, 4.0);
|
|
||||||
|
|
||||||
// Combine diffuse and specular with shadow
|
// Combine diffuse and specular with shadow
|
||||||
return (diffuse + specular * fresnel) * shadow * shadow;
|
// return (diffuse + specular * fresnel) * shadow * shadow;
|
||||||
|
//return (diffuse * fresnel);
|
||||||
|
return diffuse + specular;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 calcNormal(vec3 pos) {
|
vec3 calcNormal(vec3 pos) {
|
||||||
@ -279,8 +285,9 @@ vec3 shading(vec3 p, vec3 n, vec3 dir, vec3 camPos) {
|
|||||||
|
|
||||||
vec3 lights = vec3(0.);
|
vec3 lights = vec3(0.);
|
||||||
//lights += phongLighting(p, n, camPos, dir, vec3(0.51), outMaterial);
|
//lights += phongLighting(p, n, camPos, dir, vec3(0.51), outMaterial);
|
||||||
lights += addPointLight(vec3(0., 20.0, 0.), vec3(0.77, 0.26, 0.73), 30.0, p, dir, n);
|
lights += addPointLight(vec3(0., 20.0, 0.), vec3(0.7, 0.3, 0.7), 20.0, p, dir, n);
|
||||||
|
|
||||||
|
/*
|
||||||
// LIGHT CHANGING WITH CIRCLE RADIUS
|
// LIGHT CHANGING WITH CIRCLE RADIUS
|
||||||
float maxRadius = 25.; // Circle radius
|
float maxRadius = 25.; // Circle radius
|
||||||
float particleHeight = 15.; //(syncs[5] * 40.);
|
float particleHeight = 15.; //(syncs[5] * 40.);
|
||||||
@ -302,11 +309,12 @@ vec3 shading(vec3 p, vec3 n, vec3 dir, vec3 camPos) {
|
|||||||
//res = opU(res, vec2(sdSphere(p - objPos, sphereRadius), 1.));
|
//res = opU(res, vec2(sdSphere(p - objPos, sphereRadius), 1.));
|
||||||
|
|
||||||
lights += addPointLight(objPos, vec3(0.33, 0.91, 0.93), 30.0, p, dir, n);
|
lights += addPointLight(objPos, vec3(0.33, 0.91, 0.93), 30.0, p, dir, n);
|
||||||
|
*/
|
||||||
|
|
||||||
vec3 lightDir = vec3(0., 2., 3);
|
vec3 lightDir = vec3(0., 2., 3);
|
||||||
|
|
||||||
float ind = cl(dot(n, no(lightDir * vec3(.0, 1.0, -2.0))), 0.0, 1.0);
|
float ind = cl(dot(n, no(lightDir * vec3(.0, 1.0, -2.0))), 0.0, 1.0);
|
||||||
//lights += vec3(0.08, 0.62, 0.75) * ind * 0.8;
|
lights += vec3(0.6, 0.6, 0.6) * ind * 0.6;
|
||||||
|
|
||||||
outMaterial *= max(vec3(0.), lights); // output with lights;
|
outMaterial *= max(vec3(0.), lights); // output with lights;
|
||||||
|
|
||||||
@ -326,10 +334,10 @@ vec3 postProcess(vec3 col) {
|
|||||||
col = pow(col, vec3(.55)); // gamma 2.2
|
col = pow(col, vec3(.55)); // gamma 2.2
|
||||||
|
|
||||||
// fade in at the beginning
|
// fade in at the beginning
|
||||||
//col*=vec3(clamp((u_time-1.8)*0.5,0., 1.));
|
//col*=vec3(cl((u_time-1.8)*0.5,0., 1.));
|
||||||
|
|
||||||
// fade out at the end
|
// fade out at the end
|
||||||
// col*=vec3(clamp((120.-u_time)*.35, 0., 1.));
|
// col*=vec3(cl((120.-u_time)*.35, 0., 1.));
|
||||||
|
|
||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
@ -345,10 +353,10 @@ vec3 getCameraRayDir(vec2 uv, vec3 camPos, vec3 camTarget, float fov) {
|
|||||||
|
|
||||||
vec3 render(vec2 uv) {
|
vec3 render(vec2 uv) {
|
||||||
vec3 camPos = vec3(-20.0 + sin(syncs[0] * 0.25) * 5, abs(sin(syncs[0] * 0.25) * 10) + 25.0, -20.0);
|
vec3 camPos = vec3(-20.0 + sin(syncs[0] * 0.25) * 5, abs(sin(syncs[0] * 0.25) * 10) + 25.0, -20.0);
|
||||||
vec3 camTarget = vec3(0.0, 0.0, 0.0); // Adjust target as needed
|
// vec3 camTarget = vec3(0.) // Adjust target as needed
|
||||||
float fov = 1.0;
|
//float fov = 1.0;
|
||||||
|
|
||||||
vec3 rayDir = getCameraRayDir(uv, camPos, camTarget, fov);
|
vec3 rayDir = getCameraRayDir(uv, camPos, vec3(0.), 1.0);
|
||||||
|
|
||||||
vec3 col = vec3(0.); // background color
|
vec3 col = vec3(0.); // background color
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user