Skip to content

Commit bc7e426

Browse files
authored
Merge pull request #107 from JosefPelz/patch-1
Fixed Cutoff and added scaling/translation and depth output for shadows.
2 parents 9361f05 + 8ec9ec2 commit bc7e426

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

targets/touchDesigner.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ in Vertex
4242
#define sculptureCenter iVert.sculptureCenter;
4343
#define worldPos iVert.worldSpacePos
4444
layout(location = 0) out vec4 oFragColor[TD_NUM_COLOR_BUFFERS];
45-
out float depthTexture;
4645
`;
4746

4847
let TDFooter = `
@@ -55,11 +54,13 @@ void main()
5554
vec3 camPos = uTDMats[iVert.cameraIndex].camInverse[3].xyz;
5655
5756
// Raymarching
58-
vec3 rayOrigin = iVert.worldSpacePos.xyz - sculptureCenter;
59-
vec3 rayDirection = normalize(iVert.worldSpacePos.xyz-camPos);
60-
rayOrigin -= rayDirection*2.0;
57+
vec3 rayOrigin = (uTDMats[iVert.cameraIndex].worldInverse*vec4(camPos,1)).xyz;
58+
vec3 rayDirection = (vec4(normalize(iVert.worldSpacePos.xyz-camPos),1)).xyz;
59+
6160
float t = intersect(rayOrigin, rayDirection, stepSize);
62-
depthTexture = t;
61+
vec4 T = uTDMats[iVert.cameraIndex].proj*vec4(0,0,-t,1);
62+
gl_FragDepth = T.z/T.w;
63+
vec3 hitP = (uTDMats[iVert.cameraIndex].world*vec4(rayOrigin+t*rayDirection,1)).xyz;
6364
6465
vec4 outcol = vec4(0.0, 0.0, 0.0, 0.0);
6566
vec3 diffuseSum = vec3(0.0, 0.0, 0.0);
@@ -70,7 +71,7 @@ void main()
7071
vec3 outputColor = vec3(0.);
7172
7273
// vec3 normal = normalize(worldSpaceNorm.xyz);
73-
if(t < 2.5) {
74+
if(t < 100) {
7475
vec3 p = (rayOrigin + rayDirection*t);
7576
vec3 normal = calcNormal(p);
7677
@@ -157,7 +158,7 @@ void main()
157158
res = TDLightingPBR(i,
158159
pbrDiffuseColor,
159160
pbrSpecularColor,
160-
iVert.worldSpacePos.xyz,
161+
hitP+viewVec*0.001,
161162
normal,
162163
uShadowStrength, uShadowColor,
163164
viewVec,

0 commit comments

Comments
 (0)