change shader version to 100 for android support

This commit is contained in:
Nikola Petrov 2024-08-15 18:57:22 +02:00
parent bd31e1058d
commit f58fabcea9
3 changed files with 58 additions and 22 deletions

36
shaders/sun_100.fs Normal file
View File

@ -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);
}
}

View File

@ -5,37 +5,37 @@
#include <raylib.h>
#include <rlgl.h>
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");