Last active
May 21, 2021 20:16
-
-
Save abesmon/6e03aef8cb86673842d23ba713ca02e0 to your computer and use it in GitHub Desktop.
Пример того, как с помощью шейдера можно создать ощущение объема. Шейдер написан для работы с TouchDesigner, но в нем нет ничего такого, что было-бы невозможно адаптировать под другое окружение :) пример: https://www.instagram.com/p/CLh7OsCiSPc/
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 vec3 heights; | |
uniform sampler2D texLayerOne; | |
uniform sampler2D texLayerTwo; | |
uniform sampler2D texLayerThree; | |
uniform sampler2D frontTex; | |
in v2f { | |
flat int cameraIndex; | |
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(uTDMats[iVert.cameraIndex].camInverse[3].xyz - iVert.pos.xyz); | |
vec2 offsetUVOne = ((iVert.tbn * viewVec) * heights.x).xy; | |
vec2 offsetUVTwo = ((iVert.tbn * viewVec) * heights.y).xy; | |
vec2 offsetUVThree = ((iVert.tbn * viewVec) * heights.z).xy; | |
//vec2 UV = iVert.uv - offsetUV; | |
vec4 colorLayerThree = texture(texLayerThree, clamp(iVert.uv - offsetUVThree, 0, 1)); | |
vec4 colorLayerTwo = texture(texLayerTwo, clamp(iVert.uv - offsetUVTwo, 0, 1)); | |
vec4 colorLayerOne = texture(texLayerOne, clamp(iVert.uv - offsetUVOne, 0, 1)); | |
vec4 colorFrontTex = texture(frontTex, iVert.uv); | |
color = colorLayerThree; | |
color = over(colorLayerTwo, color); | |
color = over(colorLayerOne, color); | |
color = over(colorFrontTex, color); | |
TDAlphaTest(color.a); | |
fragColor = TDOutputSwizzle(color); | |
} |
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
out v2f { | |
flat int cameraIndex; | |
vec4 pos; | |
vec2 uv; | |
mat3 tbn; | |
} oVert; | |
in vec4 T; | |
void main() | |
{ | |
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment