rendermonkey™ - amddeveloper.amd.com/wordpress/media/2012/10/rendermonkey.pdf · • render state...

73
RenderMonkey™ Drew Card Jason L. Mitchell ATI Research

Upload: others

Post on 21-Sep-2020

24 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

RenderMonkey™Drew CardJason L. Mitchell

ATI Research

Page 2: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Outline

• What is RenderMonkey™?– Tool Suite– RenderMonkey IDE

• Example Shaders– Rusty Metal– Ocean Water– Two-tone layered car paint model– Gooch– Atmospheric scattering– Procedural Wood

• Conclusion

Page 3: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Motivation

• What problems are we trying to solve?• Aid in shader adoption in applications

– Shaders are too hard– Make our features more approachable– We are not pitching a particular language

• Create an environment that is language agnostic allowing any high level shading language to be supported via plug-ins

Page 4: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Tool Suite

• RenderMonkey™ IDE– RenderMan compiler– DirectX® 8 low level assembly support– DirectX® 9 High Level Shading Language (HLSL)

support– OpenGL

• Completely built of plug-ins– Plug-in source code available– Write your own to handle your own specific data

formats• Importer• Exporter• Editor• Viewer

Page 5: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

RenderMonkey™ IDE Workspace

• Workspace– Effect Group

• Effect– Pass

• Render State• Pixel Shader• Vertex Shader• Geometry• Textures

Page 6: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Effect Groups

• Group related effects• Mechanism for dealing with a lot of effects• Facilitate fallback versions of same effect

– Good for fallbacks to support wide range of hardware

Page 7: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Effects

• Encompasses all information needed to implement a real time visual effect

• Composed of multiple passes (draw calls)• Inherit from a Default Effect

– Used to set a known starting state for all effects

Page 8: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Pass

• Shaders• Render State

– State inherits from pass to pass• Textures• Geometry

– Can even use different geometry on different passes• Fur

Page 9: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Data Scope and Traversal

• Default Shader– Common things for your engine are set up in the

default shader– Used as a known starting point for all effects

• Effects don’t inherit from effects– Stream map

• Data validation occurs upward through passes in the effect then upward through passes in the default effect

• Variable scope is similar to C-style variable scope

Page 10: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Variables

• Parameters to your shaders• Can be bound to shader constants• Anything your engine will allocate at run time

– Matrices– Vectors– Colors– Scalars– Textures

• 2D, 3D and Cube Maps

– Strings

Page 11: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

XML

• We want to describe every bit of information needed to recreate an effect

• Universal standard– User-extensible– Parsers are available

Page 12: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

RenderMonkey™ IDE Plug-Ins

• Entire RenderMonkey™ IDE is built from plug-ins• Sample Code available with the

RenderMonkey™ SDK– Exporter– Importer– Editor– Viewer

Page 13: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Viewer Plug-in

• DirectX 8.1• HAL / REF• Pass Preview• Trackball navigation

Page 14: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Editor Plug-in

• Tabbed view allows editing multiple passes

• Constant storage in the top portion

• Shader code in the bottom portion

Page 15: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Custom Plug-ins

• Example of a custom editor

• Color Editor• Position Editor• Direction Editor

Page 16: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Importer Plug-ins

• Allows support for any input shading language– Industry Standard

– RenderMan– DirectX®– OpenGL – Maya

– ISV Specific– EAGL– Quake 3

Page 17: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

RenderMonkey Compiler

• Radeon 9700 is the first GPU in the industry to fully support true floating point computation of coordinates and color components.

• Four component, true floating point pixel format in the frame buffer.

• Multiple rendering targets facilitating seamless dissect of a complex shading representation into segments, each fitting GPU shading resources available – all in the context of multi-pass rendering.

Page 18: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Workflow

•Input is a shading description in the form of either a language or a data structure.

• Shading description compiled and processed to yield formals and GPU shader streams (e.g. vertex and pixel) back to the application.

