bug32.shader 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.));//same as next line
  46. //mtx=lookAt(vec3(0.,0.,1.),WORLD_MATRIX[3].xyz,vec3(0.,1.,0.));
  47. //tmtx=mtx;
  48. tmtx=WORLD_MATRIX; // this fix translate function line 64
  49. vec3 a=vec3(1.,WORLD_MATRIX[3].y,0.);
  50. vec3 b=vec3(0.,1.,0.);
  51. translate(tmtx,a);
  52. //tmtx[3].xyz=a; fix work if comment line 70
  53. mtx[3].xyz=b;
  54. //tmtx=mtx; //does not work
  55. //tmtx[3].xyz=mtx[3].xyz; //does work
  56. //mtx=WORLD_MATRIX; //comment this will ruin line 64 translate function
  57. }
  58. void fragment() {
  59. vec4 col=vec4(0.);
  60. if(UV.y<0.5){
  61. if(UV.x<0.5)ALBEDO=vec3(abs(mtx[3].y),0.,0.);
  62. else ALBEDO=vec3(abs(tmtx[3].y),0.,0.);
  63. }
  64. else{
  65. if(UV.x<0.5)ALBEDO = mtx[3].xyz;
  66. else ALBEDO = tmtx[3].xyz;
  67. }
  68. }