Shaders in Eve Online Páll Ragnar Pálsson

Similar documents
Dominic Filion, Senior Engineer Blizzard Entertainment. Rob McNaughton, Lead Technical Artist Blizzard Entertainment

Applications of Explicit Early-Z Z Culling. Jason Mitchell ATI Research

Lab 3 Shadow Mapping. Giuseppe Maggiore

Drawing a Crowd. David Gosselin Pedro V. Sander Jason L. Mitchell. 3D Application Research Group ATI Research

Deferred Rendering Due: Wednesday November 15 at 10pm

GUERRILLA DEVELOP CONFERENCE JULY 07 BRIGHTON

Game Graphics Programmers

Shaders (some slides taken from David M. course)

Game Architecture. 2/19/16: Rasterization

Ultimate Graphics Performance for DirectX 10 Hardware

Enhancing Traditional Rasterization Graphics with Ray Tracing. March 2015

Rendering Algorithms: Real-time indirect illumination. Spring 2010 Matthias Zwicker

Technical Report. Mesh Instancing

Could you make the XNA functions yourself?

Graphics Hardware. Instructor Stephen J. Guy

Optimizing DirectX Graphics. Richard Huddy European Developer Relations Manager

Shader Programming CgFX, OpenGL 2.0. Michael Haller 2003

Advanced Rendering & Shading

Render-To-Texture Caching. D. Sim Dietrich Jr.

1.2.3 The Graphics Hardware Pipeline

Evolution of GPUs Chris Seitz

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Fur Shader GRAPHICS PROGRAMMING 2

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

DirectX Programming #4. Kang, Seongtae Computer Graphics, 2009 Spring

CS451Real-time Rendering Pipeline

Rendering Objects. Need to transform all geometry then

Real-Time Hair Rendering on the GPU NVIDIA

Many rendering scenarios, such as battle scenes or urban environments, require rendering of large numbers of autonomous characters.

Bringing AAA graphics to mobile platforms. Niklas Smedberg Senior Engine Programmer, Epic Games

Rasterization Overview

Graphics Performance Optimisation. John Spitzer Director of European Developer Technology

Performance OpenGL Programming (for whatever reason)

A Trip Down The (2011) Rasterization Pipeline

The Application Stage. The Game Loop, Resource Management and Renderer Design

Input Nodes. Surface Input. Surface Input Nodal Motion Nodal Displacement Instance Generator Light Flocking

SAMPLING AND NOISE. Increasing the number of samples per pixel gives an anti-aliased image which better represents the actual scene.

Optimizing and Profiling Unity Games for Mobile Platforms. Angelo Theodorou Senior Software Engineer, MPG Gamelab 2014, 25 th -27 th June

Shader Series Primer: Fundamentals of the Programmable Pipeline in XNA Game Studio Express

Shadows in the graphics pipeline

Computergrafik. Matthias Zwicker. Herbst 2010

X. GPU Programming. Jacobs University Visualization and Computer Graphics Lab : Advanced Graphics - Chapter X 1

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Soft Particles. Tristan Lorach

MAXIS-mizing Darkspore*: A Case Study of Graphic Analysis and Optimizations in Maxis Deferred Renderer

Basics of GPU-Based Programming

COMP 4801 Final Year Project. Ray Tracing for Computer Graphics. Final Project Report FYP Runjing Liu. Advised by. Dr. L.Y.

Shadows & Decals: D3D10 techniques from Frostbite. Johan Andersson Daniel Johansson

Chapter 7 - Light, Materials, Appearance

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

How to Work on Next Gen Effects Now: Bridging DX10 and DX9. Guennadi Riguer ATI Technologies

Game Graphics Programmers

Low-Overhead Rendering with Direct3D. Evan Hart Principal Engineer - NVIDIA

Interactive Cloth Simulation. Matthias Wloka NVIDIA Corporation

The Vegetation of Horizon Zero Dawn. Gilbert Sanders Principal Artist, Guerrilla Games

