diff --git a/shaders/sun_100.fs b/shaders/sun_100.fs new file mode 100644 index 0000000..e3f3eda --- /dev/null +++ b/shaders/sun_100.fs @@ -0,0 +1,36 @@ +#version 100 + +precision mediump float; + +varying vec2 fragTexCoord; +varying vec4 fragColor; + + +uniform vec3 color; +uniform float sun_radius; +uniform float start_transperency; + +vec2 offset = vec2(1.0, 1.0); +float sun_end = 1.0; + +void main() +{ + offset.x -= fragTexCoord.x * 2.0; + offset.y -= fragTexCoord.y * 2.0; + float radius = length(offset); + + if(radius < sun_radius){ + + gl_FragColor = vec4(color, 1.0); + + }else if(radius < sun_end){ + + float gradient = radius; + gradient -= sun_radius; + gradient = gradient / (sun_end - sun_radius) * start_transperency; + gl_FragColor = vec4(color, start_transperency - gradient); + + }else{ + gl_FragColor = vec4(color, 0.0); + } +} \ No newline at end of file diff --git a/shaders/sun.fs b/shaders/sun_330.fs similarity index 100% rename from shaders/sun.fs rename to shaders/sun_330.fs diff --git a/src/canvas/Sun.cpp b/src/canvas/Sun.cpp index 91f0455..c3f72ed 100644 --- a/src/canvas/Sun.cpp +++ b/src/canvas/Sun.cpp @@ -5,37 +5,37 @@ #include #include -const char* sun_shader = "#version 330\n\ -in vec2 fragTexCoord;\ -in vec4 fragColor;\ -out vec4 finalColor;\ +const char* sun_shader_100 = "#version 100\n\ +precision mediump float;\ +varying vec2 fragTexCoord;\ +varying vec4 fragColor;\ uniform vec3 color;\ uniform float sun_radius;\ uniform float start_transperency;\ -vec2 offset = vec2(1.0f, 1.0f);\ -float sun_end = 1.0f;\ +vec2 offset = vec2(1.0, 1.0);\ +float sun_end = 1.0;\ void main()\ {\ - offset.x -= fragTexCoord.x * 2;\ - offset.y -= fragTexCoord.y * 2;\ - float radius = length(offset);\ - if (radius < sun_radius) {\ - finalColor = vec4(color, 1.0f);\ - }\ - else if (radius < sun_end) {\ - float gradient = radius;\ - gradient -= sun_radius;\ - gradient = gradient / (sun_end - sun_radius) * start_transperency;\ - finalColor = vec4(color, start_transperency - gradient);\ - }\ - else {\ - finalColor = vec4(color, 0.0f);\ - }\ + offset.x -= fragTexCoord.x * 2.0;\ + offset.y -= fragTexCoord.y * 2.0;\ + float radius = length(offset);\ + if (radius < sun_radius) {\ + gl_FragColor = vec4(color, 1.0);\ + }\ + else if (radius < sun_end) {\ + float gradient = radius;\ + gradient -= sun_radius;\ + gradient = gradient / (sun_end - sun_radius) * start_transperency;\ + gl_FragColor = vec4(color, start_transperency - gradient);\ + }\ + else {\ + gl_FragColor = vec4(color, 0.0);\ + }\ }"; void Sun::init() { - shader = LoadShaderFromMemory(0, sun_shader); + shader = LoadShaderFromMemory(0, sun_shader_100); target = LoadRenderTexture(sizeTexute, sizeTexute); sun_radius_loc = GetShaderLocation(shader, "sun_radius");