0

0

1600 days ago,
564 views

PowerPoint PPT Presentation
Vertex and Pixel Shaders: Making the world safe for Computer Graphics Adrian Perez 15-463: Computer Graphics 2 February 27 th , 2001

Administrivia Homework 1 will be given back on Thursday Midterm is next Tuesday Review for midterm is this Thursday.

Talk Outline Motivation for vertex/pixel shaders Vertex Shaders Implementation in DX8 Examples Pixel Shaders Implementation in DX8 Examples Integration with different regions of DX8

But First… blessed war overhaul Direct3D won. Get over it. OpenGL can't oblige the speed at which the representation business is moving at this point. The greater part of the extentions to do things like vertex and pixel shading are seller particular. Direct3D quit sucking a couple of forms prior in any case.

Transformation and Lighting The way D3D used to be was altered capacity Unlit primitives (objectspace position/ordinary/material/uv's) Lit primitives (objectspace position/shading/uv's) Transformed-and-lit primitives (screenspace position/shading/uv's)

Transformation and Lighting The Good Provided an instrument for individuals to roll their own particular T&L (back when everyone did as such) The Bad Restrictive in capacity. You will undoubtedly D3D's lighting model and change worldview; not a horribly major ordeal for briefly

Transformation and Lighting Games nowadays need more control over the equipment Important on the grounds that something else, each amusement is experiencing a similar code way, making them look fundamentally the same as Especially critical since equipment is getting un-fucking-conceivably quick Microsoft and nVidia understood that a more nonexclusive route for applications to perform change and lighting was required

Enter Vertex Shaders A Vertex Shader is basically low level computing construct for the T&L motor Subset of most ASM dialects: no expanding, for instance If equipment T&L is accessible, the operation codes are just downloaded to the chip and run locally The operation codes are translated by a shockingly quick programming usage if T&L equipment isn't accessible

Enter Vertex Shaders The Good Amazingly intense You are will undoubtedly give it a particular information as contribution, as you are composing the taking care of code Much more accuracy – everything is in drifting point The Bad Hard to troubleshoot and grok We're right back in get together hacking land

Input Registers Output Registers Vertex Shader Registers take note of: all vectors are 4 glides

include Sum dp3 Three-segments spot item dp4 Four-segment dab item dst Distance vector expp Exponential 10-bit exactness lit Lighting coefficients logp Logarithm 10-bit accuracy frantic Multiply and include max Maximum min Minimum mov Move mul Multiply rcp Reciprocal rsq Reciprocal square root sge Set on more noteworthy or equivalent than slt Set on not as much as sub Subtract def Define Constants versus Version and Type exp Exponential base2 full summary. frc Fraction log Logarithm base 2 full exactness m3x2 3×2 vector grid duplicate m3x3 3×3 vector framework increase m3x4 3×4 vector network increase m4x3 4×3 vector lattice duplicate m4x4 4×4 vector framework duplicate Vertex Shader Instructions

Vertex Shader Semantics Shaders are characterized in a different source record. They are "aggregated" into bytecode (at runtime, in the event that you wish) and afterward the bytecode can be stacked onto the card. When you render, you pick a vertex shader to utilize Fixed-work pipeline is still accessible (as a hard-coded vertex shader)

Vertex Shader Examples

#include "Constants.h"/v0 - position/v1 - ordinary/v2 - tex coord vs.1.0/change position dp4 oPos.x, v0, c[CV_WORLDVIEWPROJ_0] dp4 oPos.y, v0, c[CV_WORLDVIEWPROJ_1] dp4 oPos.z, v0, c[CV_WORLDVIEWPROJ_2] dp4 oPos.w, v0, c[CV_WORLDVIEWPROJ_3]/change typical dp3 r0.x, v1, c[CV_WORLD_IT_0] dp3 r0.y, v1, c[CV_WORLD_IT_1] dp3 r0.z, v1, c[CV_WORLD_IT_2]/standardize ordinary dp3 r0.w, r0, r0 rsq r0.w, r0.w mul r0, r0, r0.w/register world space position dp4 r1.x, v0, c[CV_WORLD_0] dp4 r1.y, v0, c[CV_WORLD_1] dp4 r1.z, v0, c[CV_WORLD_2] dp4 r1.w, v0, c[CV_WORLD_3]/vector from indicate eye include r2, c[CV_EYE], - r1/standardize e dp3 r2.w, r2, r2 rsq r2.w, r2.w mul r2, r2, r2.w/e dab n dp3 oT1.x, r0, r2/l dab n dp3 oT0.x, r0, c[CV_LIGHT_DIRECTION] Vertex Shader Examples

Vertex Shader Examples

; Distorts vertices in eye-space to give a fish-eye focal point impact #include "trees.h" #define FACTOR_KPLUS1 c[CV_CONSTANTS].x #define XYZW_MAX_XZRATIO x #define XYZW_FACTOR_K y #define XYZW_ZERO z #define XYZW_ONE w vs.1.0 ; Transform position to view space dp4 r0.x, v0, c[CV_WORLDVIEW_0] dp4 r0.y, v0, c[CV_WORLDVIEW_1] dp4 r0.z, v0, c[CV_WORLDVIEW_2] dp4 r0.w, v0, c[CV_WORLDVIEW_3] ; scale x and y, set z and w to 0 mul r1, r0, c[CV_FISHEYEINFO].xxzz ; process standardized separation from (camera in view-space is alwasy at (0,0,0)) ; r1.x = sqrt(x^2 + y^2)/z dp3 r1.x, r1, r1 rsq r1.y, r1.x mul r1.y, r1.y, r0.z rcp r1.x, r1.y ; and take the outright esteem max r1.x, r1.x, - r1.x ; figure (k*d + 1) frantic r1.z, r1.x, c[CV_FISHEYEINFO].XYZW_FACTOR_K, c[CV_FISHEYEINFO].XYZW_ONE ; figure (k+1)/(k*d + 1) - this is the complementary recipe of the ; above referenced website page in light of the fact that our separations are ; by and large at least 1.0! rcp r1.z, r1.z mul r1.xy, FACTOR_KPLUS1, r1.z ; just scale the first x, y with this element mul r0.xy, r0, r1 ; change new position to clasp space dp4 oPos.x, r0, c[CV_PROJ_0] dp4 oPos.y, r0, c[CV_PROJ_1] dp4 oPos.z, r0, c[CV_PROJ_2] dp4 oPos.w, r0, c[CV_PROJ_3] ; Draw utilizing provided tree shading mov oD0.xyzw, v1 mov oT0.xy, v2 Vertex Shader Examples

Vertex Shader Examples

One Last Example…

vs.1.0 ; Projected Textures ; Adrian Perez ; 2/27/01 ; Constants: ; c0-c3 - World+View+Projection lattice ; c4-c7 - Texture grid 1 ; c8 - Color ; c9 - 1.0 ; c10 - 0.5's for modifying the surface organize ; c11 - Texture position 1 (worldspace) ; c12-c15 - world->model network ; Transform position m4x4 oPos, v0, c0 ; Set r0 to the clasp space see from the surface light m4x4 r0, v0, c4 ; Fill r1 with 1's mov r1, c9 ; Compute two recriprocals to do point of view amendment rcp r1.xy, r0.z ; Apply reciprocals mul r2, r0, r1 ; subtract 0.5's to alter the surface directions include r2.xy, r2.xy, c10.xy ; r3: the light positoin in worldspace mov r3, c11 ; r4: the light position in modelspace m4x4 r4, r3, c12 ; r5: subtract the model-space position to get a light vector sub r5, r4, v0 ; r8: store the temp length dp3 r8.w, r5, r5 ; r6: corresponding square base of the scalar rsq r6.xyzw, r8 ; Normalize r5 with r6 mul r5.xyz, r5.xyz, r6.xyz ; r6: Compute a dab item to locate the diffuse light dp3 r6.x, r5, v3 ; adjust r6 by the diffuse shading mul r6, r6.xxxx, c8 ; Write out the shading and surface mov oD0, r6 mov oT0, r2 One Last Example…

Pixel Shaders Same thought as vertex shaders, however they control how surfaces and hues are joined per-pixel Currently there is no equipment that executes them The GeForce3 (when it turns out) will do them, so will the XBox

Pixel Shaders The Good Explicit control of surface consolidating Lots of Nifty Tricks (EMBM) The Bad Designed for a more broad bit of equipment; a considerable measure of the usefulness of the GeForce3 is not uncovered

Pixel Shader Registers

include Add cnd Conditional dp3 Three-Component Vector Dot-Product lrp Linear Interpolation Blend frantic Multiply and Add mov Copy Source Into Destination mul Modulate sub Loads the distinction of the two hues in the source operands. tex No Modification texbem Bump Environment Map texbeml Bump Environment Map with Luminance texcoord Texture Coordinate texkill Mask Out Pixel texm3x2pad Input to 3×2 Matrix Multiply texm3x2tex 3×2 Matrix Multiply Result texreg2ar Remapping Alpha and Red Components texreg2gb Remapping Green and Blue Components texm3x3pad Input to 3×3 Matrix Multiply texm3x3spec Specular Reflection and Environment Mapping texm3x3tex 3×3 Matrix Multiply Result texm3x3vspec Specular Reflection/Environment Mapping without Constant Eye Vector Pixel Shader Instructions

Pixel Shader Examples Unfortunately, at this moment the best way to create pixel shader applications is to utilize the Reference Rasterizer. So source on the most proficient method to utilize it is entirely rare The documentation is really secretive, it's not about as very much designed as vertex shaders seem to be

Pixel Shader Examples

Pixel Shader Examples

Other Cool Shit in DX8 N-Patches Subdivision conspire that requires no contiguousness data. You give an arrangement of vertices and vertex normals, and it renders a smooth work. Perfect: You send the base level work down to the card, and your vertex shader gets encouraged the subdivided vertices. This is one great approach to get around the way that you can't make new vertices in a shader Bezier surfaces Yea, yea… they're not as cool as N-Patches

N-Patches

Other Cool Shit in DX8 Volume Textures Holy poo these things fucking rock Finally, a rich approach to handle blasts and rocket flares Plus a million different traps Third surface arrange, they act precisely like 2D surfaces

Other Cool Shit not in DX8 Shadow Mapping Supported by the GeForce3, yet the usefulness is not uncovered by DX8. Furthermore, yes, it is uncovered in OpenGL. (murmur… )

Conclusion DirectX 8.0 is the fucking bomb.

Questions? ? ? ?

SPONSORS

No comments found.

SPONSORS

SPONSORS