Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - AntePost

Pages: [1]
1
Graphics / Re: Problem with shader variable
« on: March 20, 2020, 02:02:26 pm »
Quote
Copy if first to another variable if it needs to change.

Thank you, that was indeed the problem. Copying it into intermediary variable solved the issue.

2
Graphics / Problem with shader variable
« on: March 20, 2020, 12:24:46 pm »
Quick summary

Hello. I'm learning C++ through this book. In the last game project the author shows how to use simple shaders to make visual effects. I, however, cannot replicate it in my code.

I load .vert & .frag into a variable with sf::Shader::loadFromFile, however fragment shader can't compile with this error:
ERROR: 0:11: 'assign' : l-value required "vTexCoord" (cannot modify a varying)

Full Explanation

Here is the code of vertShader.vert:
#version 110

//varying "out" variables to be used in the fragment shader
varying vec4 vColor;
varying vec2 vTexCoord;
 
void main() {
    vColor = gl_Color;
    vTexCoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
 

Here is the code of rippleShader.frag:
// attributes from vertShader.vert
varying vec4 vColor;
varying vec2 vTexCoord;

// uniforms
uniform sampler2D uTexture;
uniform float uTime;

void main() {
        float coef = sin(gl_FragCoord.y * 0.1 + 1 * uTime);
        vTexCoord.y +=  coef * 0.03;
        gl_FragColor = vColor * texture2D(uTexture, vTexCoord);
}
 

Here is what I do in my program:
1. Declare a shader variable in my game engine class header:
Shader m_RippleShader;

2. Load files into shader variable in the Engine constructor:
if (!sf::Shader::isAvailable())
{
        m_Window.close();
}
else
{
        m_RippleShader.loadFromFile("shaders/vertShader.vert",
                "shaders/rippleShader.frag");
}
 

3. In my "draw" function I update shader variable each frame:
m_RippleShader.setUniform("uTime", m_GameTimeTotal.asSeconds());

4. Finally in the same function I draw the background with shader (I do it three times because the game supports splitscreen):
m_Window.draw(m_BackgroundSprite, &m_RippleShader);

When I try to launch game the rippling effect isn't there & the aforementioned error is output to console. I understand that the problem is with this line:
vTexCoord.y +=  coef * 0.03;
Something is wrong with vTexCoord.

What is curious is that m_RippleShader.loadFromFile doesn't output any errors to console, however it returns false, so I assume there is some problem with loading files. Even more curious is that it returns false after the error from the shader compilation.

I frankly don't have enough knowledge to figure it out by myself so any help will be appreciated.

Pages: [1]
anything