PF Villard d'après le cours de Eric Haines (Autodesk Inc.) disponible sur Udacity
Les concepteurs de cartes informatiques doivent élaborer des transistors pour :
→Traitement de fonctions fixes
→gl_FragColor
Quelles sont les affirmations correctes ?
uniform vec3 uMaterialColor;
WebGL: GLSL
→ OpenGL Shading Language for Embedded Systems
DirectX: HLSL
→ High Level Shading Language
vertexShader: [
"uniform vec3 uMaterialColor;",
"uniform vec3 uDirLight;",
"varying vec3 vColor;",
"void main() {",
// Transform the vertex from model space to screen space
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"vec3 light = normalize( uDirLight );",
// Compute a diffuse color using Lambertian reflection, N * L
"float diffuse = max( dot( normal, light ), 0.0);",
"vColor = uMaterialColor * diffuse;",
"}"
].join("\n"),
uniform vec3 uMaterialColor;
uniform vec3 uDirLight;
varying vec3 vColor;
void main() {
// Transform the vertex from model space to clip coordinates
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
vec3 light = normalize( uDirLight );
// Compute a diffuse color using Lambertian reflection, N * L
float diffuse = max( dot( normal, light ), 0.0);
vColor = uMaterialColor * diffuse;
}
GLSL↝ langage C ↝ javascript
Sortie du vertex shader:
gl_Position
: la position des coordonnées clipéesvColor
: la couleur diffuse au sommetCode :
varying vec3 vColor;
void main() {
gl_FragColor = vec4(vColor, 1.0);
}
vec3 uSpecularColor;
float specular;
...
gl_FragColor.rgb += specular * uSpecularColor;
gl_FragColor.rgb
→ X,Y,Z,W = Points et vecteurs
gl_FragColor.rgb
→ R,G,B,A = Couleurs
gl_FragColor.rgb
→ S,T,P,Q = Coordonnées de textures
abs(),sin(),pow(),sqrt(),normalize(), dot(),cross(),...
float diffuse = max(
dot( normal, light ), 0.0);
Si le produit scalaire est suffisamment grand:
alors
la couleur diffuse est 1.0
sinon
la couleur diffuse est 0.5
varying vec3 vNormal;
varying vec3 vViewPosition;
void main() {
gl_position= projectionMatrix*modelViewMatrix*vec4(position,1.0);
vNormal= normalize (normalMatrix*normal);
vec4 mvPosition=modelViewMatrix*vec4(position, 1.0);
vViewPosition= -mvPosition.xyz;
}
Types de projection :
Augustin-Jean Fresnel (1788-1827)