@@ -42,7 +42,6 @@ in Vertex
42
42
#define sculptureCenter iVert.sculptureCenter;
43
43
#define worldPos iVert.worldSpacePos
44
44
layout(location = 0) out vec4 oFragColor[TD_NUM_COLOR_BUFFERS];
45
- out float depthTexture;
46
45
` ;
47
46
48
47
let TDFooter = `
@@ -55,11 +54,13 @@ void main()
55
54
vec3 camPos = uTDMats[iVert.cameraIndex].camInverse[3].xyz;
56
55
57
56
// 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
+
61
60
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;
63
64
64
65
vec4 outcol = vec4(0.0, 0.0, 0.0, 0.0);
65
66
vec3 diffuseSum = vec3(0.0, 0.0, 0.0);
@@ -70,7 +71,7 @@ void main()
70
71
vec3 outputColor = vec3(0.);
71
72
72
73
// vec3 normal = normalize(worldSpaceNorm.xyz);
73
- if(t < 2.5 ) {
74
+ if(t < 100 ) {
74
75
vec3 p = (rayOrigin + rayDirection*t);
75
76
vec3 normal = calcNormal(p);
76
77
@@ -157,7 +158,7 @@ void main()
157
158
res = TDLightingPBR(i,
158
159
pbrDiffuseColor,
159
160
pbrSpecularColor,
160
- iVert.worldSpacePos.xyz ,
161
+ hitP+viewVec*0.001 ,
161
162
normal,
162
163
uShadowStrength, uShadowColor,
163
164
viewVec,
0 commit comments