bx-1480-shaderexp #76

Merged
ksenia_mikhailova merged 5 commits from bx-1480-shaderexp into dev 2024-10-01 11:03:26 +03:00
5 changed files with 47 additions and 7 deletions
Showing only changes of commit 8572014f6b - Show all commits

View File

@ -1,7 +1,7 @@
#include <dithering_fragment>
// vec2 st = vec2(vDistance,vDistance)/vec2(u_resolution);
vec2 st = gl_FragCoord.xy / vec2(u_resolution);
vec2 st = vPosition.xy / vec2(u_resolution);
vec3 pos = vec3(st * 5.0, 1.0 * 0.5);

View File

@ -2,6 +2,8 @@ uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
varying float vDistance;
varying vec3 vPosition;
float random(in float x) {
return fract(sin(x) * 1e4);
}
@ -23,3 +25,33 @@ float noise(in vec3 p) {
vec3 u = f * f * (3.0 - 2.0 * f);
return mix(mix(mix(random(n + dot(step, vec3(0, 0, 0))), random(n + dot(step, vec3(1, 0, 0))), u.x), mix(random(n + dot(step, vec3(0, 1, 0))), random(n + dot(step, vec3(1, 1, 0))), u.x), u.y), mix(mix(random(n + dot(step, vec3(0, 0, 1))), random(n + dot(step, vec3(1, 0, 1))), u.x), mix(random(n + dot(step, vec3(0, 1, 1))), random(n + dot(step, vec3(1, 1, 1))), u.x), u.y), u.z);
}
// <https://www.shadertoy.com/view/Xd23Dh>
// by inigo quilez <http://iquilezles.org/www/articles/voronoise/voronoise.htm>
//
vec3 hash3(vec2 p) {
vec3 q = vec3(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)), dot(p, vec2(419.2, 371.9)));
return fract(sin(q) * 43758.5453);
}
float iqnoise(in vec2 x, float u, float v) {
vec2 p = floor(x);
vec2 f = fract(x);
float k = 1.0 + 63.0 * pow(1.0 - v, 4.0);
float va = 0.0;
float wt = 0.0;
for(int j = -2; j <= 2; j++) for(int i = -2; i <= 2; i++) {
vec2 g = vec2(float(i), float(j));
vec3 o = hash3(p + g) * vec3(u, u, 1.0);
vec2 r = g - f + o.xy;
float d = dot(r, r);
float ww = pow(1.0 - smoothstep(0.0, 1.414, sqrt(d)), k);
va += o.z * ww;
wt += ww;
}
return va / wt;
}

View File

@ -52,7 +52,7 @@ function generateNoiseTexture(width: number, height: number) {
texture.needsUpdate = true;
return texture;
}
console.log(vertexShader)
const m_onBeforeCompile = (shader) => {
// Добавляем uniform переменную
shader.uniforms.u_resolution = { value: new Vector2(20.0, 20.0) };
@ -60,6 +60,7 @@ const m_onBeforeCompile = (shader) => {
// Изменяем вершинный шейдер
shader.vertexShader = `
varying float vDistance;
varying vec3 vPosition;
${shader.vertexShader}
`.replace(
`#include <begin_vertex>`,

View File

@ -1,7 +1,9 @@
vec2 normal_st = gl_FragCoord.xy / vec2(u_resolution);
// vec2 normal_st = vec2(random(vDistance), random(vDistance))/vec2(u_resolution);
vec2 normal_st = vec2(vPosition.x * vPosition.y, vPosition.y) * vec2(1000 * 2);
// vec2 normal_st = vec2(random(vDistance), random(vDistance))/vec2(u_resolution);
vec3 normal_pos = vec3(normal_st * 5.0, 1.0 * 0.5);
vec3 normal_noise = vec3(noise(normal_pos));
vec3 modifiedNormal = normalize(normal + normal_noise);
// vec3 pos_xz = vPosition * vec3(1.0, 0.0, 1.0);
// vec3 distance = pos_xz + vec3(0.15);
vec3 normal_noise = vec3(noise(normal_pos));
vec3 modifiedNormal = normal * normal_noise * vec3(0.5);
normal = modifiedNormal;

View File

@ -1 +1,6 @@
vDistance = length(position);
// Вычисляем расстояние от текущей вершины до некоторой точки в пространстве
vec3 pointToMeasure = vec3(1.0, 1.0, 1.0); // Некоторая точка, до которой вы хотите измерить расстояние
// Используем функцию distance, чтобы вычислить расстояние от вершины до точки
vDistance = distance(pointToMeasure, position.xyz);
vPosition = position.xyz;