CS148: Prologue to PC Design and Imaging Programmable Shaders.

Uploaded on:
CS148: Prologue to PC Design and Imaging Programmable Shaders Points The Illustrations Pipeline Settled capacity Programmable Programming Model Vertex, Geometry, Pixel Shaders Parallelism Usage GLSL Punctuation Constraints GPGPU The Representation Pipeline
Slide 1

CS148: Introduction to Computer Graphics and Imaging Programmable Shaders

Slide 2

Topics The Graphics Pipeline Fixed-capacity Programmable Programming Model Vertex, Geometry, Pixel Shaders Parallelism Implementation GLSL Syntax Limitations GPGPU

Slide 3

The Graphics Pipeline

Slide 4

Geometry Rendering Stages Vertex Data Tessellation Vertex Processing Pixel Processing Geometry Processing Pixel Rendering Primitive Data Texture Sampler Textured Surface

Slide 5

Rasterization Input: Vertices & values (ex. shading, surface) Output: Pixels & interjected qualities

Slide 6

Fixed Function Pipeline Math OpenGL glLightfv(GL_LIGHT0, GL_DIFFUSE, P); glLightfv(GL_LIGHT0, GL_POSITION, C); glEnable(GL_LIGHT0); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_BLEND); ?

Slide 7

Programmable Rendering Code Vector4 RenderPixel( Vector3 Position, Vector3 Normal) { ... return Vector4(0, 0, 1, 0); }

Slide 8

Limitations Mutable Pixels Geometry Vertices Immutable Clipping Triangle scanlines

Slide 9

Direct3D 10 pipeline Traditional design pipeline Three application-programmable stages work on autonomous vertex, primitive, and pixel parts All stages have the same programming model and can inquiry the same assets Vertices Input Assembler Textures Sampler Vertex Shader Constants Textures Sampler Geometry Shader Constants CPU or GPU Memory Rasterizer Textures Sampler Pixel Shader Constants Application Programmable Target Surface Output Merger

Slide 10

Programming Model

Slide 11

CPU versus GPU programming

Slide 12

Vertex Shader Inputs Program-gave vertex information glVertex3d(1.0, 2.0, 3.0); glNormal3d(1.0, 0.0, 0.0); Constants Textures Outputs Position Array of buoys utilized by future pipeline stages Structure decided altogether by software engineer

Slide 13

Example Vertex Shader Vertex Shader

Slide 14

Geometry Shader Inputs Geometric primitive (point, line, triangle, quad) Adjacent vertex data (AV0, AV1, AV2) Outputs More geometric primitives

Slide 15

Pixel Shader Inputs Array of buoys from vertex/geometry shader Constants Textures Outputs 4-channel shading Depth

Slide 16

Example Pixel Shader Pixel Shader

Slide 17


Slide 18

Simple Vertex Shader void primary() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex ; } gl_Position = yield of vertex shader gl_Vertex = glVertex3d(x, y, z); or STShape ::… gl_ModelViewProjectionMatrix = glLoadMatrixd (M); or STTransform ::…

Slide 19

Variables Local Variables { vec2 SomeVector = vec2 ( sin (2.0), sqrt (3.0)); float SomeFloat = SomeVector.x * SomeVector.y ; } “Varying” Variables Varyings are yield by the vertex shader and interjected over every primitive for the pixel shader fluctuating vec2 TextureCoord0; void principle() { TextureCoord0 = vec2 ( gl_Position.x , 2.0); }

Slide 20

Variables Uniform Variables Uniforms are variables set by the project that can be changed at runtime, however are consistent over every execution of the shader uniform buoy CurrentTime ; void fundamental() { coast Displacement = cos ( CurrentTime * 10); } C++ code to change this quality may resemble: STVertexShader Shader; Shader.SetUniformVariable (“ CurrentTime ”, ElapsedTimeInSeconds );

Slide 21

Textures are mapped from (0, 0) to (1, 1) Only moderately late cards bolster vertex shader surfaces, all bolster pixel shader compositions uniform sampler2D SomeTexture ; void principle() { vec4 SomeTextureColor = texture2D ( SomeTexture , vec2 (0.5, 0.5)); }

Slide 22

Vectors Constructors vec3 V3 = vec3 (1.0, 2.0, 3.0); vec4 V4 = vec4 (V3, 4.0); Swizzling vec2 V2 = V4.xy; vec4 V4Reverse = V4.wzyx; vec4 Result = V4.xyzw + V4.xxxx; Basic Vector Operators buoy Result = dab (V4, V4Reverse); vec3 Result = cross (V3, vec3 (1.0, 0.0, 0.0));

Slide 23

Simple Pixel Shader shifting vec2 TexCoord0; differing vec2 TexCoord1; uniform sampler2D SomeTexture0; uniform sampler2D SomeTexture1; void fundamental() { gl_FragColor = texture2D ( SomeTexture0, TexCoord0) * 0.5 + texture2D ( SomeTexture1, TexCoord1) * 0.5; } gl_FragColor = yield of pixel shader

Slide 24

Functions Very like C: bool Compare( in vec3 an, in vec3 b) { return spot (an, a) > speck (b, b); }

Slide 25

Limitations Memory No entrance to close-by pixels Cannot tie render focus as info composition Limited stack space, guideline check Performance Branching backing is restricted and moderate Graphics card will timeout if code takes too long Variable backing crosswise over distinctive representation cards Programmable code is much slower than devoted equipment

Slide 26

Practical Shading: The Bloom Effect Images from Gamasutra.com & Tron 2.0

Slide 27

Practical Shading: Bump-mapping A small amount of the expense of expanding the beginning number of polygons or utilizing the geometry shader

Slide 28


Slide 29

Parallelism CPU Thread synchronization Bandwidth impediments Scheduling overhead Small number of centers GPU All strings autonomous Message passing is not permitted Resource designation is finished by GPU Many centers accessible (12 to 48 run of the mill)

Slide 30

Ideal GPU Problems GPU’s are extraordinary if the issue: Executes the same code commonly on diverse info Needs bunches of math units in the meantime Does not share information between executing segments Can be communicated as a succession of operations following up on a surge of information Large information sets Has loads of work to manage without CPU mediation

Slide 31

General Purpose GPU’s Beyond triangle rendering Collision identification Fluid reproduction Physics Raytracing Video pressure Beyond illustrations Folding@Home Speech Recognition Partial differential mathematical statement solvers Fourier change

Slide 32

Object Reconstruction from Images Massive non-straight improvement issue Output: Geometry of shot item Input: 200 640x480 pictures (~250MB) .:t

View more...