-1

I was trying to display a shader in raylib, but I just got a black screen.

I created a render texture, shader object, set some shader uniforms locations and variables for them:

Shader shader = LoadShader(0, TextFormat("src/shader.frag", 330));
int timeLoc = GetShaderLocation(shader, "iTime"); 
int resolLoc = GetShaderLocation(shader, "iResolution");
int resolution[2];
RenderTexture2D target = LoadRenderTexture(GetScreenWidth(), GetScreenHeight());

double iTime{ 0. };

Then in the program loop I draw a rectangle to render texture, set shader uniforms values and then trying to apply it to my render texture:

BeginTextureMode(target);
ClearBackground(BLACK);
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLACK);
EndTextureMode();

iTime = GetTime();
SetShaderValue(shader, timeLoc, &iTime, SHADER_UNIFORM_FLOAT);

resolution[0] = target.texture.width;
resolution[1] = target.texture.height;
SetShaderValue(shader, resolLoc, resolution, SHADER_UNIFORM_VEC2);

BeginDrawing();
BeginShaderMode(shader);
DrawTextureEx(target.texture, Vector2(0, 0), 0.0f, 1.0f, BLACK);
EndShaderMode();
EndDrawing();

But for some reason I always get just black screen and in logs there's no errors.

Terminal says that everything is successful

Also shader code:

#version 330

in vec2 fragTexCoord;
in vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 colDiffuse;
uniform vec2 iResolution;
uniform float iTime = 0;
out vec4 finalColor;

vec3 palette( in float t )
{
    return vec3(0.638, 0.188, 0.318) + vec3(-0.312, 0.458, 0.428) * cos( 6.28318 * (vec3(2.138, 1.448, 1.) * t + vec3(0., 0.333, 0.667) ) );
}

void main()
{
    vec2 uv = (fragTexCoord * 2. - iResolution.xy) / iResolution.y;
    vec2 suv = uv;
    vec3 res = vec3(0.);
    for (float i = 0.; i < 2.; i++) {
        uv = fract(uv * 1.6) - .5;
        float slen = length(uv) * exp((cos(length(suv) * 3.14) - 0.52839382840284));
        slen = dot(vec2(slen), vec2(-1.729493, -0.13935));
        float len = abs(sin(slen * 8. + iTime)) * 2.0;
        len = .04 / len;
        res += palette(slen + iTime) * len * 12.;
    }
    finalColor = vec4(res, 1.);
}
Sirox0
  • 1
  • 1

0 Answers0