outlineVert.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import skinningDefines from './skinningDefine';
  2. export default
  3. /* glsl */
  4. `#version 100
  5. uniform highp mat4 u_view;
  6. uniform highp mat4 u_viewInverse;
  7. uniform highp mat4 u_vp;
  8. uniform highp mat4 u_projection;
  9. uniform mat4 u_lightSpaceMatrix;
  10. uniform vec4 u_fogInfos;
  11. uniform vec3 u_fogColor;
  12. uniform float u_gameTime;
  13. uniform float u_aspect;
  14. uniform vec3 u_ambientLight;
  15. uniform vec3 u_lightDir;
  16. uniform vec3 u_lightColor;
  17. uniform vec3 u_shadowColor;
  18. uniform float u_shadowStrength;
  19. uniform float u_shadowBias;
  20. uniform float u_lightWidthPCSS;
  21. uniform float u_blockSizePCSS;
  22. uniform vec4 u_csmFarBounds;
  23. uniform vec4 u_shadowTilingOffsets[4];
  24. uniform mat4 u_csmLightSpaceMatrices[4];
  25. uniform vec3 u_SH[9];
  26. uniform highp mat4 u_world;
  27. uniform float u_outlineWidth;
  28. uniform float u_farthestDistance;
  29. uniform float u_nearestDistance;
  30. uniform float u_offsetZ;
  31. ${skinningDefines}
  32. attribute vec3 a_position;
  33. #ifdef WX_USE_NORMAL
  34. attribute highp vec3 a_normal;
  35. #endif
  36. void main()
  37. {
  38. #ifdef WX_SKINNED
  39. mat4 boneMat = getBoneMat();
  40. mat4 modelViewMatrix = u_view * boneMat;
  41. #else
  42. mat4 modelViewMatrix = u_view * u_world;
  43. #endif
  44. vec4 worldPosition = getSkinningWorldPosition(vec4(a_position, 1.0));
  45. vec3 cameraPosWS = vec3(u_viewInverse[3][0], u_viewInverse[3][1], u_viewInverse[3][2]);
  46. vec4 posCS = u_projection * u_view * worldPosition;
  47. vec3 zeroWS = (u_projection * u_view * getSkinningWorldPosition(vec4(0, 0, 0, 1))).xyz;
  48. float objectDistanceToCamera = distance(zeroWS, cameraPosWS);
  49. float outlineWidth = 0.01 * u_outlineWidth * smoothstep(u_farthestDistance, u_nearestDistance, objectDistanceToCamera);
  50. vec3 normalCS = mat3(u_projection) * (mat3(u_view) * (mat3(u_world) * a_normal));
  51. gl_Position = vec4(posCS.xy + outlineWidth * normalCS.xy, posCS.zw);
  52. float offsetZ = u_offsetZ * (- 0.01);
  53. vec4 cameraPosCS = u_projection * u_view * vec4(cameraPosWS.xyz, 1);
  54. gl_Position.z = gl_Position.z + offsetZ * cameraPosCS.z;
  55. }
  56. `;