You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

voxelvert.vert.glsl 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #version 450
  2. layout(location = 0) in uint position;
  3. layout(location = 1) in uint face_attrib;
  4. layout(location = 2) in uint light;
  5. uniform mat4 proj, view, model; //transform matrix
  6. out vec3 texCoordInterp;
  7. out vec3 lightDataInterp;
  8. out vec4 eyeSpacePos;
  9. void main() {
  10. vec3 pos_unpacked;
  11. pos_unpacked.x = float((position >> 8u) & 15u) / 15.0f;
  12. pos_unpacked.y = float((position >> 4u) & 15u) / 15.0f;
  13. pos_unpacked.z = float((position) & 15u) / 15.0f;
  14. vec2 uv_unpacked;
  15. uv_unpacked.x = float((position >> 16u) & 15u) / 15.0f;
  16. uv_unpacked.y = float((position >> 12u) & 15u) / 15.0f;
  17. vec3 offset_unpacked;
  18. offset_unpacked.x = float((face_attrib >> 10u) & 31u);
  19. offset_unpacked.y = float((face_attrib >> 5u) & 31u);
  20. offset_unpacked.z = float((face_attrib) & 31u);
  21. float tex_index = float(face_attrib >> 15u);
  22. vec4 light_unpacked;
  23. light_unpacked.x = float((light >> 12u) & 15u) / 15.0f;
  24. light_unpacked.y = float((light >> 8u) & 15u) / 15.0f;
  25. light_unpacked.z = float((light >> 4u) & 15u) / 15.0f;
  26. light_unpacked.w = float((light) & 15u) / 15.0f;
  27. vec3 sun_color = vec3(1.0f, 1.0f, 1.0f) * light_unpacked.w;
  28. vec3 light_color = vec3(max(light_unpacked.x, sun_color.x),
  29. max(light_unpacked.y, sun_color.y),
  30. max(light_unpacked.z, sun_color.z));
  31. vec3 final_position = pos_unpacked + offset_unpacked;
  32. vec4 eyeSpacePosVert = view * model * vec4(final_position, 1.0);
  33. gl_Position = proj * eyeSpacePosVert;
  34. texCoordInterp = vec3(uv_unpacked, tex_index);//texCoord;
  35. lightDataInterp = light_color;
  36. eyeSpacePos = eyeSpacePosVert;
  37. }