Difference between revisions of "Lesson 5 - experimentation"

From Bo3b's School for Shaderhackers
Jump to: navigation, search
(Created page with "---- Sometimes we will run into an effect that really cannot be disabled without making the game a lot worse. In this game, the Lava effect is an example. It's annoyingly b...")
 
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
==== Summary ====
 +
This lesson we will talk about the role of experimentation when trying to fix shaders.
 +
 +
 +
Level of difficulty: Easy<br>
 +
Time required: 30 minutes
 +
<br>
 +
<br>
 +
[http://youtu.be/gR2FKk1hz4c <u>Video Walkthrough on YouTube, pt 1</u>] ... 
 +
[http://sg.bo3b.net/Lesson%205%20pt%201.mp4 <u>Video Walkthrough direct download link, pt 1</u>]
 +
<br>
 +
[http://youtu.be/68C5x4A81uk <u>Video Walkthrough on YouTube, pt 2</u>] ... 
 +
[http://sg.bo3b.net/Lesson%205%20pt%202.mp4 <u>Video Walkthrough direct download link, pt 2</u>]
 +
<br>
 +
<br>
 +
 +
==== Objective ====
 +
Experiment on a broken shader to see how the pieces work together.
 +
<br>
 +
Fix the lava shader so it still works.
 +
 +
==== Quiz====
 +
Fix the water shader in the last room.
 +
 +
 +
----
 +
After we've found a broken shader, we want to disable or fix them. We can't always do the easiest fix though, and this is where experimentation comes in.  This is the puzzle aspect of fixing shaders, where it's not always clear how to fix a shader, even after having seen a lot of variants.
 +
 +
The basic premise is to experiment on the shader by commenting out pieces of the code, and reloading it live with F10, and see any change.  As you do these experiments, you can get a feel for what pieces of code affect what part of the image, which can lead you to the best fix. 
 +
 +
It can be quite a bit of trial and error, but can allow you to figure out fixes that don't match common patterns, or to find the right spot for a common pattern.
 +
 +
 +
----
 +
Let's take a look at the basics of 3D graphics, so you can have a very rough idea of how the pieces fit together.  This will give you some understanding of how shaders work.
 +
 +
 +
* Play with the ''Principles of Shading'' demo.
 +
*# Get the demo from [http://stage.nvidia.com/coolstuff/demos#!/principles-of-shading here]
 +
*# Run the demo and get an understanding of the wireframe vertexes versus the textures.
 +
*# Look at the Display menu in particular.
 +
*# Take a first look at the 0.5*D*T formula as a basic building block.
 +
*# Example of texture painted onto triangle [http://www.riemers.net/images/Tutorials/DirectX/Csharp/Series3/DirectX%20Tutorial%206%20-%20Textured%20Triangle.jpg here]
 +
*# Take a look at the graphics pipeline [http://rbwhitaker.wikidot.com/intro-to-shaders here]
 +
*# Get a basic idea of the flow of graphics operations, especially noting VertexShaders run before PixelShaders.
 +
 +
 +
After playing with this demo you should have a sense for how 3D graphics are built out of a list of vertices, that make up an array of triangles, that have textures applied to the triangles.
 +
 +
 
----
 
----
 
Sometimes we will run into an effect that really cannot be disabled without making the game a lot worse.  
 
Sometimes we will run into an effect that really cannot be disabled without making the game a lot worse.  
  
In this game, the Lava effect is an example.  It's annoyingly broken, and makes those parts of the games unplayble. But, disabling it altogether removes the visual cue of the dangerous areas.   
+
In this game, the Lava effect is an example.  It's annoyingly broken, and makes those parts of the games unplayable. But, disabling it altogether removes the visual cue of the dangerous areas.   
  
 
Let's experiment with it, to see if we can make something better.
 
Let's experiment with it, to see if we can make something better.
Line 8: Line 58:
  
 
* Experiment on lava shaders.
 
* Experiment on lava shaders.
*# Inspect and experiment on lava in both VS and PS.
+
*# Inspect and experiment on lava in PS.
*# Fix lava by killing one layer instead of the entire shader.
+
*# In pixel shader, try changing each texld to invisible.
 +
*# Those don't work, look next at the input section with interesting stereo fix.
 +
*# See that v1 is an input location.
 +
*# Experiment by changing v1 to null.
 +
*# Fix lava by killing one texture instead of the entire shader.
 +
*# optional: Fix the lava from the VertexShader output side, where v1 is created.
 +
 
 +
 
 +
----
 +
 
 +
Quiz: Go to the end of the demo, and figure out a way to fix the broken water.
 +
 
 +
* Fix the water shader at the last level.
 +
*# Play through to the giant worm at the end, it's not far.
 +
*# See the water has double-imaging like the water in the hall earlier.
 +
*# Find the shader for the water effect.
 +
*# Disable it. Note that it's really not good enough disabled.
 +
*# Experiment with it to fix it to where it's acceptable.
 +
*# Save a screenshot to your personal page.
 +
 
 +
 
 +
* optional: Fix the entire game.
 +
*# Go through at least 3 levels, and find and mark all broken effects.
 +
*# Disable all broken effects.
 +
*# Fix the lava effect by disabling the texture.
 +
*# Save your complete list of modified shaders to your personal page.
 +
 
 +
<br>

Latest revision as of 00:09, 14 September 2014

Summary

This lesson we will talk about the role of experimentation when trying to fix shaders.


Level of difficulty: Easy
Time required: 30 minutes

Video Walkthrough on YouTube, pt 1 ... Video Walkthrough direct download link, pt 1
Video Walkthrough on YouTube, pt 2 ... Video Walkthrough direct download link, pt 2

Objective

Experiment on a broken shader to see how the pieces work together.
Fix the lava shader so it still works.

Quiz

Fix the water shader in the last room.



After we've found a broken shader, we want to disable or fix them. We can't always do the easiest fix though, and this is where experimentation comes in. This is the puzzle aspect of fixing shaders, where it's not always clear how to fix a shader, even after having seen a lot of variants.

The basic premise is to experiment on the shader by commenting out pieces of the code, and reloading it live with F10, and see any change. As you do these experiments, you can get a feel for what pieces of code affect what part of the image, which can lead you to the best fix.

It can be quite a bit of trial and error, but can allow you to figure out fixes that don't match common patterns, or to find the right spot for a common pattern.



Let's take a look at the basics of 3D graphics, so you can have a very rough idea of how the pieces fit together. This will give you some understanding of how shaders work.


  • Play with the Principles of Shading demo.
    1. Get the demo from here
    2. Run the demo and get an understanding of the wireframe vertexes versus the textures.
    3. Look at the Display menu in particular.
    4. Take a first look at the 0.5*D*T formula as a basic building block.
    5. Example of texture painted onto triangle here
    6. Take a look at the graphics pipeline here
    7. Get a basic idea of the flow of graphics operations, especially noting VertexShaders run before PixelShaders.


After playing with this demo you should have a sense for how 3D graphics are built out of a list of vertices, that make up an array of triangles, that have textures applied to the triangles.



Sometimes we will run into an effect that really cannot be disabled without making the game a lot worse.

In this game, the Lava effect is an example. It's annoyingly broken, and makes those parts of the games unplayable. But, disabling it altogether removes the visual cue of the dangerous areas.

Let's experiment with it, to see if we can make something better.


  • Experiment on lava shaders.
    1. Inspect and experiment on lava in PS.
    2. In pixel shader, try changing each texld to invisible.
    3. Those don't work, look next at the input section with interesting stereo fix.
    4. See that v1 is an input location.
    5. Experiment by changing v1 to null.
    6. Fix lava by killing one texture instead of the entire shader.
    7. optional: Fix the lava from the VertexShader output side, where v1 is created.



Quiz: Go to the end of the demo, and figure out a way to fix the broken water.

  • Fix the water shader at the last level.
    1. Play through to the giant worm at the end, it's not far.
    2. See the water has double-imaging like the water in the hall earlier.
    3. Find the shader for the water effect.
    4. Disable it. Note that it's really not good enough disabled.
    5. Experiment with it to fix it to where it's acceptable.
    6. Save a screenshot to your personal page.


  • optional: Fix the entire game.
    1. Go through at least 3 levels, and find and mark all broken effects.
    2. Disable all broken effects.
    3. Fix the lava effect by disabling the texture.
    4. Save your complete list of modified shaders to your personal page.