Hello, so I created a fragment shader which can be viewed here for the desired correct effect:
http://glslsandbox.com/e#28532.0Now in my game, the code is exactly the same except the stars are in wildly different positions. Here's the exact code that is being used in my game:
/*
* Copyright (C) 2013-2015 Snailsoft <https://github.com/snailsoft/starborn/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
uniform float fade_time;
uniform float time;
uniform vec2 resolution;
bool outside(vec2 center, float radius)
{
return (pow((center.x - gl_FragCoord.x), 2.0) + pow((center.y - gl_FragCoord.y), 2.0)) >= pow(radius, 2.0);
}
float random(vec2 value)
{
return fract(sin(dot(value, vec2(12.9898, 78.233))) * 43758.5453);
}
void main()
{
float rand = 0.0;
vec2 position = (gl_FragCoord - (resolution / 2.0)) / resolution.y;
vec2 position2 = (gl_FragCoord - (0.7 * resolution)) / (resolution.y / 24.0);
position2.x = (gl_FragCoord.x - (0.47 * resolution.y)) / (resolution.y / 24.0);
position /= cos(1.5 * length(position));
position2 /= cos(1.5 * length(position2));
vec3 star_color;
if((random(gl_FragCoord / resolution) > 0.995) && outside(resolution / 2.0, resolution.y / 2.7))
{
rand = random(gl_FragCoord);
star_color = vec3((rand < 0.85) ? vec3(1.0) : ((rand < 0.9) ? vec3(0.0, 1.0, 0.5) : vec3(0.0, 1.0, 1.0)));
}
float light_color = sqrt(pow(((((1.0 / ((64.0 * mod(-atan(position.y, position.x) + (((time / 3.0) + 43200.0) * (length(position) * length(position))), cos(-1.0) * 64.0)) + 0.2)) * (1.0 - step(0.42, length(position)))) + ((1.0 / ((0.125 * mod(-atan(position2.y, position2.x) + (((time / 0.025) + 43200.0) * (length(position2) * length(position2))), cos(-1.0) * 1.5)) + 0.2)) * (1.0 - step(0.42, length(position2))))) + (0.1 / distance(length(position2), 0.42))) + (1.0 / ((75.0 * distance(length(position), 0.42)) + 0.2)), 1.5));
gl_FragColor = vec4((rand > 0.0) ? (star_color - light_color) : ((vec3(0.0, 1.0, 1.0) * 0.3) * light_color) * (1.6 - length(((gl_FragCoord / resolution) * 2.0) - 1.0)), (fade_time > 0.0) ? max(0.0, 1.0 - (time - fade_time)) : min(1.0, time));
if(rand > 0.0)
gl_FragColor.a *= rand * (0.225 * sin((time * (rand * 5.0)) + (720.0 * rand)) + 0.5);
}
And here is what it looks like in game: (ignore the bad gif quality, you get the idea of what's going on)
As you can see they are all being rendered in the lower left corner even though it is the same code and they both use GLSL so I'm really confused. Can anyone with shader experience have a look and see if anything immediate is going on here?
I'll highlight the actual code that is controlling where the stars are rendered here: if((random(gl_FragCoord / resolution) > 0.995) &&
outside(resolution / 2.0, resolution.y / 2.7)) // basically only render stars if the coord is outside of the "planet" which is coded as a radius around the center of the screen
Thanks in advance guys.