Created
January 9, 2019 20:29
-
-
Save wormyrocks/cf884b558aff57c291cb2a9fe684888c to your computer and use it in GitHub Desktop.
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
import math | |
import json | |
# Generates glsl shader file based on visual calibration file | |
calib = json.load(open("visual.json")) | |
def v(n): | |
return calib[n]['value'] | |
views_x = 5 | |
views_y = 9 | |
# Panel resolution | |
size = (int(v('screenW')), int(v('screenH'))) | |
# Physical image width | |
screenInches = size[0]/v('DPI') | |
pitch = v('pitch') * screenInches * math.cos(math.atan(1.0/v('slope'))) | |
tilt = size[1]/(size[0]*v('slope')) | |
subp = 1.0 / (3*size[0]) * pitch | |
center = v('center') | |
shader_text = ''' | |
//!HOOK MAINPRESUB | |
//!DESC Looking Glass Quilt renderer | |
//!BIND HOOKED | |
//!WIDTH ''' + str(size[0]) + ''' | |
//!HEIGHT ''' + str(size[1]) + ''' | |
const float pitch = '''+str(pitch)+'''; | |
const float center = '''+str(center)+'''; | |
const float tilt = '''+str(tilt)+'''; | |
const float subp = '''+str(subp)+'''; | |
const vec2 tiles = vec2('''+str(views_x)+''','''+str(views_y)+'''); | |
vec2 quilt_map(vec2 pos, float a) { | |
// Y major positive direction, X minor negative direction | |
vec2 tile = vec2(tiles.x-1,0), dir=vec2(-1,1); | |
a = fract(a)*tiles.y; | |
tile.y += dir.y*floor(a); | |
a = fract(a)*tiles.x; | |
tile.x += dir.x*floor(a); | |
return (tile+pos)/tiles; | |
} | |
vec4 hook() { | |
vec4 res; | |
float a; | |
a = (HOOKED_pos.x + (1.0 - HOOKED_pos.y)*tilt)*pitch - center; | |
res.x = HOOKED_tex(quilt_map(HOOKED_pos, a)).x; | |
res.y = HOOKED_tex(quilt_map(HOOKED_pos, a+subp)).y; | |
res.z = HOOKED_tex(quilt_map(HOOKED_pos, a+2*subp)).z; | |
res.w = 1.0; | |
return res; | |
} | |
''' | |
print(shader_text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment