1
0

__BulbRendererDefineAccumulateSoft.gml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // Feather disable all
  2. function __BulbRendererDefineAccumulateSoft()
  3. {
  4. __AccumulateSoftLights = function(_boundaryL, _boundaryT, _boundaryR, _boundaryB, _cameraCX, _cameraCY, _cameraW, _cameraH, _cameraCos, _cameraSin, _normalCoeff)
  5. {
  6. static _shdBulbSoftShadows_u_vLight = shader_get_uniform(__shdBulbSoftShadows, "u_vLight" );
  7. static _shdBulbSoftShadowsSunlight_u_vLightVector = shader_get_uniform(__shdBulbSoftShadowsSunlight, "u_vLightVector");
  8. static _shdBulbLightWithNormalMap_u_vInfo = shader_get_uniform(__shdBulbLightWithNormalMap, "u_vInfo" );
  9. static _shdBulbLightWithoutNormalMap_u_fIntensity = shader_get_uniform(__shdBulbLightWithoutNormalMap, "u_fIntensity" );
  10. static _shdBulbSunlightWithNormalMap_u_vSunInfo = shader_get_uniform(__shdBulbSunlightWithNormalMap, "u_vInfo" );
  11. static _sshdBulbSunlightWithoutNormalMap_u_fIntensity = shader_get_uniform(__shdBulbSunlightWithoutNormalMap, "u_fIntensity" );
  12. var _staticVBuffer = __staticVBuffer;
  13. var _dynamicVBuffer = __dynamicVBuffer;
  14. var _rendererNormalMap = normalMap;
  15. if (_rendererNormalMap)
  16. {
  17. shader_set(__shdBulbLightWithNormalMap);
  18. texture_set_stage(shader_get_sampler_index(__shdBulbLightWithNormalMap, "u_sNormalMap"), surface_get_texture(GetNormalMapSurface()));
  19. shader_set_uniform_f(shader_get_uniform(__shdBulbLightWithNormalMap, "u_vCamera"), _cameraCX, _cameraCY, _cameraW/2, _cameraH/2);
  20. shader_set_uniform_f(shader_get_uniform(__shdBulbLightWithNormalMap, "u_vCameraVector"), _cameraCos, _cameraSin);
  21. shader_set_uniform_f(shader_get_uniform(__shdBulbLightWithNormalMap, "u_fSpecularIntensity"), hdr? BULB_SPECULAR_MAP_INTENSITY : 0);
  22. shader_set(__shdBulbSunlightWithNormalMap);
  23. shader_set_uniform_f(shader_get_uniform(__shdBulbSunlightWithNormalMap, "u_fSpecularIntensity"), hdr? BULB_SPECULAR_MAP_INTENSITY : 0);
  24. }
  25. var _i = 0;
  26. repeat(array_length(__lightsArray))
  27. {
  28. var _weak = __lightsArray[_i];
  29. if (!weak_ref_alive(_weak) || _weak.ref.__destroyed)
  30. {
  31. array_delete(__lightsArray, _i, 1);
  32. }
  33. else
  34. {
  35. with(_weak.ref)
  36. {
  37. if (visible)
  38. {
  39. __CheckSpriteDimensions();
  40. //If this light is active, do some drawing
  41. if (__IsOnScreen(_boundaryL, _boundaryT, _boundaryR, _boundaryB))
  42. {
  43. if (castShadows)
  44. {
  45. //Only write into the alpha channel
  46. gpu_set_colorwriteenable(false, false, false, true);
  47. //Clear the alpha channel for the light's visual area
  48. gpu_set_blendmode_ext(bm_one, bm_zero);
  49. draw_sprite_ext(sprite, image,
  50. x, y,
  51. xscale, yscale, angle,
  52. c_black, 1);
  53. //Cut out shadows in the alpha channel
  54. gpu_set_blendmode(bm_subtract);
  55. shader_set(__shdBulbSoftShadows);
  56. shader_set_uniform_f(_shdBulbSoftShadows_u_vLight, x, y, penumbraSize);
  57. vertex_submit(_staticVBuffer, pr_trianglelist, -1);
  58. vertex_submit(_dynamicVBuffer, pr_trianglelist, -1);
  59. //Set the light sprite to borrowing the alpha channel already on the surface
  60. gpu_set_colorwriteenable(true, true, true, false);
  61. gpu_set_blendmode_ext(bm_dest_alpha, bm_one);
  62. //Draw light sprite
  63. if (_rendererNormalMap && normalMap)
  64. {
  65. shader_set(__shdBulbLightWithNormalMap);
  66. shader_set_uniform_f(_shdBulbLightWithNormalMap_u_vInfo, x, y, normalMapZ, intensity);
  67. }
  68. else
  69. {
  70. shader_set(__shdBulbLightWithoutNormalMap);
  71. shader_set_uniform_f(_shdBulbLightWithoutNormalMap_u_fIntensity, intensity);
  72. }
  73. draw_sprite_ext(sprite, image,
  74. x, y,
  75. xscale, yscale, angle,
  76. blend, 1);
  77. }
  78. else
  79. {
  80. //No shadows - draw the light sprite normally
  81. gpu_set_blendmode(bm_add);
  82. if (_rendererNormalMap && normalMap)
  83. {
  84. shader_set(__shdBulbLightWithNormalMap);
  85. shader_set_uniform_f(_shdBulbLightWithNormalMap_u_vInfo, x, y, normalMapZ, intensity);
  86. }
  87. else
  88. {
  89. shader_set(__shdBulbLightWithoutNormalMap);
  90. shader_set_uniform_f(_shdBulbLightWithoutNormalMap_u_fIntensity, intensity);
  91. }
  92. draw_sprite_ext(sprite, image,
  93. x, y,
  94. xscale, yscale, angle,
  95. blend, 1);
  96. }
  97. }
  98. }
  99. }
  100. ++_i;
  101. }
  102. }
  103. var _i = 0;
  104. repeat(array_length(__sunlightArray))
  105. {
  106. var _weak = __sunlightArray[_i];
  107. if (!weak_ref_alive(_weak) || _weak.ref.__destroyed)
  108. {
  109. array_delete(__sunlightArray, _i, 1);
  110. }
  111. else
  112. {
  113. with(_weak.ref)
  114. {
  115. if (visible)
  116. {
  117. //Only write into the alpha channel
  118. gpu_set_colorwriteenable(false, false, false, true);
  119. //Clear the alpha channel for the light's visual area
  120. gpu_set_blendmode_ext(bm_one, bm_zero);
  121. draw_sprite_ext(__sprBulbPixel, 0, _boundaryL, _boundaryT, _boundaryR - _boundaryL, _boundaryB - _boundaryT, 0, c_black, 1);
  122. //Cut out shadows in the alpha channel
  123. gpu_set_blendmode(bm_subtract);
  124. shader_set(__shdBulbSoftShadowsSunlight);
  125. shader_set_uniform_f(_shdBulbSoftShadowsSunlight_u_vLightVector, dcos(angle), -dsin(angle), penumbraSize);
  126. vertex_submit(_staticVBuffer, pr_trianglelist, -1);
  127. vertex_submit(_dynamicVBuffer, pr_trianglelist, -1);
  128. //Set the light sprite to borrowing the alpha channel already on the surface
  129. gpu_set_colorwriteenable(true, true, true, false);
  130. gpu_set_blendmode_ext(bm_dest_alpha, bm_one);
  131. //Draw light sprite
  132. if (_rendererNormalMap && normalMap)
  133. {
  134. shader_set(__shdBulbSunlightWithNormalMap);
  135. shader_set_uniform_f(_shdBulbSunlightWithNormalMap_u_vSunInfo, dcos(angle), -dsin(angle), normalMapZ, intensity);
  136. }
  137. else
  138. {
  139. shader_set(__shdBulbSunlightWithoutNormalMap);
  140. shader_set_uniform_f(_sshdBulbSunlightWithoutNormalMap_u_fIntensity, intensity);
  141. }
  142. draw_sprite_ext(__sprBulbPixel, 0, _boundaryL, _boundaryT, _boundaryR - _boundaryL, _boundaryB - _boundaryT, 0, blend, 1);
  143. }
  144. }
  145. ++_i;
  146. }
  147. }
  148. shader_reset();
  149. gpu_set_blendmode(bm_normal);
  150. }
  151. }