5,336
edits
No edit summary |
|||
Line 1: | Line 1: | ||
OpenGL Shading Language (GLSL) is the shader language used in OpenGL and WebGL. | OpenGL Shading Language (GLSL) is the shader language used in OpenGL and WebGL. | ||
Note that there are multiple versions of OpenGL such as 3, 4, ES | |||
==Usage== | ==Usage== | ||
===Vertex Shader=== | |||
In the vertex shader, you position vertices by projecting them from object coordinates to camera coordinates. | |||
This is typically done by multiplying each vertex position, passed as an attribute, with the MVP matrices, passed as a uniform. | |||
Oftentimes you will also want to pass the UV coordinates to the fragment shader as a varying. | |||
===Fragment Shader=== | |||
In the fragment shader, you will typically sample a base color and apply lighting to your object. | |||
Sampling is typically done with <code>texture2D</code> which returns an interpolated and mipmaped color from your <code>sampler2D<code> texture. | |||
==Pipeline== | ==Pipeline== |