Last active
December 4, 2021 17:18
-
-
Save ogrew/d14b7928b7832f95000c53842c0e7c3b to your computer and use it in GitHub Desktop.
Reverse Perspective Camera in TouchDesigner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reverse Perspective projection | |
eps = 0.000001 | |
def onSetupParameters(scriptOp): | |
params = scriptOp.appendCustomPage('Parameters') | |
params.appendFloat('Perspective', label='Perspective') | |
params.appendFloat('Distance', label='Distance') | |
params.appendFloat('Ratio', label='Aspect Ratio') | |
params.appendFloat('Size', label='Orthographic Size') | |
return | |
def onCook(scriptOp): | |
scriptOp.clear() | |
prsp = scriptOp.par.Perspective / 100 | |
dist = - scriptOp.par.Distance | |
ratio = scriptOp.par.Ratio + eps | |
size = scriptOp.par.Size + eps | |
m00 = 1 / size / ratio | |
m11 = 1 / size | |
m22 = - eps | |
m23 = prsp | |
m32 = prsp | |
m33 = 1.0 - dist * prsp | |
scriptOp.insertRow([m00, 0, 0, 0], 0) | |
scriptOp.insertRow([0, m11, 0, 0], 1) | |
scriptOp.insertRow([0, 0, m22, m23], 2) | |
scriptOp.insertRow([0, 0, m32, m33], 3) | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment