alphaprepass.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import * as THREE from 'three'
  2. type AttributesDescription = {
  3. vPosition:THREE.Vector3
  4. vTexCoord: THREE.Vector2
  5. }
  6. type VaryingDescription = {
  7. d: THREE.Vector2
  8. }
  9. const uniforms = {
  10. uModelViewProjectionMatrix: { value: new THREE.Matrix4 },
  11. uUVOffset: { value: new THREE.Vector2 },
  12. }
  13. export default {
  14. attributesDescription: undefined as AttributesDescription | undefined,
  15. varyingDescription: undefined as VaryingDescription | undefined,
  16. uniforms: uniforms,
  17. vetexShader: `
  18. precision highp float;
  19. uniform mat4 uModelViewProjectionMatrix;
  20. uniform vec2 uUVOffset;
  21. attribute vec3 vPosition;
  22. attribute vec2 vTexCoord;
  23. varying mediump vec2 d;
  24. vec4 mul(mat4 i,vec3 p) //mulPoint
  25. {
  26. return i[0] * p.x + ( i[1] * p.y + ( i[2]*p.z + i[3]) );
  27. }
  28. void main(void)
  29. {
  30. gl_Position= mul( uModelViewProjectionMatrix, vPosition.xyz);
  31. d = vTexCoord + uUVOffset;
  32. }
  33. `,
  34. fragmentShader: `
  35. precision mediump float;
  36. #include <matdither.glsl>
  37. uniform sampler2D tAlbedo;
  38. varying mediump vec2 vUv;
  39. void main()
  40. {
  41. float albedo=texture2D(tAlbedo,vUv).a;
  42. if(albedo<=f(vUv.x))
  43. {
  44. discard;
  45. }
  46. gl_FragColor=vec4(0.0);
  47. }
  48. `
  49. }