Difference between revisions of "Canonical Stereo Code"

From Bo3b's School for Shaderhackers
Jump to: navigation, search
Line 1: Line 1:
  
<syntaxhighlight lang="cpp">
+
<syntaxhighlight lang="c">
 
...
 
...
 
// Sampler used to fetch stereo params,  
 
// Sampler used to fetch stereo params,  
Line 15: Line 15:
  
 
// Fetch the Separation (r30.x) and Convergence (r30.y)   
 
// Fetch the Separation (r30.x) and Convergence (r30.y)   
// using Helix's NVapi trick
+
// using the Helix NVapi trick
 
texldl r30, c200.z, s0
 
texldl r30, c200.z, s0
  
Line 32: Line 32:
  
  
Another variant that is more concise, but less clear.  As you get more accustomed to seeing this sequence of code, it's less useful to fully document it.
+
Another variant that is more concise, but less clear.  As you get more accustomed to seeing this sequence of code, or are sharing with an expert crowd, it's less necessary to fully document this part, as it is always the same sequence and easy to recognize because of the texldl of 0.0625.
  
<nowiki>
+
<syntaxhighlight lang="c">
 
...
 
...
 
// Stereo correction constants
 
// Stereo correction constants
Line 50: Line 50:
 
add r30.w, r0.w, -r30.y
 
add r30.w, r0.w, -r30.y
 
mad r0.x, r30.x, r30.w, r0.x
 
mad r0.x, r30.x, r30.w, r0.x
 +
</syntaxhighlight>
  
</nowiki>
+
 
 +
Another very common variant you'll see in HelixMod fixes is the four line version, with no comments. This is less optimal than the two above, but is worth seeing to be able to recognize it.
 +
 
 +
<syntaxhighlight lang="c">
 +
...
 +
// Stereo correction constants
 +
dcl_2d s0
 +
def c200, 1.0, 600, 0.0625, 0
 +
...
 +
 
 +
// At this point r0 is the output position, correctly
 +
// placed, but without stereo.
 +
texldl r30, c200.z, s0
 +
add r30.w, r0.w, -r30.y
 +
mul r30.z, r30.x, r30.w
 +
add r0.x, r0.x, r30.z
 +
</syntaxhighlight>

Revision as of 22:28, 20 September 2014

...
// Sampler used to fetch stereo params, 
// and the required constant for txldl in c200.z
dcl_2d s0
def c200, 1.0, 600, 0.0625, 0
...
 
// At this point r0 is the output position, correctly
// placed, but without stereo.
 
// To create stereo effects, we need to calculate:
//  Xnew = Xold + Separation * (W - Convergence)
 
// Fetch the Separation (r30.x) and Convergence (r30.y)  
// using the Helix NVapi trick
texldl r30, c200.z, s0
 
// (W - Convergence)
add r30.w, r0.w, -r30.y
 
// multiply that times Separation for:
//   Separation * (W - Convergence)
mul r30.z, r30.x, r30.w
 
// Add that to Xold for the complete:
//  Xold + Separation * (W - Convergence)
add r0.x, r0.x, r30.z


Another variant that is more concise, but less clear. As you get more accustomed to seeing this sequence of code, or are sharing with an expert crowd, it's less necessary to fully document this part, as it is always the same sequence and easy to recognize because of the texldl of 0.0625.

...
// Stereo correction constants
dcl_2d s0
def c200, 1.0, 600, 0.0625, 0
...
 
// At this point r0 is the output position, correctly
// placed, but without stereo.
 
// To create stereo effects, we need to calculate:
//  Xnew = Xold + Separation * (W - Convergence)
 
texldl r30, c200.z, s0
add r30.w, r0.w, -r30.y
mad r0.x, r30.x, r30.w, r0.x


Another very common variant you'll see in HelixMod fixes is the four line version, with no comments. This is less optimal than the two above, but is worth seeing to be able to recognize it.

...
// Stereo correction constants
dcl_2d s0
def c200, 1.0, 600, 0.0625, 0
...
 
// At this point r0 is the output position, correctly
// placed, but without stereo.
texldl r30, c200.z, s0
add r30.w, r0.w, -r30.y
mul r30.z, r30.x, r30.w
add r0.x, r0.x, r30.z