Skip to content

Commit

Permalink
Merge pull request #107 from JosefPelz/patch-1
Browse files Browse the repository at this point in the history
Fixed Cutoff and added scaling/translation and depth output for shadows.
  • Loading branch information
torinmb authored May 28, 2024
2 parents 9361f05 + 8ec9ec2 commit bc7e426
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions targets/touchDesigner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -157,7 +158,7 @@ void main()
res = TDLightingPBR(i,
pbrDiffuseColor,
pbrSpecularColor,
iVert.worldSpacePos.xyz,
hitP+viewVec*0.001,
normal,
uShadowStrength, uShadowColor,
viewVec,
Expand Down

0 comments on commit bc7e426

Please sign in to comment.