Advanced Rendering & Shading Seminar 3 Advanced Rendering and Shading
Pluto Computer room with NVidia 6600 graphics cards All remaining assignment examination slots are in this room Advanced Rendering and Shading 2
Preparations fxfiles.zip available for download from course web page Create effects folder and unpack into it FX Composer User Guide Introduction to the DirectX High-Level Shading Language Work at home: Use FX Composer 1.8! Advanced Rendering and Shading 3
FXComposer UI panels Advanced Rendering and Shading 4
FX Composer Editor for materials expressed in shader language Materials stored in effect files (.fx) Semantics & Annotations Tweakables Shader code (vertex and pixel) Techniques Advanced Rendering and Shading 5
FX Composer how to Create fxcomposer project Create new material (effect) Tweak an effect Add scene object Edit scene object properties Advanced Rendering and Shading 6
FXComposer configuration Not necessary for assignment! But nice to know FXComposer manual page 27 fxcomposer_config.xml standard materials fxmapping.xml semantics and annotations defaultscene.fx rendering method used by fxcomposer expressed in xml, see manual chapter 3 Advanced Rendering and Shading 7
Semantics & Annotations Input semantics are names used to link the given shader input to an output of the previous stage of the graphics pipeline Output semantics are used to specify how data generated by the shader should be linked to the inputs of the next stage. For example, the output semantics for a vertex shader are used to link the outputs with the interpolators in the rasterizer to generate input data for the pixel shader. Global variables can have annotations, which can be queried using effects. One or more annotations can be attached to any parameter. Annotations are metadata that can be attached to any parameter. They are specified inside of angle brackets (< >). Advanced Rendering and Shading 8
Semantics & Annotations float4x4 worldviewproj : WorldViewProjection; float4x4 world : World; float4x4 worldinversetranspose : WorldInverseTranspose; float4x4 viewinverse : ViewInverse; float shininess : SpecularPower < string UIWidget = "slider"; float UIMin = 1.0; float UIMax = 128.0; float UIStep = 1.0; string UIName = "specular power"; > = 30.0; Tweakable Advanced Rendering and Shading 9
Shader code Previous lecture... Advanced Rendering and Shading 10
Technique Contains a number of passes Each pass may contain a vertex and a pixel shader and device state information Profile 2.a in FXComposer examples NVidia-specific 2.a can in most instances be replaced with standard 2.0 Advanced Rendering and Shading 11
First.fx // An empty material, which simply transforms the vertex and sets the color. /*********** Parameters ******/ float4x4 ModelViewProj : WorldViewProjection; /*********** Vertex shader ******/ void simplevs(float4 position : POSITION, out float4 clipposition : POSITION, out float4 color : COLOR) { clipposition = mul( position, ModelViewProj); color = float4(1.0, 1.0, 0.0, 1.0); } technique simple { pass p0 {!! VertexShader = compile vs_1_1 simplevs(); } } Advanced Rendering and Shading 12
Green Pixel Shader first.fx is a color vertex shader PS semantics OUT: COLOR Advanced Rendering and Shading 13
Bulging shader Semantics: IN: POSITION, NORMAL OUT: POSITION Bulging = move vertex along normal direction Advanced Rendering and Shading 14
Phong reflection You have access to Gouraud shader! Per pixel instead of per vertex Move calculations to the pixel shader Advanced Rendering and Shading 15
Phong shader Semantics VS IN: POSITION, NORMAL OUT: POSITION, TEXCOORDn PS IN: TEXCOORDn OUT: COLOR worldnormal worldeye worldlight Intrinsic for reflection calculation: -reflect(l,n) Advanced Rendering and Shading 16
Phong with Bulging Bulging = move vertex along normal direction Animate to grow and shrink hint: float t : Time; Advanced Rendering and Shading 17
Phong with Texture kd Pick material constant from texture instead of keeping it constant Look at Texturing.fx Advanced Rendering and Shading 18
Phong with Bump mapping Hint: look at hemibump.fx Vertex shader Tangent space base vectors (given in object space) Normal (semantic: NORMAL) Tangent (semantic: TANGENT) Binormal (semantic: BINORMAL) Need tangent space base vectors in world space! UV for bump normal map (semantic: TEXCOORD0) Pixel shader Read bump normal from texture (vector c) Perturbed world normal = c.x*wx+c.y*wy+c.z*wz Bump normal stored in RGB space! c.xyz = tex2d(...) - (0.5,0.5,0.5) Advanced Rendering and Shading 19
Environment + Bump mapping Create effect that combines environment and bump mapping Hint: study hemibump.fx and reflection.fx Advanced Rendering and Shading 20
Animated bump heights Environment mapping + bump mapping Animate bump mapped heights Advanced Rendering and Shading 21
Combination Phong + environment + bump + animated bump heights + bulging Advanced Rendering and Shading 22
Texture twisting Advanced Rendering and Shading 23
Texture twisting a = twisting * (1.0/(length(uvpos.xy)+0.1)) uvpos <- TEXCOORD0 Advanced Rendering and Shading 24
Vertex twisting Advanced Rendering and Shading 25
Vertex twisting angle = twisting * length(pos.xy) Twist is performed in clip space Advanced Rendering and Shading 26
Mandelbrot Advanced Rendering and Shading 27
Mandelbrot Parameters: S: 0-10, X: -2-2, Y: -2-2 Varying input: u,v: 0-1 (TEXCOORD0) Complex function: (c_real,c_imag) = S*(u-0.5,v-0.5) + (X,Y) Iterate k times (init: (r,i)=(c_real, c_imag)) (r,i) = (r*r-i*i+c_real, 2*r*i+c_imag) If dist_square > 4 then outside else inside dist_square = r*r+i*i PS 2.0 unrolls loops! Limited number of instructions! Try ps_2_a or ps_3_0 Advanced Rendering and Shading 28
Wood Color lightwood = float4(0.5,0.2,0.067,1) Color darkwood = float4(0.3,0.154,0.056,1) WoodColor: lerp(lightwood, darkwood, b) (PS) Help functions: SmoothPulseTrain(e0, e1, e2, e3, period, x) Return SmoothPulse(e0, e1, e2, e3, fmod(x,period) SmoothPulse(e0, e1, e2, e3, x) Return smoothstep(e0, e1,x) smoothstep(e2, e3,x) b = SmoothPulseTrain(0.1, 0.55, 0.7, 0.95, 2, woodradius) WoodRadius (radius from z axis) (VS) perturbedpos = scaledpos.xyz + (1,0.5,0.2)*noise3d(0.5*scaledPos.xyz) r = length(perturbedpos.xy) + 1.1 * noise3d(0.2*scaledpos.xyz) + 1.5 * noise1d (0.1*scaledPos.z) ScaledPos = scale*pos. //Scale factor in reference image = 40 Noise functions from perlin.zip from the course homepage. Quality depends on tessellation! Why not noise in pixel shader? GPU Gems 2 chapter 26 if someone wants to try (might run into instruction length problems). Advanced Rendering and Shading 29