Point based global illumination is now a standard tool for film quality renderers. Since it started out as a real time technique it is only natural

Game Graphics Programmers

Programming Graphics Hardware

Parallax Occlusion in Direct3D 11

Learn the fundamentals of shader writing in unity in this complete tutorial series.

CMSC427 Advanced shading getting global illumination by local methods. Credit: slides Prof. Zwicker

Shadow Techniques. Sim Dietrich NVIDIA Corporation

Models and Architectures

Introduction to Computer Graphics with WebGL

Computer Graphics. Shadows

Chapter 1 Introduction

Wed, October 12, 2011

Real - Time Rendering. Pipeline optimization. Michal Červeňanský Juraj Starinský

Building scalable 3D applications. Ville Miettinen Hybrid Graphics

Multi-View Soft Shadows. Louis Bavoil

Forward rendering. Unity 5's rendering paths. Which lights get what treatment?

Blis: Better Language for Image Stuff Project Proposal Programming Languages and Translators, Spring 2017

Computer Graphics (CS 543) Lecture 10: Soft Shadows (Maps and Volumes), Normal and Bump Mapping

DOOM 3 : The guts of a rendering engine

Lecture 9: Deferred Shading. Visual Computing Systems CMU , Fall 2013

Rendering 13 Deferred Shading

Enhancing Traditional Rasterization Graphics with Ray Tracing. October 2015

Optimizing for DirectX Graphics. Richard Huddy European Developer Relations Manager

Computer Graphics - Treasure Hunter

All the Polygons You Can Eat. Doug Rogers Developer Relations

Computer Graphics. Bing-Yu Chen National Taiwan University The University of Tokyo

CMSC427: Computer Graphics Lecture Notes Last update: November 21, 2014

Computer Graphics 10 - Shadows

Applications of Explicit Early-Z Culling

Real - Time Rendering. Graphics pipeline. Michal Červeňanský Juraj Starinský

Deus Ex is in the Details

Real-Time Universal Capture Facial Animation with GPU Skin Rendering

Abstract. 2 Description of the Effects Used. 1 Introduction Phong Illumination Bump Mapping

After the release of Maxwell in September last year, a number of press articles appeared that describe VXGI simply as a technology to improve

Shaders Part II. Traditional Rendering Pipeline

Me Again! Peter Chapman. if it s important / time-sensitive

Efficient and Scalable Shading for Many Lights

The Graphics Pipeline

CS 354R: Computer Game Technology

Projective Textures & Shadow Mapping. Prof. Aaron Lanterman School of Electrical and Computer Engineering Georgia Institute of Technology

Computer Graphics 1. Chapter 7 (June 17th, 2010, 2-4pm): Shading and rendering. LMU München Medieninformatik Andreas Butz Computergraphik 1 SS2010

More 3D - Overview. Alpha Blending (Transparency)

RASTERISED RENDERING

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

Sébastien Dominé, NVIDIA. CgFX

Transcription:

Shaders in Eve Online Páll Ragnar Pálsson

EVE Online

Eve Online Trinity First released 2003 Proprietary graphics engine DirectX 9 (DX11 on its way) Shader Model 3 (4 & 5 in development) HLSL

Turning this

Into this

HLSL code structure Matrices, Variables and Structures Vertex Shaders Pixel shaders Techniques Functions

HLSL code structure Matrices, Variables and Structures Vertex Shaders Pixel shaders Techniques Functions

Matrices, Variables and Structures //<variable name> : SEMANTIC FROM APP //world space float4x4 wmatrix : World; //World View Projection float4x4 wvpmatrix : WorldViewProjection; //contains camera position float4x4 vitmatrix : ViewInverseTranspose;

Matrices, Variables and Structures // --------------------------------------------------------- // Vertex shader input // --------------------------------------------------------- struct SimpleAppVtx { float3 pos : POSITION; float3 normal : NORMAL; float3 tangent : TANGENT; float3 bitangent : BINORMAL; float2 texcoord : TEXCOORD; };

