Advertisement
GregroxMun

Procedural Sun Generator

May 11th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 KB | None | 0 0
  1. @Kopernicus:FOR[WHATEVER]
  2. {
  3. @Body[Sun]
  4. {
  5.  
  6. DefineStar
  7. {
  8. //Define a Main Sequence Star from mass in SmallSolar Units.
  9. SolarMass = 0.1
  10. }
  11. StellarProperties
  12. {
  13. mass = 1.988435e28
  14. @mass *= #$../DefineStar/SolarMass$
  15.  
  16. radius = #$../DefineStar/SolarMass$
  17. @radius != 0.74
  18. @radius *= 6.957e7
  19.  
  20. SurfaceArea = #$radius$
  21. @SurfaceArea != 2
  22.  
  23. RelativeSurfaceTemperature = #$../DefineStar/SolarMass$
  24. @RelativeSurfaceTemperature != 0.505
  25.  
  26. SurfaceTemperature = #$RelativeSurfaceTemperature$
  27. @SurfaceTemperature *= 5772
  28.  
  29. TempRatio = #$SurfaceTemperature$
  30. @TempRatio /= 5772
  31.  
  32. TempRatioToTheFourth = #$TempRatio$
  33. @TempRatioToTheFourth != 4
  34.  
  35. StarLuminosity = #$TempRatioToTheFourth$
  36. @StarLuminosity *= #$SurfaceArea$
  37.  
  38. SqrtStarLuminosity = #$StarLuminosity$
  39. @SqrtStarLuminosity != 0.5
  40. }
  41.  
  42. @Properties
  43. {
  44. %mass = #$../StellarProperties/mass$
  45. %radius = #$../StellarProperties/radius$
  46. }
  47.  
  48. !COLOR,* {}
  49. COLOR
  50. {
  51. Temperature = #$../StellarProperties/SurfaceTemperature$
  52. RED = 0
  53. GREEN = 0
  54. BLUE = 0
  55. }
  56.  
  57. @COLOR
  58. {
  59. // Set Temperature = Temperature \ 100
  60. @Temperature /= 100
  61. @Temperature = #$Temperature$.0
  62. @Temperature = #$Temperature[0,.]$
  63. }
  64.  
  65.  
  66.  
  67. // Calculate Red:
  68.  
  69. // If Temperature <= 66 Then
  70. @COLOR:HAS[~Temperature[>66]]
  71. {
  72. // Red = 255
  73. @RED = 1
  74. }
  75. // Else
  76. @COLOR:HAS[#Temperature[>66]]
  77. {
  78. // Red = Temperature - 60
  79. @RED = #$Temperature$
  80. @RED -= 60
  81.  
  82. // Red = 329.698727446 * (Red ^ -0.1332047592)
  83. @RED != -0.1332047592
  84. @RED *= 329.698727446
  85. @RED /= 255
  86. }
  87. // If Red < 0 Then Red = 0
  88. @COLOR:HAS[#RED[<0]]
  89. {
  90. @RED = 0
  91. }
  92. // If Red > 255 Then Red = 255
  93. @COLOR:HAS[#RED[>1]]
  94. {
  95. @RED = 1
  96. }
  97.  
  98.  
  99.  
  100. // Calculate Green:
  101.  
  102. // If Temperature <= 66 Then
  103. @COLOR:HAS[~Temperature[>66]]
  104. {
  105. // Green = Temperature
  106. // Green = 99.4708025861 * Ln(Green) - 161.1195681661
  107. // APPROX TO Green = -0.0431*Temperature^2 + 6.9703*Temperature - 0.206
  108. // REWRITE AS Green = Temperature * (-0.0431*Temperature + 6.9703) - 0.206
  109. @GREEN = #$Temperature$
  110. @GREEN *= -0.0431
  111. @GREEN += 6.9703
  112. @GREEN *= #$Temperature$
  113. @GREEN -= 0.206
  114. @GREEN /= 255
  115. }
  116. // Else
  117. @COLOR:HAS[#Temperature[>66]]
  118. {
  119. // Green = Temperature - 60
  120. @GREEN = #$Temperature$
  121. @GREEN -= 60
  122.  
  123. // Green = 288.1221695283 * (Green ^ -0.0755148492)
  124. @GREEN != -0.0755148492
  125. @GREEN *= 288.1221695283
  126. @GREEN /= 255
  127. }
  128. // If Green < 0 Then Green = 0
  129. @COLOR:HAS[#GREEN[<0]]
  130. {
  131. @GREEN = 0
  132. }
  133. // If Green > 255 Then Green = 255
  134. @COLOR:HAS[#GREEN[>1]]
  135. {
  136. @GREEN = 1
  137. }
  138.  
  139.  
  140.  
  141. // Calculate Blue:
  142.  
  143. // If Temperature >= 66 Then
  144. @COLOR:HAS[~Temperature[<66]]
  145. {
  146. // Blue = 255
  147. @BLUE = 1
  148. }
  149. // If Temperature <= 19 Then
  150. @COLOR:HAS[~Temperature[>19]]
  151. {
  152. // Blue = 0
  153. @BLUE = 0
  154. }
  155. @COLOR:HAS[#Temperature[<66],#Temperature[>19]]
  156. {
  157. // Blue = Temperature - 10
  158. @Temperature -=10
  159.  
  160. // Blue = 138.5177312231 * Ln(Blue) - 305.0447927307
  161. // APPROX TO Blue = -0.0784*Temperature^2 + 10.274*Temperature - 73.434
  162. // REWRITE AS Blue = Temperature*(-0.0784*Temperature+10.274)-73.434
  163. @BLUE = #$Temperature$
  164. @BLUE *= -0.0784
  165. @BLUE += 10.274
  166. @BLUE *= #$Temperature$
  167. @BLUE -= 73.434
  168. @BLUE /= 255
  169.  
  170. // RESTORE Temperature
  171. @Temperature += 10
  172. }
  173. // If Blue < 0 Then Blue = 0
  174. @COLOR:HAS[#BLUE[<0]]
  175. {
  176. @BLUE = 0
  177. }
  178. // If Blue > 255 Then Blue = 255
  179. @COLOR:HAS[#BLUE[>1]]
  180. {
  181. @BLUE = 1
  182. }
  183.  
  184. // APPLY CHANGES
  185.  
  186. %ScaledVersion
  187. {
  188. %Material
  189. {
  190. %emitColor0 = #$../../COLOR/RED$,$../../COLOR/GREEN$,$../../COLOR/BLUE$
  191. %emitColor1 = #$emitColor0$
  192. @emitColor1[*] *= 0.9
  193. %rimColor = #$../../COLOR/RED$,$../../COLOR/GREEN$,$../../COLOR/BLUE$
  194. @rimColor[*] *= 1.7
  195. rimBlend = 0.8
  196. rimPower = 1
  197. %sunspotColor = #$../../COLOR/RED$,$../../COLOR/GREEN$,$../../COLOR/BLUE$
  198. @sunspotColor[*] *= 0.01
  199. }
  200. %Light
  201. {
  202. %sunLensFlareColor = #$../../COLOR/RED$,$../../COLOR/GREEN$,$../../COLOR/BLUE$
  203. @sunLensFlareColor[*] *= 0.3
  204. %IVASunColor = #$../../COLOR/RED$,$../../COLOR/GREEN$,$../../COLOR/BLUE$
  205. %scaledSunlightColor = #$../../COLOR/RED$,$../../COLOR/GREEN$,$../../COLOR/BLUE$
  206. %sunlightColor = #$../../COLOR/RED$,$../../COLOR/GREEN$,$../../COLOR/BLUE$
  207. %sunAU = #$../../StellarProperties/radius$
  208. !brightnessCurve {}
  209. brightnessCurve
  210. {
  211. key = 0.001 0 0 0
  212. key = 0.01 0.4 0 0
  213. key = 0.1 4 0 0
  214. key = 0.2 6 0 0
  215. key = 0.3 10 0 0
  216. }
  217. }
  218.  
  219. %Coronas
  220. {
  221. %Corona
  222. {
  223. %Material
  224. {
  225. texture = RealisticStars/PluginData/NoCorona.png
  226. }
  227. }
  228. %Corona
  229. {
  230. %Material
  231. {
  232. texture = RealisticStars/PluginData/NoCorona.png
  233. }
  234. }
  235. }
  236. }
  237. }
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement