카테고리 없음

shader is a computer program that is used to do shading

Jacob_ 2014. 2. 2. 18:25

https://www.shadertoy.com/

https://www.shadertoy.com/view/MdX3Rr   <-- it's awesome work and amazing





In the field of computer graphics, a shader is a computer program that is used to do shading - the production of appropriate levels of light and color within an image - or, in the modern era, also to produce special effects or do postprocessing. A definition in layman's terms might be given as "a program that teaches a computer how to draw something in a specific and unique way".


Shaders calculate rendering effects on graphics hardware with a high degree of flexibility. Most shaders are coded for a graphics processing unit (GPU), though this is not a strict requirement. Shading languages are usually used to program the programmable GPU rendering pipeline, which has mostly superseded the fixed-function pipeline that allowed only common geometry transformation and pixel-shading functions; with shaders, customized effects can be used. The position, hue, saturation, brightness, and contrast of all pixels, vertices, or textures used to construct a final image can be altered on the fly, using algorithms defined in the shader, and can be modified by external variables or textures introduced by the program calling the shader.


Shaders are used widely in cinema postprocessing, computer-generated imagery, and video games to produce a seemingly infinite range of effects. Beyond just simple lighting models - see List of common shading algorithms - more complex uses include altering the hue, saturation,brightness and/or contrast of an image, producing blur, bokeh, cel shading, posterization, bump mapping, distortion, chroma keying (so-called "bluescreen/ greenscreen" effects), edge detection and motion detection, psychedelic effects, and a wide range of others.


from wikipedia.org




Programming shaders[edit]


The language in which shaders are programmed depends on the target environment. The official OpenGL and OpenGL ES shading language is OpenGL Shading Language, also known as GLSL, and the official Direct3D shading language is High Level Shader Language, also known as HLSL. However, Cg is a third-party shading language developed by Nvidia that outputs both OpenGL and Direct3D shaders.


Example: GLSL program for shading vertices without light or texture

// Vertex Shader
varying vec4 color;
 
void main()
{
  // Treat the normal (x, y, z) values as (r, g, b) color components.
  color = vec4(clamp(abs((gl_Normal + 1.0) * 0.5), 0.0, 1.0), 1.0);
 
  gl_Position = ftransform();
}
 
// Fragment Shader
varying vec4 color;
 
void main()
{
  gl_FragColor = color;
}