Skip to content

Commit

Permalink
added some ambient lighting + fixed shading
Browse files Browse the repository at this point in the history
  • Loading branch information
BarthPaleologue committed Nov 6, 2023
1 parent 52c5efa commit 99769e9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/shaders/grassFragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion src/shaders/grassVertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 99769e9

Please sign in to comment.