SyntaxHighlighter

Tuesday 2 July 2013

Day 17: Shaders in XNA, Walter felt left out and threw a tantrum

Realised the darkish hue shifting across the model of the head was not due to shadow, but actually due to some sort of reflection to do with the light source. Looks specular.

Tested different light modes, tested different sources etc, fixed models being very dark by disabling the second directional light source as it was doing dodgy stuff. I honestly don't know why it exists, a relic of older code.

Shaders

To fix the above problems and others previously, I had to research in-depth into how Goblin XNA uses shaders. These are a few notes as a reference.

Instead of using a set of fixed-pipeline functions to render the 3D object and the scene, Goblin XNA uses programmable 3D graphics pipeline with the ability to create customized vertex shaders and pixel shaders.

+ Gives programmer more power and flexibility in determining how the 3D objects in the scene are rendered
- But must create your own shader to draw even a single triangle.

Sample set of shaders provided, includes simple effect shader (can render many kinds of simple objects), more advanced general shader, particle shader, and a shadow mapping shader.

Regarding which light sources from scene graph are passed to shaders, shader interface code determines which lights take priority. E.g. may give priority to global lights over local lights, or local lights over global lights, if not all lights are passed.

SimpleEffectShader

Renders all models by default. Uses BasicEffect class from vanilla XNA GS 4, which means it has an important limitation: can only use 3 light sources and all must be directional lights. Any point or spot lights are ignored. If over 3 light sources, local ones take precedence over global.

DirectX Shader

Implements fixed-pipeline lighting of DX9, can render point, spot and directional light sources.

Other shaders

ParticleShader to render particle effects

NormalMapShader render 3D models with bump map textures and environmental reflections. To assign bump map texture for reflections, must use NormalMapMaterial instead of regular Material class.

MultiLightShadowMap and SimpleShadowShader render shadows, to display them need to do the following:
  1. Set Scene.EnableShadowMapping to true
  2. Set Model.ShadowAttribute for each 3D model (receive only, or cast + receive, or none).
  3. May need to tweak DepthBias properties of MultiLightShadowMap for any light types (directional, point or spot) to make shadow render properly.

Poor Walter

Walter decided to stop booting! Started off when another vacation student, Anna, noticed that Walter's sound wasn't working. After investigation I noted that the sound device was not visible in Windows. I reinstalled the sound drivers and rebooted, and that's when Walter decided to throw in the towel. The PC starts up, displays the POST screen and then just hangs.

Diagnosis:
Unplugged absolutely everything except CPU video card and Ram, but same problem (stuck at post). Removed hard drive, dvd drive, sata cables, all front panel pins and cables, case fans. Attaching just the hard drive makes no difference.

Removing the ram means nothing comes on screen at all (monitor doesnt get any signal). I was expecting the board to warning beep but it does nothing. Replacing the ram (one stick at a time in different slots) means the POSTscreen comes up but it hangs there as usual. It correctly recognizes 4gb and 2gb ram.

All i can presume is that its the motherboard at fault. New parts ordered from Scan, had to forego the FX 6300 hex-core 3.5GHz processor in favour of a quad-core 4.3GHz processor as it was out of stock, but other than that it's the same parts Donald recently got. Seems Walter was jealous!

No comments:

Post a Comment

Note: only a member of this blog may post a comment.