Prologue to 3D Design Programming with Direct3D and .NET.

Uploaded on:
Category: News / Events
Prologue to 3D Illustrations Programming with Direct3D and .NET Ben Houston Neuralsoft Partnership Slight Subject Change Direct3D particular, OpenGL is somewhat hard to use from C#. 3D illustrations programming center, 2D is a subset of 3D. Rendering is Reproduction
Slide 1

Prologue to 3D Graphics Programming with Direct3D and .NET Ben Houston Neuralsoft Corporation

Slide 2

Slight Topic Change Direct3D particular, OpenGL is fairly hard to use from C#. 3D representation programming center, 2D is a subset of 3D.

Slide 3

Rendering is Simulation The thought is to (as a rule) mimic how a virtual world with manufactured properties would show up on the off chance that it existed, in actuality. Parts of reality: Observer – our eyes, a camera, etc… Light sources – transmit light vitality (i.e. photons) Physical elements that reflect, ingest, and channel the light vitality. Two principle approaches: Global illumuniation/worldwide reproduction Local enlightenment/neighborhood reenactment

Slide 4

Global Illumination Models light from source, to its conceivably numerous connections in the earth (reflection, refraction, dispersion, assimilation) and how it is percieved by the spectator. Normal methodologies: Ray following (doesn’t handle dissemination well) Radiosity (doesn’t handle reflection well, moderate) Photon mapping (extremely decent results)

Slide 5

Global Illumination – Photon Mapping high detail models, profundity of field, delicate shadows, intelligent surfaces.

Slide 6

Global Illumination – Photon Mapping refraction, reflection list of refraction shifts with light wavelength making rainbow impacts. + 30 minutes render time for every edge.

Slide 7

Local Illumination Each surface is shaded successively based neighborhood data just, no broad worldwide data is given. Any worldwide light impacts are “faked” by means of different easy route systems. The present era of GPUs is limited to neighborhood light models – for the present...

Slide 8

History of 3D Graphics on the PC Castle Wolfenstien (1992) Descent (1994) Descent II (1995) Lara Croft & Quake (1996) …. speedier and quicker … Doom 3 & Half-Life 2 (2004)

Slide 9

Castle Wolfenstien (1992) The first famous 3D first individual shooter. Was a 2D beam caster consolidated with vertical output line rasterization. Composed by John Carmark (who later made the Doom, and Quake arrangement.)

Slide 10

Descent and Descent II (1994-95) One of the first well known genuine 3D textured polygon-based amusement. Utilized profoundly enhanced programming schedules – kept running at 320x200 and had extremely clear “jitters.” One of the first amusements to bolstered 3D illustrations quickening agents. ATI & Matrox offered moderate increasing speed – frequently slower than programming. 3DFX Voodoo Graphics chipset was astounding.

Slide 11

Lara Croft & Quake (1996) The initial 2 noteworthy 3D textured polygon-based first individual shooters. 3D representation quickening agents got to be well known The way that Quake utilized OpenGL as its 3D API practically without any help kept Direct3D out of the spotlight for two or three years.

Slide 12

… quicker and speedier … 3D was all over, just about it quite often utilized the altered capacity rendering pipeline. Multi-pass rendering was utilized to make complex impacts. NVIDIA GForce 2 (~2000) presented the programmable pipeline Programs must be composed in constructing agent. Must be under 256 directions. No circles. Was generally overlooked.

Slide 13

Doom III & Half-Life 2 (2004) New GPUs alongside Cg/HLSL make the programmable pipeline usable. Totally excellent impacts.

Slide 14

Getting Started – Managed DirectX: “An propelled suite of sight and sound application programming interfaces (APIs) incorporated with Microsoft Windows⮠working systems” Fully highlighted oversaw layer for the DirectX runtime. Fits inside of the style rules for .NET Does all that you can do with local DirectX Managed Direct X Characteristics/Features: High Performance Interoperates with local C++ DirectX Design Stresses convenience. Occasion model. Firmly sorts usefulness. Organized exemption taking care of.

Slide 15

Getting Started - MyForm/contains helpful polynomial math structs: Matrix , Vector3 , Plane , Quaternion utilizing Microsoft.DirectX;/contains everything else: Device , Mesh , Texture , Light , Material , … utilizing Microsoft.DirectX.Direct3D; open class MyForm : System.Windows.Forms.Form { open MyForm() { this .InitializeComponent();/instate WinForms controls (discretionary) this. InitializeGraphics();/instate Direct3D stuff/this.InitializeVertexBuffer();/instate vertices (2 nd sample) } …

Slide 16

Getting Started – Device Setup Device _device = invalid ; open void InitializeGraphics() { PresentParameters presentParams = new PresentParameters(); presentParams.Windowed = genuine;/we are not in full screen mode presentParams.SwapEffect = SwapEffect.Discard;/make our drawing surface and indicate full GPU acceleration… _device = new Device( 0, DeviceType.Hardware, this , CreateFlags.HardwareVertexProcessing, presentParams); }

Slide 17

Getting Started - Rendering ensured void Render() { //clear the casing cradle preceding rendering _device.Clear( ClearFlags.Target, Color.Black, 1.0f , 0 ); _device.BeginScene();/constantly matched with _device.EndScene() this .DrawScene(); _device.EndScene(); _device.Present(); /demonstrate this edge cushion on screen } secured void DrawScene() {/doing nothing for the minute }

Slide 18

Getting Started - Main static void Main() { using ( myForm = new MyForm() ) { myForm.Show();/render and procedure messages until quit while ( myForm.Created ) { myForm.Render(); Application.DoEvents(); } } }

Slide 19

Getting Started – Example

Slide 20

Simple 2D – Introduction *Everything* rendered is made out of vertices and triangles. You can utilize a great deal of little polygons giving the impression of bended surfaces. Different layers of semi-straightforward polygons can make smoke or flame impacts.

Slide 21

Simple 2D – Screen Vertices utilizing TCVertex = CustomVertex.TransformedColored; /essentially our code open void InitializeVertexBuffer() { //determine the corner areas and shades of our first triangle TCVertex[] verts = new TCVertex[ 3 ]; verts[ 0 ] = new TCVertex( new Vector4( 150 , 50 , 1 , 1 ), Color.Red.ToArgb() ); verts[ 1 ] = new TCVertex( new Vector4( 250 , 250 , 1, 1 ), Color.Green.ToArgb() ); verts[ 2 ] = new TCVertex( new Vector4( 50 , 250 , 1 , 1 ), Color.Yellow.ToArgb() ); … X (150,50) Positions of TransformedColored vertices are indicated in Screen Space (50,250) (250,250) Y

Slide 22

Simple 2D - Rendering //vertex cushions conceal the intricacy of stacking vertices into GPU memory _vertexBuffer = new VertexBuffer( typeof ( TCVertex ), verts.Length, _device, 0 , TCVertex.Format, Pool.Default ); GraphicsStream graphicsStream = _vertexBuffer.Lock( 0 , 0 , LockFlags.None ); graphicsStream.Write( verts ); _vertexBuffer.Unlock(); } ensured void DrawScene() { _device.SetStreamSource( 0 , _vertexBuffer, 0 ); _device.VertexFormat = TCVertex.Format; _device.DrawPrimitives( PrimitiveType.TriangleList, 0 , 1 ); }

Slide 23

Simple 2D - Example

Slide 24

Simple 3D - Introduction The Transformation Pipeline: changes over 3D vertices into 2D screen facilitates

Slide 25

Simple 3D – World Vertices utilizing PCVertex = CustomVertex.PositionColored; open void InitializeVertexBuffer() {/indicate the corner areas and shades of our first triangle PCVertex[] verts = new PCVertex[3]; verts[0] = new PCVertex( new Vector3( 0, 1, 0 ), Color.Red.ToArgb() ); verts[1] = new PCVertex( new Vector3( 1, - 1, 0 ), Color.Green.ToArgb() ); verts[2] = new PCVertex( new Vector3(- 1, - 1, 0 ), Color.Yellow.ToArgb() ); … Y (0,1) Positions of PositionColored vertices are determined in World Space X (- 1,- 1) (1,- 1)

Slide 26

Simple 3D – Matrix Math Transforms are Vector-Matrix duplications. Networks are 4x4 homogeneous frameworks. The relative changes: Scale Rotations interpretation The projection changes: Perspective Orthogonal

Slide 27

Simple 3D – Affine Transforms Rotations Scaling X-Axis Y-Axis Translation Z-Axis

Slide 28

Simple 3D – Affine Transforms secured void DrawScene() {/guarantee revolution rate is autonomous of PC velocity float rotationAngle = ( 2*Math.PI ) * ((Environment.TickCount % 1000)/1000f); _device.Transform.World = Matrix.RotationY( rotationAngle ); …

Slide 29

Simple 3D – Affine Transforms Camera can be put and arranged self-assertively inside of world space. … _device.Transform.View = Matrix.LookAtLH( new Vector3( 0, 0, - 5 ), /target area new Vector3( 0, 0, 0 ), /eye/camera area new Vector3( 0, 1, 0 ) ); /“up” pivot … Y Side View Z Camera (0,0,- 5)

Slide 30

Simple 3D – Perspective Transform … _device.Transform.Projection = Matrix.PerspectiveFovLH( ( coast ) Math.PI/4, /y-hub field of perspective 1, /pixel angle proportion 1, /close z cutting 100 ); /far z cutting …

Slide 31

Simple 3D - Example

Slide 32

Simple Shading – Introduction Three enlightenment parts can be indicated: Ambient – strong shading Diffuse – general form shading Specular – sparkle, highlight Three shading models: Flat –one shading per triangle, figured at midpoint. Gouraud – one shading for every vertex, shading inserted crosswise over triangle inside Phong – one shading for each pixel, parameters added crosswise over triangle inside Requires Materials & Lights .

Slide 33

Simple Shading – Wireframe

Slide 34

Simple Shading – Flat/Ambient

Slide 35

Simple Shading – Flat/Amb. + Diff.

Slide 36

Simple Shading – Gouraud/Amb. + Diff. .:tsli

View more...