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);