bug2.shader 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. shader_type spatial;
  2. render_mode blend_mix,depth_draw_opaque,cull_back,unshaded;
  3. varying mat4 mtx;
  4. varying mat4 tmtx;
  5. // this is only small part of "comples logic" that ruined because bugs
  6. // every function is valid, should be no error on function-side
  7. vec3 my_normalize3(vec3 v){
  8. float len = length(v);
  9. vec3 ret=vec3(0.);
  10. if(len==0.0)ret= vec3(1.0,0.0,0.0);
  11. else ret= v/len;
  12. return ret;
  13. }
  14. mat4 lookAt(vec3 from, vec3 to, vec3 tup )
  15. {
  16. vec3 forward = my_normalize3(from - to);
  17. if(length(forward.xz)<=0.001)forward.x=0.001;
  18. vec3 right = cross(my_normalize3(tup), forward);
  19. right = my_normalize3(right);
  20. vec3 up = cross(forward, right);
  21. mat4 camToWorld=mat4(1.);
  22. camToWorld[0][0] = right.x;
  23. camToWorld[0][1] = right.y;
  24. camToWorld[0][2] = right.z;
  25. camToWorld[1][0] = up.x;
  26. camToWorld[1][1] = up.y;
  27. camToWorld[1][2] = up.z;
  28. camToWorld[2][0] = forward.x;
  29. camToWorld[2][1] = forward.y;
  30. camToWorld[2][2] = forward.z;
  31. camToWorld[3][0] = from.x;
  32. camToWorld[3][1] = from.y;
  33. camToWorld[3][2] = from.z;
  34. //camToWorld=mat4(vec4(0.),vec4(0.),vec4(0.),vec4(0.,0.,1.,0.)); //not same result with next line
  35. //return mat4(vec4(0.),vec4(0.),vec4(0.),vec4(0.,0.,1.,0.));
  36. return camToWorld;
  37. }
  38. void translate(inout mat4 m, vec3 d){
  39. m[3][0] = d.x;
  40. m[3][1] = d.y;
  41. m[3][2] = d.z;
  42. m[3].xyz=d; //does not matter, both does not work
  43. }
  44. void vertex() {
  45. //mtx=mat4(vec4(0.),vec4(0.),vec4(0.),vec4(0.,0.,1.,0.));//uncomment and comment next line, not same result
  46. //bug
  47. mtx=lookAt(vec3(0.,0.,1.),WORLD_MATRIX[3].xyz,vec3(0.,1.,0.));
  48. tmtx=mtx;
  49. vec3 a=vec3(1.,0.,0.);
  50. vec3 b=vec3(0.,1.,0.);
  51. translate(tmtx,a); //still do nothing
  52. //tmtx[3].xyz=a; //fix still work
  53. mtx[3].xyz=b;
  54. tmtx=mtx; //does not work
  55. }
  56. void fragment() {
  57. vec4 col=vec4(0.);
  58. if(UV.y<0.5)ALBEDO=vec3(abs(WORLD_MATRIX[3].y),0.,0.);
  59. else{
  60. if(UV.x<0.5)ALBEDO = mtx[3].xyz;
  61. else ALBEDO = tmtx[3].xyz; //this blue
  62. }
  63. }