Difference between revisions of "Canonical Stereo Code"

From Bo3b's School for Shaderhackers
Jump to: navigation, search
(Created page with " <nowiki> ... // 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 th...")
 
Line 1: Line 1:
  
  <nowiki>
+
  <syntaxhighlight lang="cpp">
 
...
 
...
 
// Sampler used to fetch stereo params,  
 
// Sampler used to fetch stereo params,  
Line 29: Line 29:
 
add r0.x, r0.x, r30.z
 
add r0.x, r0.x, r30.z
  
</nowiki>
+
</syntaxhighlight>
  
  

Revision as of 22:10, 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 Helix's 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, it's less useful to fully document 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.

// 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