Created
February 22, 2021 17:09
-
-
Save abesmon/babe3481da4596b5a37477f74141f8ac to your computer and use it in GitHub Desktop.
Interior mapping made for TouchDesigner in GLSL
This file contains hidden or 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
// Example Vertex Shader | |
out v2f { | |
flat int cameraIndex; | |
vec3 p; | |
vec4 pos; | |
vec2 uv; | |
mat3 tbn; | |
} oVert; | |
in vec4 T; | |
vec3 rand3(float co){ | |
return fract(sin(co * vec3(12.9898,78.233,43.2316)) * 43758.5453); | |
} | |
void main() | |
{ | |
oVert.p = P; | |
vec4 worldSpacePos = TDDeform(P); | |
oVert.pos = worldSpacePos; | |
vec3 texcoord = TDInstanceTexCoord(uv[0]); | |
oVert.uv.st = texcoord.st; | |
oVert.cameraIndex = TDCameraIndex(); | |
vec3 worldSpaceT = normalize(TDDeformNorm(T.xyz)); | |
vec3 worldSpaceN = normalize(TDDeformNorm(N)); | |
oVert.tbn = TDCreateTBNMatrix(worldSpaceN, worldSpaceT, T.w); | |
gl_Position = TDWorldToProj(worldSpacePos); | |
} |
This file contains hidden or 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
uniform sampler2D mapTex; | |
uniform sampler2D wallOut; | |
uniform vec4 uTilingOffset; | |
in v2f { | |
flat int cameraIndex; | |
vec3 p; | |
vec4 pos; | |
vec2 uv; | |
mat3 tbn; | |
} iVert; | |
out vec4 fragColor; | |
vec4 over(vec4 front, vec4 backv) { | |
return mix(backv, front, front.a); | |
} | |
void main() | |
{ | |
TDCheckDiscard(); | |
vec4 color = vec4(1.0); | |
vec3 viewVec = normalize(iVert.pos.xyz - uTDMats[iVert.cameraIndex].camInverse[3].xyz); | |
vec3 uvw = iVert.p * uTilingOffset.xyx * 0.999 + uTilingOffset.zwz; | |
viewVec *= uTilingOffset.xyx; | |
vec3 roomUVW = fract(uvw); | |
vec3 pos = roomUVW * 2.0 - 1.0; | |
vec3 id = 1.0 / viewVec; | |
vec3 k = abs(id) - pos * id; | |
float kMin = min(min(k.x, k.y), k.z); | |
pos += kMin * viewVec; | |
pos = normalize(pos); | |
color = texture(mapTex, TDCubeMapToEquirectangular(pos)); | |
color = over(texture(wallOut, iVert.uv), color); | |
TDAlphaTest(color.a); | |
fragColor = TDOutputSwizzle(color); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment