ENG New site

Advanced search

[ New messages · Forum rules · Members ]
  • Page 1 of 1
  • 1
Star Colors and Saturation
HarbingerDawnDate: Thursday, 05.04.2012, 05:56 | Message # 1
Cosmic Curator
Group: Administrators
United States
Messages: 8717
Status: Offline
As I was looking up at the sky tonight I realized something that was missing from SpaceEngine. In reality, dim stars appear neutral in color, because they are too dim for the human eye to perceive the color. Only in bright stars is the color really noticeable. I believe that this would be a good visual effect to implement in SpaceEngine. Currently in the program, a magnitude 5 star looks just as colorful as a magnitude -5 star. In reality, to the unaided eye the dim star would appear white/gray.

I think that a good feature to implement would be rendering star color saturation as a function of apparent magnitude (perhaps by an inverse-logarithmic or logistic curve?) If this could be made to be a toggle-able option that would be even better. This would give the sky a much more natural appearance when viewed in the engine.

Just a thought I had and felt like sharing. And I apologize if this has been mentioned before, I can't recall seeing it so I just went ahead and posted smile





All forum users, please read this!
My SE mods and addons
Phenom II X6 1090T 3.2 GHz, 16 GB DDR3 RAM, GTX 970 3584 MB VRAM
 
SpaceEngineerDate: Saturday, 07.04.2012, 18:16 | Message # 2
Author of Space Engine
Group: Administrators
Russian Federation
Messages: 4800
Status: Offline
I was trying to do these, but found the effect strange... First idea is to add a few lines in the final HDR shader, that will desaturate dim pixels, but this approach doesn't work well - desaturation affects even the dark rocks or evening sky on planets. The second attempt is to change star shader. This works, but with low desaturation threshold the effect is not noticeble, and with the entire galaxy it becomes black and white, which is noticeble especially with interstellar flight.

You may experiment with these parameters, maybe you will find some are good. This is the star_blur.glsl shader, red lines are the new code:

Code

//attribute float gl_Vertex;          // Sprite center world position
//attribute float gl_MultiTexCoord0;  // Luminosity
//attribute vec2  gl_Color;           // Color index, vertex id

uniform sampler1D ColorMap;
uniform sampler2D Texture;
uniform vec4      Param;
uniform mat4x4    oldModelViewMatrix;

#ifdef _VERTEX_

out vec3 TexCoord;
out vec3 ColBright;

void main()
{
       TexCoord.x = mod(floor(gl_Color.y * 4.0), 2.0);
       TexCoord.y = mod(floor(gl_Color.y * 2.0), 2.0);

       vec4 viewPosN = gl_ModelViewMatrix * gl_Vertex;
       vec4 viewPosO = oldModelViewMatrix * gl_Vertex;
       vec4 viewPos;
       if (TexCoord.x == 0.0) viewPos = viewPosN;
       else                   viewPos = viewPosO;

       float Dist2 = dot(viewPos.xyz, viewPos.xyz);
       float mag = Param.x * exp(gl_MultiTexCoord0.x) / Dist2;

       ColBright.x = gl_Color.x;
       ColBright.y = clamp(Param.w*(mag - Param.y), 0.0, 1.0);
       ColBright.z = mag;

       if (mag > 1.0)  mag = 1.0 + log(mag);
       float spriteSize = Param.z * sqrt(Dist2 * mag);

       vec2 Offset = 1.0 - TexCoord.xy * 2.0;
       vec3 Ray = viewPosN.xyz - viewPosO.xyz;

       //if ((dot(Ray, Ray) <= 1e-6) || (abs(viewPosN.z - viewPosO.z) <= 1e-4))
       if (dot(Ray, Ray) <= 1e-6)
       {
           viewPos.xy += Offset * spriteSize;
           TexCoord.z = 0.0;
       }
       else
       {
           //float RayLen = 0.5 * length(viewPosN.xy - viewPosO.xy) / ((1.0 + abs(viewPosN.z - viewPosO.z)) * spriteSize);
           float RayLen = 0.5 * length(viewPosN.xy - viewPosO.xy);

           spriteSize /= RayLen + 1.0;
           //spriteSize /= RayLen*RayLen + 1.0;
           TexCoord.z = RayLen / (RayLen + 1.0);

           /*if (dot(Ray, viewPosN.xyz) <= 1e-3)
           {
               viewPos.xy += Offset * spriteSize;
               TexCoord.z = 0.0;
           }
           else*/
           {
               vec3 Tangent = normalize(cross(Ray, viewPosN.xyz));
               mat2x2 Mat = mat2x2(Tangent.y, -Tangent.x, Tangent.x, Tangent.y);
               viewPos.xy += (Mat * Offset) * spriteSize;
           }
       }

       gl_Position = gl_ProjectionMatrix * viewPos;
}

#else

in vec3 TexCoord;
in vec3 ColBright;

void main()
{
       vec2 texCoord;
       texCoord.y = TexCoord.y;
       if (abs(2.0 * TexCoord.x - 1.0) < TexCoord.z)
           texCoord.x = 0.5;
       else
       {
           if (TexCoord.x > 0.5)
               texCoord.x = (TexCoord.x - TexCoord.z) / (1.0 - TexCoord.z);
           else
               texCoord.x = TexCoord.x / (1.0 - TexCoord.z);
       }

       vec4 Color = texture1D(ColorMap, ColBright.x);

       //////////////////////
       // new code nere //
       //////////////////////

       float DesaturateThreshold = 2.0;
       float Gray = dot(Color.rgb, vec3(0.3, 0.59, 0.11));
       Color.rgb = mix(vec3(Gray), Color.rgb, pow(clamp(ColBright.z / DesaturateThreshold, 0.0, 1.0), 3));

       ////////////////////////
       // end of new code //
       ////////////////////////

       gl_FragColor.rgb = ColBright.y * Color.rgb * texture2D(Texture, texCoord).rgb;
       //gl_FragColor.a = ColBright.y;
       gl_FragColor.a = 0.0;
}

#endif


Edit: ok, color text doesn't work in the "code" tag, so I've highlighted the new code with a comment - look at the end of the shader.

*





 
HarbingerDawnDate: Saturday, 07.04.2012, 21:36 | Message # 3
Cosmic Curator
Group: Administrators
United States
Messages: 8717
Status: Offline
Thanks SpaceEngineer, I'll tinker with it.




All forum users, please read this!
My SE mods and addons
Phenom II X6 1090T 3.2 GHz, 16 GB DDR3 RAM, GTX 970 3584 MB VRAM
 
  • Page 1 of 1
  • 1
Search: