EntityBlend.htm 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <html>
  2. <head>
  3. <title>Blitz3D Docs</title>
  4. <link rel=stylesheet href=../css/commands.css type=text/css>
  5. </head>
  6. <body>
  7. <h1>EntityBlend Entity, Blend</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. Entity - Entity handle <br />
  13. <br />
  14. Blend - Blend mode of the entity. <br />
  15. 1: Alpha (default) <br />
  16. 2: Multiply <br />
  17. 3: Add
  18. </td>
  19. </tr>
  20. </table>
  21. <h1>Description</h1>
  22. <table>
  23. <tr>
  24. <td>
  25. Sets the blending mode of an entity. This blending mode determines the way in which the new RGBA of the pixel being rendered is combined with the RGB of the background. <br />
  26. <br />
  27. To calculate the new RGBA of the pixel being rendered, the texture RGBA for the pixel (see <a class=small href=../3d_commands/TextureBlend.htm>TextureBlend</a> for more information on how the texture RGBA is calculated) is taken, its alpha component multiplied by the entities/brushes (where applicable) alpha value and its color compentent multiplied by the entities/brushes colour. This is the RGBA which will then be blended into the background pixel, and how this is done depends on the EntityBlend value. <br />
  28. <br />
  29. Alpha: <br />
  30. This blends the pixels according to the Alpha value. This is rougly done to the formula: <br />
  31. <br />
  32. Rr = ( An * Rn ) + ( ( 1.0 - An ) * Ro ) <br />
  33. Gr = ( An * Gn ) + ( ( 1.0 - An ) * Go ) <br />
  34. Br = ( An * Bn ) + ( ( 1.0 - An ) * Bo ) <br />
  35. <br />
  36. Where R = Red, G = Green, B = Blue, n = new pixel colour values, r = resultant colour values, o = old pixel colour values. <br />
  37. <br />
  38. Alpha blending is the default blending mode and is used with most world objects. <br />
  39. <br />
  40. Multiply: <br />
  41. This blend mode will darken the underlying pixels. If you think of each RGB value as being on a scale from 0% to 100%, where 0 = 0% and 255 = 100%, the multiply blend mode will multiply the red, green and blue values individually together in order to get the new RGB value, roughly according to: <br />
  42. <br />
  43. Rr = ( ( Rn / 255.0 ) * ( Ro / 255.0 ) ) * 255.0 <br />
  44. Gr = ( ( Gn / 255.0 ) * ( Go / 255.0 ) ) * 255.0 <br />
  45. Br = ( ( Bn / 255.0 ) * ( Bo / 255.0 ) ) * 255.0 <br />
  46. <br />
  47. The alpha value has no effect with multiplicative blending. Blending a RGB value of 255, 255, 255 will make no difference, while an RGB value of 128, 128, 128 will darken the pixels by a factor of 2 and an RGB value of 0, 0, 0 will completely blacken out the resultant pixels. An RGB value of 0, 255, 255 will remove the red component of the underlying pixel while leaving the other color values <br />
  48. untouched. <br />
  49. <br />
  50. Multiply blending is most often used for lightmaps, shadows or anything else that needs to 'darken' the resultant pixels. <br />
  51. <br />
  52. Add: <br />
  53. Additive blending will add the new color values to the old, roughly according to: <br />
  54. <br />
  55. Rr = ( Rn * An ) + Ro <br />
  56. Gr = ( Gn * An ) + Go <br />
  57. Br = ( Bn * An ) + Bo <br />
  58. <br />
  59. The resultant RGB values are clipped out at 255, meaning that multiple additive effects can quickly cause visible banding from smooth gradients. <br />
  60. <br />
  61. Additive blending is extremely useful for effects such as laser shots and fire.
  62. <br>
  63. <br>
  64. See also: <a class=small href=TextureBlend.htm>TextureBlend</a>, <a class=small href=EntityAlpha.htm>EntityAlpha</a>.
  65. </td>
  66. </tr>
  67. </table>
  68. <h1><a href=../3d_examples/EntityBlend.bb>Example</a></h1>
  69. <table>
  70. <tr>
  71. <td>
  72. Graphics3D 640,480 <br />
  73. <br />
  74. SetBuffer BackBuffer() <br />
  75. <br />
  76. SeedRnd MilliSecs() <br />
  77. <br />
  78. <br />
  79. ; create camera <br />
  80. camera=CreateCamera() <br />
  81. CameraClsColor camera,160,160,160 <br />
  82. PositionEntity camera,0,0,-30 <br />
  83. middle=CreatePivot() <br />
  84. EntityParent camera,middle <br />
  85. <br />
  86. ; create add texture - white cirlce on a black background <br />
  87. For n=0 To 50 <br />
  88. Color 5+(n*5),5+(n*5),5+(n*5) <br />
  89. Oval 10+n,10+n,236-(n*2),236-(n*2),1 <br />
  90. Next <br />
  91. <br />
  92. blob_tex=CreateTexture(256,256) <br />
  93. blob=CreateImage(256,256) <br />
  94. GrabImage blob,0,0 <br />
  95. CopyRect 0,0,256,256,0,0,ImageBuffer(blob),TextureBuffer(blob_tex) <br />
  96. FreeImage blob <br />
  97. <br />
  98. max_blobs=100 <br />
  99. <br />
  100. ; create blobs using add blend mode <br />
  101. Dim blobs(max_blobs) ; blob sprites <br />
  102. Dim xyblobs#(max_blobs,2) ; blob vector <br />
  103. <br />
  104. For n=0 To max_blobs <br />
  105. blobs(n)=CreateSprite() <br />
  106. EntityFX blobs(n),1 <br />
  107. EntityBlend blobs(n),3 ;set blend mode to add <br />
  108. EntityTexture blobs(n),blob_tex <br />
  109. xyblobs(n,0)=Rnd(-.1,.1) <br />
  110. xyblobs(n,1)=Rnd(-.1,.1) <br />
  111. xyblobs(n,2)=Rnd(-.1,.1) <br />
  112. EntityColor blobs(n),Rand(0,255),Rand(0,255),Rand(0,255) ;give it a colour <br />
  113. Next <br />
  114. <br />
  115. ; create cube texture <br />
  116. Color 255,255,255 <br />
  117. Rect 0,0,256,256,1 <br />
  118. For n=0 To 7 <br />
  119. If n=0 Then Color 0,0,0 <br />
  120. If n=1 Then Color 0,0,255 <br />
  121. If n=2 Then Color 0,255,0 <br />
  122. If n=3 Then Color 0,255,255 <br />
  123. If n=4 Then Color 255,0,0 <br />
  124. If n=5 Then Color 255,0,255 <br />
  125. If n=6 Then Color 255,255,0 <br />
  126. If n=7 Then Color 255,255,255 <br />
  127. Rect n*32,n*32,32,32,1 <br />
  128. Next <br />
  129. Color 0,0,0 <br />
  130. For n=0 To 255 Step 32 <br />
  131. Line 0,n,255,n <br />
  132. Line n,0,n,255 <br />
  133. Next <br />
  134. <br />
  135. cube_tex=CreateTexture(256,256) <br />
  136. cube=CreateImage(256,256) <br />
  137. GrabImage cube,0,0 <br />
  138. CopyRect 0,0,256,256,0,0,ImageBuffer(cube),TextureBuffer(cube_tex) <br />
  139. FreeImage cube <br />
  140. <br />
  141. ; create cube <br />
  142. cube=CreateCube() <br />
  143. ScaleEntity cube,11,11,11 <br />
  144. EntityTexture cube,cube_tex <br />
  145. EntityFX cube,17 ;set fullbright and 2 sided textures <br />
  146. EntityBlend cube,2 ;set multiply blend <br />
  147. <br />
  148. Repeat <br />
  149. <br />
  150. ; move the blobs around <br />
  151. For n=0 To max_blobs <br />
  152. MoveEntity blobs(n),xyblobs(n,0),xyblobs(n,1),xyblobs(n,2) <br />
  153. ;bounce off sides <br />
  154. If EntityX(blobs(n))<-10 Or EntityX(blobs(n))>10 Then xyblobs(n,0)=-xyblobs(n,0) <br />
  155. If EntityY(blobs(n))<-10 Or EntityY(blobs(n))>10 Then xyblobs(n,1)=-xyblobs(n,1) <br />
  156. If EntityZ(blobs(n))<-10 Or EntityZ(blobs(n))>10 Then xyblobs(n,2)=-xyblobs(n,2) <br />
  157. Next <br />
  158. <br />
  159. ; turn camera <br />
  160. TurnEntity middle,.1,.2,.3 <br />
  161. <br />
  162. <br />
  163. UpdateWorld <br />
  164. RenderWorld <br />
  165. Flip <br />
  166. <br />
  167. <br />
  168. Until KeyHit(1)
  169. </td>
  170. </tr>
  171. </table>
  172. <br>
  173. <a target=_top href=../index.htm>Index</a><br>
  174. <br>
  175. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=EntityBlend&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  176. </html>