From 8ec9ec2ff2c9cbba3402d83ec804aea1963a78c9 Mon Sep 17 00:00:00 2001 From: Josef Pelz Date: Tue, 28 May 2024 14:11:41 +0200 Subject: [PATCH] Fixed Cutoff and added scaling/translation and depth output for shadows. --- targets/touchDesigner.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/targets/touchDesigner.js b/targets/touchDesigner.js index 6bc17b0..79754c1 100644 --- a/targets/touchDesigner.js +++ b/targets/touchDesigner.js @@ -42,7 +42,6 @@ in Vertex #define sculptureCenter iVert.sculptureCenter; #define worldPos iVert.worldSpacePos layout(location = 0) out vec4 oFragColor[TD_NUM_COLOR_BUFFERS]; -out float depthTexture; `; let TDFooter = ` @@ -55,11 +54,13 @@ void main() vec3 camPos = uTDMats[iVert.cameraIndex].camInverse[3].xyz; // Raymarching - vec3 rayOrigin = iVert.worldSpacePos.xyz - sculptureCenter; - vec3 rayDirection = normalize(iVert.worldSpacePos.xyz-camPos); - rayOrigin -= rayDirection*2.0; + vec3 rayOrigin = (uTDMats[iVert.cameraIndex].worldInverse*vec4(camPos,1)).xyz; + vec3 rayDirection = (vec4(normalize(iVert.worldSpacePos.xyz-camPos),1)).xyz; + float t = intersect(rayOrigin, rayDirection, stepSize); - depthTexture = t; + vec4 T = uTDMats[iVert.cameraIndex].proj*vec4(0,0,-t,1); + gl_FragDepth = T.z/T.w; + vec3 hitP = (uTDMats[iVert.cameraIndex].world*vec4(rayOrigin+t*rayDirection,1)).xyz; vec4 outcol = vec4(0.0, 0.0, 0.0, 0.0); vec3 diffuseSum = vec3(0.0, 0.0, 0.0); @@ -70,7 +71,7 @@ void main() vec3 outputColor = vec3(0.); // vec3 normal = normalize(worldSpaceNorm.xyz); - if(t < 2.5) { + if(t < 100) { vec3 p = (rayOrigin + rayDirection*t); vec3 normal = calcNormal(p); @@ -157,7 +158,7 @@ void main() res = TDLightingPBR(i, pbrDiffuseColor, pbrSpecularColor, - iVert.worldSpacePos.xyz, + hitP+viewVec*0.001, normal, uShadowStrength, uShadowColor, viewVec,