• Formals provide shading run time control and resource binding data.

• Multiple sets of formals and shading streams, each to be applied to one rendering pass in a sequence.

• Application commences rendering and attaches GPU shader streams to geometry.

Page 19: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Application to GPU Shading Path

Application Shading Description

(e.g .sl, material, node attribute)

Application

RenderMonkey CompilerTools

DriverRuntime, Assembly

GPU

Page 20: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

RenderMonkey Compiler PipelineApplicationshader formals languageGPU shader streams data structure

Scanner/Parser

meta

Segmentor

Simplifier Ashli

intermediate code

Optimizer

DX GL

Target Code Generator

vertex & pixel shader streams

Page 21: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Metal Radeon Logo

Page 22: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Ocean Water

Page 23: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Gooch Shading

Page 24: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Gooch Shading

•Motivated by techniques used by illustrators•Useful for Mechanical CAD rendering

•Shows surface shape without obscuring outlines or specular highlights

•Compute N•L then scale and bias into the range 0-1

•Eliminates clamping at zero that causes the unlit side of the object to be completely black

•Input color is scaled by a cool to warm color ramp •The result is a shading model that never gets too dark or too bright while still conveying the surface’s shape

Page 25: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Toon Shading

Page 26: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Hatching

Page 27: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Tonal Art Map

• Weighted sum of these channels determines final tone

Page 28: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Basic Hatchingps.1.4texld r0, t0 ; sample the 1st three channels of the TAMtexld r1, t0 ; sample the 2nd three channels of the TAMtexcrd r2.rgb, t1.xyz ; get the 123 TAM weights and place in r2texcrd r3.rgb, t2.xyz ; get the 456 TAM weights and place in r3dp3_sat r0, 1-r0, r2 ; dot 123 TAM values with 123 TAM weightsdp3_sat r1, 1-r1, r3 ; dot 456 TAM values with 456 TAM weightsadd_sat r0, r0, r1 ; add reg 0 and reg1mov_sat r0, 1-r0 ; complement and saturate

Page 29: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Two-Tone Car Paint (RenderMonkey)

Page 30: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Two-tone Car Paint

Page 31: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Layers of Car Paint

Page 32: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Two-tone Car Paint

• Normal Decompression• Sparkle from microflake• Base color• Clear coat• Rough Specular

Page 33: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Normal Decompression

• Sample from two-channel 16-16 normal map• Derive z from sqrt (1 – x2 – y2)

Page 34: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Ns and Nss

• Two normal maps on car– Normal from appearance preserving

simplification process, N– High frequency normalized vector noise,

Nn

• Compute Ns and Nss from N and Nn

– Ns = (aNn + bN) / |aNn + bN| , where a << b– Nss = (cNn + dN) / |cNn + dN| , where c = d

Page 35: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Base Color and Flake

• Base color and flake effect are derived from Ns and Nss using the following polynomial

c0(Ns·V) + c1(Ns·V)2 + c2(Ns·V)4 + c3(Nss·V)16

Base Color Flake

Page 36: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Layers of Car Paint

Base Colorc0(Ns·V) + c1(Ns·V)2 + c2(Ns·V)4

Flake(Nss·V)16

HDR Clear Coat Final Color

Page 37: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

RGBScale HDR Environment Map

Ceiling of car showroom

Top Face Scale in Alpha Channel

Top Cube Map Face RGB

Page 38: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

RGBScale HDR Environment Map

• Alpha channel contains 1/16 of the true HDR scale of the pixel value

• RGB contains normalized color of the pixel• Pixel shader reconstructs HDR value from

scale*8*color to get half of the true HDR value• Obvious quantization issues, but reasonable for

some applications• Similar to Ward’s RGBE “Real Pixels” but

simpler to reconstruct in the pixel shader

Page 39: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Image Space Glows

• Render scene into multisample AA back buffer• Also render HDR clear coat and other emissive

objects into small texture map• Run separable Gaussian blur over this small

texture similar to RNL demo shown earlier• Composite this with rendered scene• Gives glows off of any bright areas in the

scene, including reflections off of the car body

Page 40: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Procedural Wood

• Based on example in Advanced RenderMan

• Uses volume texture for noise and 1D texture for smooth pulse train

• My version has 8 intuitive parameters– Light Wood Color– Dark Wood– ring frequency– noise amplitude– trunk wobble frequency– trunk wobble amplitude– specular exponent scale– specular exponent bias

Non-Real-Time Version

Page 41: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Procedural Wood

Real-Time Version• 40-instruction 2.0 pixel

shader• Samples noise map 6 times• Phong shading

Page 42: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Step-by-step Approach

• Shader Space (Pshade)• Distance from trunk axis (z)• Run through pulse train• Add noise to Pshade

• Add noise as function of z to wobble

Page 43: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Wood Vertex Shader

dcl_position v0dcl_normal v3

def c40, 0.0f, 0.0f, 0.0f, 0.0f // All zeroesm4x4 oPos, v0, c[0] // Transform position to clip space

m4x4 r0, v0, c[17] // Transformed Pshade (using texture matrix 0)mov oT0, r0m4x4 oT1, v0, c[21] // Transformed Pshade (using texture matrix 1)m4x4 oT2, v0, c[25] // Transformed Pshade (using texture matrix 2)

mov r1, c40mul r1.x, r0.z, c29.x // {freq*Pshade.z, 0, 0, 0}mov oT3, r1 // {freq*Pshade.z, 0, 0, 0} for 1D trunkWobble noise in xmov r1, c40mad r1.x, r0.z, c29.x, c29.y // {freq*Pshade.z + 0.5, 0, 0, 0}mov oT4, r1 // {Pshade.z+0.5, 0, 0, 0} for 1D trunkWobble noise in y

m4x4 oT6, v0, c[4] // Transform position to eye spacem4x4 oT7, v3, c[8] // Transform normal to eye space

Page 44: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Pshade

• For this app, Pshade is just world space• The infinite virtual log runs along the z axis• I make a few different transformed versions of

Pshade in the vertex shader in order to turn scalar noise into color noise, as I’ll show later

Page 45: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Distance from z axis

• sqrt (Pshade.x2 + Pshade.y2) * freq• Pass this in to pulse train

Page 46: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Pulse Train• Tuned to look mimic the way colors mix in real wood• One pulse stored in 1D texture which repeats

Page 47: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Concentric Rings

ps.2.0def c0, 2.0f, -1.0f, 0.5f, 0.5f // scale, bias, half, Xdef c1, 1.0f, 1.0f, 0.1f, 0.0f // X, X, 0.1, zero// c2: xyz == Light Wood Color, w == ringFreq// c3: xyz == Dark Wood Colordcl t0.xyzw // xyz == Pshade (shader-space position), w == Xdcl_2d s1 // 1D smooth step functiondp2add r0, t0, t0, c1.w // x2 + y2 + 0rsq r0, r0.x // 1/sqrt(x2 + y2)rcp r0, r0.x // sqrt(x2 + y2)mul r0, r0, c2.w // sqrt(x2 + y2) * freqtexld r0, r0, s1 // Sample from 1D pulse train texturemov r1, c3lrp r2, r0.x, c2, r1 // Blend between light and dark wood colorsmov oC0, r2

Page 48: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Concentric Rings

Page 49: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Noisy Ringsps.2.0def c0, 2.0f, -1.0f, 0.5f, 0.5f // scale, bias, half, Xdef c1, 1.0f, 1.0f, 0.1f, 0.0f // X, X, 0.1, zero// c2: xyz == Light Wood Color, w == ringFreq// c3: xyz == Dark Wood Color, w == noise amplitude// c4: xyz == L_eye, w == trunkWobbleAmplitudedcl t0.xyzw // xyz == Pshade (shader-space position), w == Xdcl t1.xyzw // xyz == Perturbed Pshade, w == Xdcl t2.xyzw // xyz == Perturbed Pshade, w == Xdcl t3.xyzw // xyz == {Pshade.z, 0, 0}, w == Xdcl t4.xyzw // xyz == {Pshade.z + 0.5, 0, 0}, w == Xdcl_volume s0 // Luminance-only Volume noisedcl_2d s1 // 1D smooth step functiontexld r3, t0, s0 // Sample dX from scalar noise at Pshadetexld r4, t1, s0 // Sample dY from scalar noise at perturbed Pshadetexld r5, t2, s0 // Sample dZ from scalar noise at perturbed Pshademov r3.y, r4.x // Put dY in ymov r3.z, r5.x // Put dZ in zmad r3, r3, c0.x, c0.y // Put noise in -1..+1 rangemad r7, c3.w, r3, t0 // Scale by amplitude and add to Pshade to warp the domaindp2add r0, r7, r7, c1.w // x2 + y2 + 0rsq r0, r0.x // 1/sqrt(x2 + y2)rcp r0, r0.x // sqrt(x2 + y2)mul r0, r0, c2.w // sqrt(x2 + y2) * freqtexld r0, r0, s1 // Sample from 1D pulse train texturemov r1, c3lrp r2, r0.x, c2, r1 // Blend between light and dark wood colorsmov oC0, r2

Page 50: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Colored Volume Noise

Page 51: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Noisy Rings

Page 52: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Trunk Wobble

Without Wobble With Wobble

Page 53: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Noise and wobbledef c0, 2.0f, -1.0f, 0.5f, 0.5f // scale, bias, half, Xdef c1, 1.0f, 1.0f, 0.1f, 0.0f // X, X, 0.1, zero// c2: xyz == Light Wood Color, w == ringFreq// c3: xyz == Dark Wood Color, w == noise amplitude// c4: xyz == L_eye, w == trunkWobbleAmplitudedcl t0.xyzw // xyz == Pshade (shader-space position), w == Xdcl t1.xyzw // xyz == Perturbed Pshade, w == Xdcl t2.xyzw // xyz == Perturbed Pshade, w == Xdcl t3.xyzw // xyz == {Pshade.z, 0, 0}, w == Xdcl t4.xyzw // xyz == {Pshade.z + 0.5, 0, 0}, w == Xdcl_volume s0 // Luminance-only Volume noisedcl_2d s1 // 1D smooth step function (blend factor in x, spec exp in y, ...)texld r3, t0, s0 // Sample dX from scalar volume noise texture at Pshadetexld r4, t1, s0 // Sample dY from scalar volume noise texture at perturbed Pshadetexld r5, t2, s0 // Sample dZ from scalar volume noise texture at perturbed Pshadetexld r6, t3, s0 // Sample trunkWobble.x from scalar noise at {Pshade, 0, 0}texld r7, t4, s0 // Sample trunkWobble.y from scalar noise at {Pshade + 0.5, 0, 0}mov r3.y, r4.x // Put dY in ymov r3.z, r5.x // Put dZ in zmov r6.y, r7.x // Move to get {trunkWobble.x, trunkWobble.y, 0}mad r6, r6, c0.x, c0.y // Put {trunkWobble.x, trunkWobble.y, 0} in -1..+1 rangemad r3, r3, c0.x, c0.y // Put noise in -1..+1 rangemad r7, c3.w, r3, t0 // Scale noise by amplitude and add to Pshade to warp the domainmad r7, c4.w, r6, r7 // Scale {trunkWobble.x, trunkWobble.y, 0} by amplitude and add indp2add r0, r7, r7, c1.w // x2 + y2 + 0rsq r0, r0.x // 1/sqrt(x2 + y2)rcp r0, r0.x // sqrt(x2 + y2)mul r0, r0, c2.w // sqrt(x2 + y2) * freqtexld r0, r0, s1 // Sample from 1D pulse train texturemov r1, c3lrp r2, r0.x, c2, r1 // Blend between light and dark wood colorsmov oC0, r2

Page 54: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Noise and Wobble

Page 55: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Full Shaderps.2.0def c0, 2.0f, -1.0f, 0.5f, 0.5f // scale, bias, half, Xdef c1, 1.0f, 1.0f, 0.1f, 0.0f // X, X, 0.1, zerodcl t0.xyzw // xyz == Pshade (shader-space position), w == Xdcl t1.xyzw // xyz == Perturbed Pshade, w == Xdcl t2.xyzw // xyz == Perturbed Pshade, w == Xdcl t3.xyzw // xyz == {Pshade.z, 0, 0}, w == Xdcl t4.xyzw // xyz == {Pshade.z + 0.5, 0, 0}, w == Xdcl t6.xyzw // xyz == P_eye, w == Xdcl t7.xyzw // xyz == N_eye, w == Xdcl_volume s0 // Luminance-only Volume noisedcl_2d s1 // 1D smooth step function (blend factor in x, specular exponent in y, ...)texld r3, t0, s0 // Sample dX from scalar volume noise texture at Pshadetexld r4, t1, s0 // Sample dY from scalar volume noise texture at perturbed Pshadetexld r5, t2, s0 // Sample dZ from scalar volume noise texture at perturbed Pshadetexld r6, t3, s0 // Sample trunkWobble.x from scalar volume noise at {Pshade.z, 0, 0}texld r7, t4, s0 // Sample trunkWobble.y from scalar volume noise at {Pshade.z + 0.5, 0, 0}mov r3.y, r4.x // Put dY in ymov r3.z, r5.x // Put dZ in zmov r6.y, r7.x // Move to get {trunkWobble.x, trunkWobble.y, 0}mad r6, r6, c0.x, c0.y // Put {trunkWobble.x, trunkWobble.y, 0} in -1..+1 rangemad r3, r3, c0.x, c0.y // Put noise in -1..+1 rangemad r7, c3.w, r3, t0 // Scale noise by amplitude and add to Pshade to warp the domainmad r7, c4.w, r6, r7 // Scale {trunkWobble.x, trunkWobble.y, 0} by amplitude and add indp2add r0, r7, r7, c1.w // x2 + y2 + 0rsq r0, r0.x // 1/sqrt(x2 + y2)rcp r0, r0.x // sqrt(x2 + y2)mul r0, r0, c2.w // sqrt(x2 + y2) * freqtexld r0, r0, s1 // Sample from 1D pulse train texturemov r1, c3lrp r2, r0.x, c2, r1 // Blend between light and dark wood colorssub r4, c4, t6 // Compute normalized vector from vertex to light in eye space (L_eye)dp3 r5.w, r4, r4 //rsq r5.w, r5.w //mul r4, r4, r5.w // L_eyedp3 r6.w, t7, t7 // Normalize the interpolated normalrsq r6.w, r6.w //mul r5, t7, r6.w // N_eyedp3 r3.w, t6, t6 // Compute normalized vector from the eye to the vertexrsq r3.w, r3.w //mul r3, -t6, r3.w // V_eyeadd r6, r3, r5 // Compute Eye-Space HalfAngle (L_eye+V_eye)/|L_eye+V_eye|dp3 r6.w, r6, r6rsq r6.w, r6.wmul r6, r6, r6.w // H_eyedp3_sat r6, r5, r6 // N.Hmad r0.z, r0.z, c5.z, c5.w // scale and bias wood ring pulse to specular exponent rangepow r6, r6.x, r0.z // (N.H)^kdp3 r5, r4, r5 // Non-clamped N.Lmad_sat r5, r5, c0.z, c0.z // "Half-Lambert" trick for more pleasing diffuse termmul r6, r6, r0.y // Gloss the highlight with the ramp texturemad r2, r5, r2, r6 // N.L * procedural albedo + specularmov oC0, r2

Page 56: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

With Phong Shading

Page 57: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Final Scene

Page 58: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

High Dynamic Range Rendering

Page 59: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

HDR Rendering Process

Scene Geometry lit with

HDR Light

Probes

Tone Map

HDR Scene

Bloom Filter +

Displayable Image

Page 60: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Rendering the Scene

• Render reflected scene into HDR planar reflection map for table top

• HDR light probe for distant environment• HDR environment maps for local reflections from

balls on pedestals• Postprocess to get glows• Tone map to displayable image

Page 61: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Local Reflection

• Distant HDR Light probe is always sampled with reflection vector in pixel shader

• Local environment map is sampled with a blend of the surface normal (N) and the reflection vector (R)

Up

100% R

Blend between R

and N

100% N

Page 62: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Frame Postprocessing

Vertical 3-Gaussian Filters

Tone Map

Displayable Image

+

HDR Scene

¼ Size Frame

Horizontal 3-Gaussian

Filters

Page 63: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Tone Mapping

Very Underexposed Underexposed

Good exposure Overexposed

Page 64: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Motion Blur in Animusic Pipe Dream Demo

• Real-time version of Animusic Pipe Dream animation from SIGGRAPH 2001 Electronic Theater

Image from Real-Time Animusic Pipe Dream demoImage from Real-Time Animusic Pipe Dream demo

Page 65: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Motion Blur Distorts Shape and Shading• Shape

– Stretching objects similar to [Wloka and Zeleznik]• Flying balls• Plucked strings

• Shading– Lower specular exponent and intensity as function of

velocity– Apply per-pixel lod bias as a function of velocity– Alpha set to represent contribution to the scene

Page 66: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Motion Blur

Image from Real-Time Animusic Pipe Dream demoImage from Real-Time Animusic Pipe Dream demo

Plucked String

Moving Balls

Page 67: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Motion Blur

Plucked Plucked StringString

Image from Real-Time Animusic Pipe Dream demoImage from Real-Time Animusic Pipe Dream demo

Moving BallsMoving Balls

Page 68: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Distorting Shape of Balls

• Geometry stretching similar to [Wloka and Zeleznik]

• Instantaneous velocity (distance ball moved since previous time step) is input to vertex shader as is the motion vector M

• M – (M · Eye) is motion perpendicular to the eye

• Vertex shader computes Blur factor• 1/(1+distance traveled/ball diameter)

Page 69: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Capsule Distortion

Path of Motion

Direction of Motion

Path of Motion

Direction of Motion

No Motion BlurNo Motion Blur With Motion BlurWith Motion Blur

Page 70: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Distorting Shading of Balls

• Blur factor interpolated across polygons– Pixel shader does LOD biased texture load from

environment map as function of blurriness factor– Specular exponent (k) gets smaller as ball goes

faster, broadening the highlight– Scalar gloss term also get smaller– Serves to distribute the energy over pixels as

specular highlight “smears”– Alpha of pixel says how much the ball was “there” at a

given pixel

Page 71: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Motion Blur on StringsPlucked Plucked StringString

Page 72: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Motion Blur on Strings

• Two instances of string geometry are drawn when in motion

• One instance bends back and forth over time and retains original thickness

• Other instance is stretched apart to span full current amplitude of motion and is blended on top

• Alpha of second string is function of amplitude– More motion equals lower alpha

Page 73: RenderMonkey™ - AMDdeveloper.amd.com/wordpress/media/2012/10/RenderMonkey.pdf · • Render State • Pixel Shader • ... texld r0, r0, s1 // Sample from 1D pulse train texture

Conclusion

• RenderMonkey™ is a suite of tools designed to help developers create, manage and share real-time effects

• The RenderMonkey™ IDE facilitates rapid prototyping of real time effects

– Built with a plug-in interface– Customizable