Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

68 строки
2.2 KiB

  1. #if defined(BUMPED)
  2. void applyLight(vec4 position, mat3 tangentSpaceTransformMatrix)
  3. {
  4. #if (defined(SPECULAR) || (POINT_LIGHT_COUNT > 0) || (SPOT_LIGHT_COUNT > 0))
  5. vec4 positionWorldViewSpace = u_worldViewMatrix * position;
  6. #endif
  7. #if (DIRECTIONAL_LIGHT_COUNT > 0)
  8. for (int i = 0; i < DIRECTIONAL_LIGHT_COUNT; ++i)
  9. {
  10. // Transform light direction to tangent space
  11. v_directionalLightDirection[i] = tangentSpaceTransformMatrix * u_directionalLightDirection[i];
  12. }
  13. #endif
  14. #if (POINT_LIGHT_COUNT > 0)
  15. for (int i = 0; i < POINT_LIGHT_COUNT; ++i)
  16. {
  17. // Compute the vertex to light direction, in tangent space
  18. v_vertexToPointLightDirection[i] = tangentSpaceTransformMatrix * (u_pointLightPosition[i] - positionWorldViewSpace.xyz);
  19. }
  20. #endif
  21. #if (SPOT_LIGHT_COUNT > 0)
  22. for (int i = 0; i < SPOT_LIGHT_COUNT; ++i)
  23. {
  24. // Compute the vertex to light direction, in tangent space
  25. v_vertexToSpotLightDirection[i] = tangentSpaceTransformMatrix * (u_spotLightPosition[i] - positionWorldViewSpace.xyz);
  26. v_spotLightDirection[i] = tangentSpaceTransformMatrix * u_spotLightDirection[i];
  27. }
  28. #endif
  29. #if defined(SPECULAR)
  30. // Compute camera direction and transform it to tangent space.
  31. v_cameraDirection = tangentSpaceTransformMatrix * (u_cameraPosition - positionWorldViewSpace.xyz);
  32. #endif
  33. }
  34. #else
  35. void applyLight(vec4 position)
  36. {
  37. #if defined(SPECULAR) || (POINT_LIGHT_COUNT > 0) || (SPOT_LIGHT_COUNT > 0)
  38. vec4 positionWorldViewSpace = u_worldViewMatrix * position;
  39. #endif
  40. #if (POINT_LIGHT_COUNT > 0)
  41. for (int i = 0; i < POINT_LIGHT_COUNT; ++i)
  42. {
  43. // Compute the light direction with light position and the vertex position.
  44. v_vertexToPointLightDirection[i] = u_pointLightPosition[i] - positionWorldViewSpace.xyz;
  45. }
  46. #endif
  47. #if (SPOT_LIGHT_COUNT > 0)
  48. for (int i = 0; i < SPOT_LIGHT_COUNT; ++i)
  49. {
  50. // Compute the light direction with light position and the vertex position.
  51. v_vertexToSpotLightDirection[i] = u_spotLightPosition[i] - positionWorldViewSpace.xyz;
  52. }
  53. #endif
  54. #if defined(SPECULAR)
  55. v_cameraDirection = u_cameraPosition - positionWorldViewSpace.xyz;
  56. #endif
  57. }
  58. #endif