Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 4 Lecture 1: OpenGL 3.x & 4.x. 2 Objectives Changes in OpenGL 3.x 4.x Changes in GLSL 1.3/4/5 4.x.

Similar presentations


Presentation on theme: "Week 4 Lecture 1: OpenGL 3.x & 4.x. 2 Objectives Changes in OpenGL 3.x 4.x Changes in GLSL 1.3/4/5 4.x."— Presentation transcript:

1 Week 4 Lecture 1: OpenGL 3.x & 4.x

2 2 Objectives Changes in OpenGL 3.x 4.x Changes in GLSL 1.3/4/5 4.x

3 3 Fixed Function / Immediate Mode OpenGL 3.x deprecated stuff includes: ­immediate mode (Begin/End etc) ­Vertex specification ­Vertex Arrays ­Matrices ­Texture Coordinates ­Lighting ­All fixed-function options ­pixel formats with colour palettes

4 4 I Need My Immediate Mode! Why have they done this? Shaders! Shader performance is so much better that immediate mode is no longer competative. Direct X Direct X was outperforming OpenGL since Direct X 10 Hardware New Graphics cards were reducing fixed functionality support in order to focus on gpu.

5 5 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 No, Really, I want immediate mode. Ok, immediate mode is still available if you include OpenGL’s compatibility profile. A core profile and a compatibility profile exist… int attribs[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, major, WGL_CONTEXT_MINOR_VERSION_ARB, minor, WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, 0 }; PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = NULL; wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress("wglCreateContextAttribsARB"); if(wglCreateContextAttribsARB != NULL) { m_hrc = wglCreateContextAttribsARB(pDC->m_hDC,0, attribs); }

6 6 Shaders OpenGL 3.x Shader Versions 1.40 and 1.50 Geometry Shader OpenGL 4.x Shader Version 4.x Tessolation Shaders Control shader Primitive Generator Evaluation shader

7 7 Vertex Shader Frame Buffer Fragment Shader CPU vertices fragments Rasterizer fragments OpenGL 2.x Shaders

8 8 Vertex Shader Frame Buffer Fragment Shader CPU Rasterizer OpenGL 3.x Shaders Geometry Shader vertices primitives fragments

9 9 Vertex Shader Frame Buffer Fragment Shader CPU Rasterizer OpenGL 4.x Shaders Geometry Shader vertices primitives fragments Primitive generator Control Shader Evaluation shader Optional Tessellation Shaders

10 10 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Geometry Shaders Take vertices (of a primitive) Output Primitives (triangle strip, points, line) Can create new vertices, unlike vertex shaders, which are limited to a 1:1 input to output ratio. Layered rendering; this means that the GS can specifically say that a primitive is to be rendered to a particular layer of the framebuffer.

11 11 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Geometry Shaders #version 150 layout(triangles) in; layout(triangle_strip, max_vertices = 3) out; void main() { for(int i = 0; i < gl_in.length(); i++) { gl_Position = gl_in[i].gl_Position; EmitVertex(); } EndPrimitive(); }

12 12 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Uniform Buffer Objects Allow blocks of data to be transferred as a single variable to shader. Need a layout parameter to define memory layout. uniform BlockName { vec3 blockMember1, blockMember2; float blockMember3; } glslBlockName;

13 13 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Example (Projection/Model Matrix now need to be manually passed) #version 140 uniform Transformation { mat4 projection_matrix; mat4 modelview_matrix; }; in vec3 vertex; void main() { gl_Position = projection_matrix * modelview_matrix * vec4(vertex, 1.0); }

14 14 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Layout Defines memory structure of passed variables. For UBO it can be std140, packed, or shared. Packed or Shared needs the byte offset to access, std140 is more user friendly but may not be optimal. Layout can be set for other compound memory, e.g. row_major or colomn_major for matrices, triangles for vertex arrays etc.

15 15 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Tessellation Control Processor Programmable unit that operates on a patch of incoming vertices and their associated data, emitting a new output patch. Invoked for each vertex of the output patch. Each invocation can read the attributes of any vertex in the input or output patches, but can only write per- vertex attributes for the corresponding output patch vertex. As many shaders can run, the built-in function barrier() can be used to control execution order by synchronizing invocations, dividing tessellation control shader execution into a set of phases.

16 16 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Tessellation Evaluation Processor Evaluates the position and other attributes of a vertex generated by the tessellation primitive generator, using a patch of incoming vertices and their associated data. computes the position and attributes of a single vertex generated by the tessellation primitive generator. Reads the attributes of any vertex in the input patch, plus the tessellation coordinate, which is the relative location of the vertex in the primitive being tessellated. The executable writes the position and other attributes of the vertex.

17 17 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 What variables do we get for free? Vertex: in int gl_VertexID; in int gl_InstanceID; out gl_PerVertex { vec4 gl_Position; float gl_PointSize; float gl_ClipDistance[]; }; + Compatability Profile: in vec4 gl_Color; in vec4 gl_SecondaryColor; in vec3 gl_Normal; in vec4 gl_Vertex; in vec4 gl_MultiTexCoord0; in vec4 gl_MultiTexCoord1; in vec4 gl_MultiTexCoord2; in vec4 gl_MultiTexCoord3; in vec4 gl_MultiTexCoord4; in vec4 gl_MultiTexCoord5; in vec4 gl_MultiTexCoord6; in vec4 gl_MultiTexCoord7; in float gl_FogCoord;

18 18 What variables do we get for free? Geometry: in gl_PerVertex { vec4 gl_Position; float gl_PointSize; float gl_ClipDistance[]; } gl_in[]; in int gl_PrimitiveIDIn; in int gl_InvocationID; out gl_PerVertex { vec4 gl_Position; float gl_PointSize; float gl_ClipDistance[]; }; out int gl_PrimitiveID; out int gl_Layer;

19 19 What variables do we get for free? Tessellation control language: in gl_PerVertex { vec4 gl_Position; float gl_PointSize; float gl_ClipDistance[]; } gl_in[gl_MaxPatchVertices]; in int gl_PatchVerticesIn; in int gl_PrimitiveID; in int gl_InvocationID; out gl_PerVertex { vec4 gl_Position; float gl_PointSize; float gl_ClipDistance[]; } gl_out[]; patch out float gl_TessLevelOuter[4]; patch out float gl_TessLevelInner[2];

20 20 What variables do we get for free? tessellation evaluation language: in gl_PerVertex { vec4 gl_Position; float gl_PointSize; float gl_ClipDistance[]; } gl_in[gl_MaxPatchVertices]; in int gl_PatchVerticesIn; in int gl_PrimitiveID; in vec3 gl_TessCoord; patch in float gl_TessLevelOuter[4]; patch in float gl_TessLevelInner[2]; out gl_PerVertex { vec4 gl_Position; float gl_PointSize; float gl_ClipDistance[]; };

21 21 What variables do we get for free? Fragment: in vec4 gl_FragCoord; in bool gl_FrontFacing; in float gl_ClipDistance[]; in vec2 gl_PointCoord; in int gl_PrimitiveID; in int gl_SampleID; in vec2 gl_SamplePosition; out vec4 gl_FragColor; // deprecated out vec4 gl_FragData[gl_MaxDrawBuffers]; // deprecated out float gl_FragDepth; out int gl_SampleMask[];

22 22 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Compatibility Profile State uniform mat4 gl_ModelViewMatrix; uniform mat4 gl_ProjectionMatrix; uniform mat4 gl_ModelViewProjectionMatrix; uniform mat4 gl_TextureMatrix[gl_MaxTextureCoords]; uniform mat3 gl_NormalMatrix; uniform mat4 gl_ModelViewMatrixInverse; uniform mat4 gl_ProjectionMatrixInverse; uniform mat4 gl_ModelViewProjectionMatrixInverse; uniform mat4 gl_TextureMatrixInverse[gl_MaxTextureCoords]; uniform mat4 gl_ModelViewMatrixTranspose; uniform mat4 gl_ProjectionMatrixTranspose; uniform mat4 gl_ModelViewProjectionMatrixTranspose; uniform mat4 gl_TextureMatrixTranspose[gl_MaxTextureCoords]; uniform mat4 gl_ModelViewMatrixInverseTranspose; uniform mat4 gl_ProjectionMatrixInverseTranspose; uniform mat4 gl_ModelViewProjectionMatrixInverseTranspose; uniform mat4 gl_TextureMatrixInverseTranspose[gl_MaxTextureCoords]; uniform float gl_NormalScale; uniform vec4 gl_ClipPlane[gl_MaxClipPlanes];

23 23 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Compatibility Profile State struct gl_PointParameters { float size; float sizeMin; float sizeMax; float fadeThresholdSize; float distanceConstantAttenuation; float distanceLinearAttenuation; float distanceQuadraticAttenuation; }; struct gl_MaterialParameters { vec4 emission; // Ecm vec4 ambient; // Acm vec4 diffuse; // Dcm vec4 specular; // Scm float shininess; // Srm }; uniform gl_MaterialParameters gl_FrontMaterial; uniform gl_MaterialParameters gl_BackMaterial;


Download ppt "Week 4 Lecture 1: OpenGL 3.x & 4.x. 2 Objectives Changes in OpenGL 3.x 4.x Changes in GLSL 1.3/4/5 4.x."

Similar presentations


Ads by Google