fs_debugdraw_fill_lit.sc 921 B

1234567891011121314151617181920212223242526272829303132333435
  1. $input v_view, v_world
  2. /*
  3. * Copyright 2011-2025 Branimir Karadzic. All rights reserved.
  4. * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
  5. */
  6. #include <bgfx_shader.sh>
  7. uniform vec4 u_params[4];
  8. #define u_lightDir u_params[0].xyz
  9. #define u_shininess u_params[0].w
  10. #define u_skyColor u_params[1].xyz
  11. #define u_groundColor u_params[2].xyz
  12. #define u_matColor u_params[3]
  13. void main()
  14. {
  15. vec3 normal = normalize(cross(dFdx(v_world), dFdy(v_world) ) );
  16. vec3 viewDir = -normalize(v_view);
  17. float ndotl = dot(normal, u_lightDir);
  18. vec3 diffuse = mix(u_groundColor, u_skyColor, ndotl*0.5 + 0.5) * u_matColor.xyz;
  19. #if 0
  20. vec3 reflected = 2.0*ndotl*normal - u_lightDir;
  21. float rdotv = dot(reflected, viewDir);
  22. float spec = step(0.0, ndotl) * pow(max(0.0, rdotv), u_shininess);
  23. #else
  24. float spec = 0.0;
  25. #endif
  26. gl_FragColor = vec4(diffuse + vec3_splat(spec), u_matColor.w);
  27. }