From 99769e924d68ac8e6d4b44c90caebb30a3b6d9b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9lemy?= <31370477+BarthPaleologue@users.noreply.github.com> Date: Mon, 6 Nov 2023 18:23:33 +0100 Subject: [PATCH] added some ambient lighting + fixed shading --- src/shaders/grassFragment.glsl | 3 +++ src/shaders/grassVertex.glsl | 3 ++- src/ts/index.ts | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/shaders/grassFragment.glsl b/src/shaders/grassFragment.glsl index a401286..f8a0224 100644 --- a/src/shaders/grassFragment.glsl +++ b/src/shaders/grassFragment.glsl @@ -16,5 +16,8 @@ void main() { float ndl2 = max(dot(-normalW, lightDirection), 0.0); float ndl = ndl1 + ndl2; + // ambient lighting + ndl = clamp(ndl + 0.1, 0.0, 1.0); + gl_FragColor = vec4(finalColor * ndl, 1.0);// apply color and lighting } \ No newline at end of file diff --git a/src/shaders/grassVertex.glsl b/src/shaders/grassVertex.glsl index 967b0d1..50eefc3 100644 --- a/src/shaders/grassVertex.glsl +++ b/src/shaders/grassVertex.glsl @@ -22,10 +22,11 @@ void main() { float leanAmount = 0.3; float curveAmount = leanAmount * position.y; vec3 rotatedPosition = rotateAround(position, vec3(1.0, 0.0, 0.0), curveAmount); + vec3 rotatedNormal = rotateAround(normal, vec3(1.0, 0.0, 0.0), curveAmount); vec4 outPosition = viewProjection * finalWorld * vec4(rotatedPosition, 1.0); gl_Position = outPosition; normalMatrix = transpose(inverse(finalWorld)); - vNormal = normal; + vNormal = rotatedNormal; } \ No newline at end of file diff --git a/src/ts/index.ts b/src/ts/index.ts index 8091adf..072b693 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -46,7 +46,7 @@ grassBlade.material = material; const grassBlades = []; const patchSize = 10; -const patchResolution = 20; +const patchResolution = 50; const cellSize = patchSize / patchResolution; const patchPosition = new Vector3(0, 0, 0);