dilevin / computer-graphics-shader-pipeline

Computer Graphics Assignment about the Shader Pipeline
2 stars 5 forks source link

Normalize not working #21

Closed yeqingxi closed 5 years ago

yeqingxi commented 5 years ago

I'm currently doing snap_to_sphere and for some reason when I normalize the interpolated coordinates, the results aren't normalized (as in they don't have a length of 1). So I'm still getting the edgy sphere instead of the smooth sphere. Any ideas why this is happening? I'm using the function normalize(vector).

Update: I tested the normalize function and it appears to be working, but the result I see is still the edgy planet.

rin-23 commented 5 years ago

are you sure you are saving the output of normalize function into another vector and using it?

So it should be smth like this vec4 interp_pos = interpolate(gl_TessCoord, pos_es_in[0], pos_es_in[1], pos_es_in[2]); then normalize interp_pos and save the result either to some other vector or overwrite interp_pos. Use interp_pos to calculate sphere_fs_in, view_pos_fs_in, normal_fs_in, pos_fs_in

rin-23 commented 5 years ago

Also be careful: interpolate returns vec4 which is a point but when you normalize you should normalize only vec3 part of the vec4 if that makes sense

yeqingxi commented 5 years ago

Oh my god yeah it worked after I normalized only the vec3 part, I forgot that the 4th coordinate is set to 1.0 instead of 0.0 so it actually matters.