36

OpenGL ES 2.0: Shaders Go Mobile - AMD Developer Central · PDF fileAPI of choice for 3D handheld games OpenGL ES 2.0 is the path forward for 3D Lean and clean Allows for vendor-specific

Embed Size (px)

Citation preview

OpenGL ES 2.0:Shaders Go Mobile

Presented byDan Ginsburg, Staff Engineer

Agenda

� OpenGL ES

� Overview and History

� OpenGL ES 2.0

� Shaders Overview

� What’s changed in GLSL?

� What’s changed from OpenGL 2.0?

� Writing OpenGL ES 2.0 Games

OpenGL ES:Overview and History

What is OpenGL ES?

� OpenGL-based API for embedded systems

� Removed redundant and expensive functionality

� Kept as compatible with OpenGL as possible

� Added features needed for embedded systems

Who created OpenGL ES?

Over 100 companies creating media authoring and acceleration standards

Why is OpenGL ES important?

� API of choice for 3D handheld games

� OpenGL ES 2.0 is the path forward for

3D

� Lean and clean

� Allows for vendor-specific extensibility

� Simplified driver implementation

OpenGL ES History

� OpenGL ES 1.0

� Basic 3D functionality

� OpenGL ES 1.1+

� Comprehensive set of fixed-function 3D

� Backwards compatible

� OpenGL ES 2.0

� Shader only

� Not backwards compatible

OpenGL ES 2.0:Shaders Overview

OpenGL ES 2.0 Overview

� ES GLSL forms core of API

� Shifts some burden to application

� But puts more power in your hands

� Convergence of desktop and handheld!

OpenGL ES Pipeline

APIAPI

VertexShader

VertexShader RasterizerRasterizerPrimitive

Assembly

PrimitiveAssembly

FragmentShader

FragmentShader

DepthStencil

DepthStencilAlpha

Test

AlphaTest DitherDitherColour

BufferBlend

ColourBufferBlend

VertexBuffer

Objects

VertexBuffer

Objects

Vertices

Triangles/Lines/Points

PrimitiveProcessing

PrimitiveProcessing

Frame BufferFrame Buffer

TextureEnvironment

TextureEnvironment Colour

Sum

ColourSum FogFogTexture

Environment

TextureEnvironment Colour

Sum

ColourSum FogFog

Fragment shaders replace Fixed Function Texture, Color and Fog

Transformand

Lighting

Transformand

Lighting

Vertex shaders replace Fixed Function Transform and Lighting

OpenGL ES 2.0 – Vertex Shader

UniformsUniforms TexturesTextures

Attribute 0Attribute 0

Attribute 1Attribute 1

Attribute 2Attribute 2

Attribute 3Attribute 3

Attribute 4Attribute 4

Attribute 5Attribute 5

Attribute 6Attribute 6

Attribute 7Attribute 7

Varying 0Varying 0

Varying 1Varying 1

Varying 2Varying 2

Varying 3Varying 3

Varying 4Varying 4

Varying 5Varying 5

Varying 6Varying 6

Varying 7Varying 7

gl_Positiongl_Position

gl_FrontFacinggl_PointSize

Vertex ShaderVertex Shader

OpenGL ES 2.0 – Example Vertex Shader

attribute vec4 Vertex;

attribute vec2 VertexSt;

uniform mat4 Transform;

varying vec2 TexCoord;

invariant gl_Position;

void main()

{

gl_Position = Transform * Vertex;

TexCoord = VertexSt;

}

OpenGL ES 2.0 – Fragment Shader

UniformsUniforms TexturesTextures

gl_FragColorgl_FragColorFragment ShaderFragment Shader

Varying 0Varying 0

Varying 1Varying 1

Varying 2Varying 2

Varying 3Varying 3

Varying 4Varying 4

Varying 5Varying 5

Varying 6Varying 6

Varying 7Varying 7

gl_FrontFacinggl_FrontFacing

gl_Positiongl_FragCoord

gl_PointCoord

OpenGL ES 2.0 – Example Fragment Shader

uniform sampler2D Sampler;

varying vec2 TexCoord;

void main()

{

vec4 color = texture2D(Sampler, TexCoord);

color *= 0.5;

gl_FragColor = color;

}

OpenGL ES 2.0:What’s changed in GLSL?

OpenGL ES 2.0 – GLSL Changes

� Binary Shaders

� Allows for off-line shader compiler

� Vendor-specific opaque format

� Optional: on-line vs. off-line compiler

� Removed multiple vertex / fragment

shaders

� Load a binary shader pair

OpenGL ES 2.0 – GLSL Changes(continued)

� All built-in attribute variables removed

� gl_Vertex, gl_Normal, etc.

� Generic vertex attributes only

� All built-in varying variables removed

� One new varying: gl_PointSize

� Most built-in uniform variables removed

� Shifts burden to application

� Removed 1D and Shadow texture functions

� noise(), dFdx(), dFdy() optional

� ftransform() is removed

� Replaced with invariance qualifier

OpenGL ES 2.0 – GLSL Changes(continued)

� Precision qualifiers added

� Low, medium, high

� Vertex shader default: high float

� Fragment shader default: none

� Fewer attributes (8) and uniforms (384)

� User-clipping removed

OpenGL ES 2.0 – GLSL Changes(continued)

OpenGL ES 2.0:What’s changed from OpenGL 2.0?

OpenGL ES 2.0 – What’s new?

� Vertex and attribute data formats

� Fixed (16.16)

� Half float (optional)

� Compressed texture formats

� Ericsson Texture Compression (ETC)

� Floating-point textures

� 16-bit and 32-bit

OpenGL ES 2.0 – What’s new? (continued)

� Framebuffer Objects

� Simplified version of EXT_framebuffer_object

� Shader precision query

� glGetShaderPrecisionFormatOES

� Binary shaders

� glShaderBinaryOES

OpenGL ES 2.0 – What’s Gone?

� Enable/Disable(MULTISAMPLE)

� Anti-aliased lines

� Points and anti-aliased points

� Only point sprites supported

� Coordinate transforms & matrix stack

� Occlusion queries

OpenGL ES 2.0 – What’s Optional?

� MapBuffer/UnmapBuffer

� 3D textures

� Non-power of 2 textures

� FP16 vertex attribute data

� FP16 and FP32 textures

OpenGL ES 2.0:Writing OpenGL ES 2.0 Games

Fixed-Function is Gone

� Your game engine must now manage:

� Matrices: modelview, projection, etc.

� Setup of frustum projection

� Storage of constants:

� Light properties

� Fog properties

� Etc.

Managing constants

� One option: implement a fixed-function

wrapper

� Another option: create a custom solution

� This is what ATI does in our new demo engine

� Other APIs such as D3D10 are removing fixed-function too

Lighting

� All lighting computations and properties

must be shader-based

� Implement the GL or custom lighting

equations

� Great place to start:� 3DLabs ShaderGen – shows you how to generate

GLSL shaders from any fixed-function state!

� developer.3dlabs.com/downloads/shadergen/

Effect file formats

� Need a file format with more than just shaders� Render state

� Material properties

� Techniques and render passes

� Constant bindings

� Vertex attribute bindings

� Texture information

Effect File Solutions

� COLLADA FX

� Extensible file format supporting multiple

APIs

� Custom solution

� ATI demo team developed its own effect file

format

� Similar to D3D .FX, but cross-API friendly

Developing shaders

� Use the tools that are out there:

� RenderMonkey provides GLSL support

� OpenGL ES 2.0 support is planned

� Various other shader tools available

Summary

� OpenGL ES overview and history

� OpenGL ES 2.0 technical details

� How to develop OpenGL ES 2.0 games

Conclusions

� Convergence of desktop and handheld

� Design shaders into your engine

� Implement fixed-functionality you need

� Leverage existing solutions

Where to get more info

� www.khronos.org

� OpenGL ES 2.0 and ES Shading Language

specs

� Extensive library of presentations

� The latest OpenGL ES news

Questions?