Matrices, Variables and Structures // ------------------------------------------------------ // Vertex shader output / Pixel shader input // ------------------------------------------------------ struct SimpleShaderVtx { float4 posclip : POSITION; float2 texcoord0 : TEXCOORD0; };

Matrices, Variables and Structures struct StandardShaderVtx { float4 posclip : POSITION; float4 texcoord01 : TEXCOORD0; float3 normalworld : TEXCOORD1; float3 tangentworld : TEXCOORD2; float3 bitangentworld : TEXCOORD3; float4 eyedirworld : TEXCOORD4; // 4th component is the fogcoefficient (0 = full fog, 1 = no fog) float3 posworld : TEXCOORD5; #if SHADOW_ENABLED float4 posshadowview : TEXCOORD7; float4 posshadowviewprojection : TEXCOORD8; #endif };

Matrices, Variables and Structures struct BaseLightingParams { float3 normalworld; float diffuse; float specularmaskedbrightness; float speculardot; float3 pointlights; float3 reflectdir; };

Matrices, Variables and Structures

HLSL code structure Matrices, Variables and Structures Vertex Shaders Pixel shaders Functions Techniques

Vertex Shaders StandardShaderVtx StandardVS( StandardAppVtx invtx, float4x4 world ) { StandardShaderVtx outvtx = (StandardShaderVtx)0; } // position float4 posworld = mul( float4( invtx.pos, 1.0f ), world ); outvtx.posclip = mul( posworld, PerFrameVS.ViewProjectionMat ); // texcoord outvtx.texcoord01 = invtx.tex.xyyy; float4x4 worldinversetranspose = PerObjectVS.WorldInverseTransposeMat; outvtx.normalworld = mul( invtx.normal, worldinversetranspose ); outvtx.tangentworld = mul( invtx.tangent, worldinversetranspose ); outvtx.bitangentworld = mul( invtx.bitangent, worldinversetranspose ); float3 eyeposworld = ExtractEyePosFromViewMatrix( PerFrameVS.ViewInverseTransposeMat ); float3 pos2eye = eyeposworld - posworld.xyz; float4 eyedirworld; outvtx.eyedirworld = float4( normalize( pos2eye ), 0.0f ); outvtx.posworld = posworld; ProjectPositionToShadow( posworld, outvtx.posshadowview, outvtx.posshadowviewprojection ); return outvtx;

HLSL code structure Matrices, Variables and Structures Vertex Shaders Pixel shaders Functions Techniques

Pixel Shaders float4 SinglePS( StandardShaderVtx invtx ) : COLOR { BaseLightingParams params = CalcBaseLightingParams( invtx ); float4 diffusemap = tex2d( DiffuseMapSampler, invtx.texcoord01.xy ); return ColorWithFog( invtx, CalcBaseLighting( params, diffusemap, MaterialDiffuseColor, MaterialAmbientFactor, MaterialSpecularFactors, MaterialSpecularCurve ) ); }

HLSL code structure Matrices, Variables and Structures Vertex Shaders Pixel shaders Functions Techniques

Functions struct BaseLightingParams { BaseLightingParams CalcBaseLightingParams( StandardShaderVtx invtx ) float3 normalworld; { float diffuse; float specularmaskedbrightness; BaseLightingParams ret; float speculardot; ret.normalworld = CalcNormalFromMap( invtx ); float3 pointlights; ret.pointlights = CalcPointLightsColor( invtx.posworld, invtx.normalworld ); float3 reflectdir; float2 brightness = CalcBrightnessFromShadowMap( invtx ); }; // diffuse ret.diffuse = saturate( 2.0f * dot( ret.normalworld, PerFramePS.Sun.DirWorld ) 0.2f ); ret.diffuse *= brightness.x; // specular float3 halfdirworld = normalize( PerFramePS.Sun.DirWorld + invtx.eyedirworld.xyz ); ret.speculardot = saturate( dot( ret.normalworld, halfdirworld ) ); float specularmask = GetSpecularStrengthFromMap( invtx.texcoord01.xy ); ret.specularmaskedbrightness = specularmask * brightness.x; // reflection (Need to negate the reflect function since it is implemented all backwards!) float3 reflectdirworld = reflect( invtx.eyedirworld, ret.normalworld ); ret.reflectdir = mul( float4( reflectdirworld, 1.0 ), ReflectionMapTransform ); return ret; }

HLSL code structure Matrices, Variables and Structures Vertex Shaders Pixel shaders Functions Techniques

Techniques technique Main { pass P0 { // We can put device state changes here, // But we try not to do them per-shader // Explained later in the talk. } VertexShader = COMPILE_VS( StandardStaticVS ); PixelShader = COMPILE_PS( SinglePS ); } pass P1...

Textures

Diffuse

Specular map

Normal map

Object normals, tangents and bitangents

Wire frame

Shadow map

Shadows shadow maps For each object receiving shadows Create a frustum from the bounding info of the object Use this frustum to gather list of objects casting shadows on this object Render the shadow casters using the frustum In Eve the sun is always assumed to be far away so we use orthogonal projection matrix We override the pixel shader, but keep the vertex shader intact Only store the depth, discard the color info End up with one shadow map per receiver

Shadows continued During rendering We project the pixel position into the light s coordinate space using the light s view and projection transforms The depth in the camera s frustum is the z value of the projected position The x and y values are used to calculate the UVs needed to look up into the shadow map rendered earlier. If the projected value is closer to the light than the value read from the texture the pixel in question is not behind a shadow caster, and is fully lit.

Trinity graphics engine Batches Sending triangles to the GPU is fairly slow A batch is a group of triangles that you can render with one draw call We want to have few draw calls We want to have few device state changes Trinity uses areas for this purpose Each object in the scene has a list of different area lists The most commonly used are opaque, decal, transparent and additive

Trinity graphics engine Areas During rendering we gather the batches from each area type and render together We only change render states between batches Opaque batches are not sorted Should they be? Transparent batches are sorted and rendered back to front Additive areas are not sorted

Not just ships

Not Just ships

Not just ships

Not just ships

But sometimes A LOT OF SHIPS

But sometimes A LOT OF SHIPS

Depth effects God rays

God rays Render depth to a texture Render a quad centered on the sun In the pixel shader: Use VPOS to get screen UV Walk form this screen position to the center of the quad For each step, sample the depth map, with random jitter and compare the value to a threshold Accumulate all Hits and find the occlusion ratio Subtract the occlusion from the texture of the quad (a faint glow)

God rays for (int i = 0; i < numsamples; ++i) { float ratio = (float)i / (float)numsamples; float2 uv = lerp( screentextureuv, spritecenterscreen, ratio + noise); depth = GetDepthFromMirroredTexture( uv ); occlusion += step(thresholddepth, depth); } texcolor = saturate( texcolor - float4(occlusion.xxx, 0.0 ) );

Physical not always best We make games, not simulations Art director has the final say Artists want control If a cheap hack delivers almost the same results, then by all means hack away.

Best practices General Performance Tips Clear only when you must. Minimize state changes and group the remaining state changes. Use smaller textures, if you can do so. Draw objects in your scene from front to back. Use triangle strips instead of lists and fans. For optimal vertex cache performance, arrange strips to reuse triangle vertices sooner, rather than later. Gracefully degrade special effects that require a disproportionate share of system resources.

Best practices General Performance Tips Constantly test your application's performance. Minimize vertex buffer switches. Use static vertex buffers where possible. Choose texture formats wisely. Draw using indexed primitives. This can allow for more efficient vertex caching within hardware. If the depth buffer format contains a stencil channel, always clear the depth and stencil channels at the same time.

Questions www.eveonline.com pallragnar@ccpgames.com