Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Convert astronomical luminosity and color to color space from attribute map

Discussion in 'Visual Effect Graph' started by gregjdf, Nov 21, 2022.

  1. gregjdf

    gregjdf

    Joined:
    Jul 23, 2022
    Posts:
    11
    Hello

    I'am working on a astronomical project named Gaia (containing 2billions stars). For now I'am working on a subsample of the dataset. I'am happy that the rendering is at 80FPS on my laptop with 13M stars.

    Each star has the following atrtibutes:
    - x,y,z coordinates
    - luminosity is a float (magnitude) ranging from ~0 to ~20 where 0 is brigther and 20 is fainter
    - color is also a single float ranging from -10 to 10 (it is similar to a gradient -10 would be reddish 0 white/yellow and 10 blue-ish) I think I could have this value in Kelvin as well

    I load data in a point cache.
    But I cannot figure out after reading docs and searching various examples how to extract the luminosity and the color from the point cache attributes to various nodes be able to derive and compute a sRGB color.

    My second question might be more complicated . I'd like that if two or more stars are aligned in the same pixel then the final luminosity to be the mean off all the stars. I have impression I could use some kind of alpha blending where alpha would be 1/num_stars , but I cannot see how to do it in VFX graph.

    Here is my current graph fyi:

    I'am unsing unity 2021 LTS on windows
    Any help would be much appreciated.


    upload_2022-11-21_9-45-47.png
     
  2. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,296
    Hi, could you precise what you mean by "how to extract the luminosity and the color from the point cache attributes"?
    You want to convert some units? luminosity to color? or read the value itself from point cache? If you want to read it, it must be stored there.

    About second question, this might be tricky because you would need to know all star particles in that place - I mean if there are 3 stars in the same place, then star A has no clue about star B and C, so you are unable to calculate mean of them all. My first two thoughts are:
    1. You need to know number off stars beforehand - you can do it by precomputing it before creating point cache. Simply speaking decrease luminosity of stars in the same place or pass that information with point cache. However I don't know how your project works, and if observer can move with speed of light then relative positions of stars can change and in result illusion breaks, so it works only in "our solar system".
    2. You can try to do some kind of post process to cut bright pixels or add additional rendering to do base your calculations on that. However this sounds expansive.

    In any case one more note - you enabled premultply mode and I guess this should give you still some decent results, but you are using default particle and if I remember correctly does not work well in this mode. It's not like there is only "one way" to prepare textures, but good premultiply particles should give you no black regions when two of them intersect. You can get results similar to max(A, B, C).
     
  3. gregjdf

    gregjdf

    Joined:
    Jul 23, 2022
    Posts:
    11
    Many thanks for your answer.

    Issue 1
    Indeed for the first issue I wanted to perform this conversion in the VFX graph i.e at runtime. I could do this upfront i.e export the values in the pCache file, but for it is not practical at all because I would have to extract data and reimport it systematically in the assets for testing and visualizing the results.

    In the VFX graph I wish I could easily play with a color palette and map my 2 number (magnitude,color) to a coordinate in the color palette (maybe a 2D texture?). That's why I said I'd like to extract the values from the attribute map and compte the rgb values using some vfx graph nodes and blocks.

    Just to clarify even more I give an example: if I have in the point caches the following values for point p1: magnitude = 10 and color = 2 it would be a moderately bright red star. On the other hand a point p2 with magnitude 1 and color -5 would be a very bright blue star.

    The image at the bottom is the current result Fyi. So indeed colors and luminosity are .... There are also artefacts in the data but it is another story ... :)

    Issue2
    Again thank you for your insights. Indeed the big issue here is how to know that 2 or more stars are aligned. usually in static 2D we bin the screen in small squares and mean all the stars luminosity fitting in one square: It gives very beautiful results already. You can see this image below that use this technique. But in 3D we need to do this at Runtime as because I want to be able to travel in the space :) I was wondering If in one of the VFX graph node or fragment shader I have access to the stacked pixels on the same screen coordinates , and in such a case be able to update there value. If it is not doable in VFX graph I guess I'd have to do it in a custom fragment shader ?

    upload_2022-11-22_8-48-31.png
     
    Last edited: Nov 22, 2022
  4. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,296
    For the first one (if I understood correctly) there are two parameters you want to remap to final color, so it's just grid 2D. Create texture 2D with row as luminosity and column kelvin scale or whatever that is. Remap your values to 0-1 (or prepare beforehand) and sample that texture during init.

    The second one - there is no such node (in URP at least), there is scene color only, so you would need to add your own custom pass and render the whole thing twice to get what you want. I mean maybe it might be possible somehow, but for sure it's out of scope of my current knowledge. The only thing I know that could help is to use some custom blend mode.
     
    gregjdf likes this.
  5. gregjdf

    gregjdf

    Joined:
    Jul 23, 2022
    Posts:
    11
    OK I got something working for item 1, and for item 2. Current solution for item 2 (additive blending) looks fair enough.

    Fyi here is the graph for item 1. I had to use this PointCacheUV subgraph (PCUV) + the remap operator that is extremely handy . PointCacheUV was posted in the forum or on github and is very convenient.

    For now I still do not use the mag that represent the star brighteness, but in next step I'll combine both mag and col to have proper color and brightness. I'll then mark this issue solved .

    I anyone has an idea how to combine properly ...
    Ideally in a 2 texture representing in u the color, in v the brightness :)
    VFXgraph.png
     
  6. gregjdf

    gregjdf

    Joined:
    Jul 23, 2022
    Posts:
    11
    Not sure how to do this in unity ! I'am searching
     
  7. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,296
    I don't know your exact needs, but if color/temperature is not related to brightness, then you don't need it I guess?
    You can sample gradient (as you did) and multiply by luminosity. Separate texture can be good if these things are not so simple, for example when color is shifted or color scale changes depending on the other value. In this case you can generate proper texture 2D and remap values. If you meant how to create it in technical way then either create it outside Unity, or if you know how it should look like, then create texture in script, iterate pixels and set to proper values, then save as asset (AssetDatabase).
     
  8. gregjdf

    gregjdf

    Joined:
    Jul 23, 2022
    Posts:
    11
    Indeed I'd Ideally like to have color/temperature related to the brightness, ideally like here http://www.vendian.org/mncharity/dir3/blackbody/intensity.html. But here there are only few examples.

    The blackbody node (in shader graph) in only working at fixed brightness unfortunately.
    Probably I'll have to generate this texture 2D using code

    Thanks !