Lecture 6: The Rasterization Pipeline (46)
colinsteidtmann

I used Bard to help explain this slide to me (this doesn't need to count for my comment count lol). Pasting it here in case it helps for readers before exams

Inputs:

uniform sampler2D myTexture: This refers to a texture image stored in memory, accessible by the shader program.

uniform vec3 lightDir: This is a three-dimensional vector representing the direction of the light source in the scene.

varying vec2 uv: This is a two-dimensional vector (u, v coordinates) that tells the shader where the current fragment (pixel) is located within the texture image.

varying vec3 norm: This is a three-dimensional vector representing the normal vector of the surface at the current fragment. It indicates the surface's "up" direction.

Shader code:

void diffuseShader() {

vec3 kd; // Declare variable to store diffuse color

// Look up the color from the texture at the current UV coordinates

kd = texture2d(myTexture, uv);

// Calculate diffuse shading using Lambert's cosine law

kd *= clamp(dot(-lightDir, norm), 0.0, 1.0);

// Set the fragment's color to the calculated diffuse color

gl_FragColor = vec4(kd, 1.0); // Set alpha to 1.0 for full opacity }

You must be enrolled in the course to comment