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 - Snail

Pages: [1]
1
Graphics / Re: Fragment shader issue [possible bug]
« on: October 29, 2015, 11:08:38 am »
Turns out it was an error in the way that I was calculating for the bounds, ended up removing the outside() function and replacing the check line to look line this:
Code: [Select]
if((random(gl_FragCoord / resolution) > 0.995) && (length(gl_FragCoord - (resolution / 2.0)) > (resolution.y / 2.65)))
Works perfectly now.

2
Graphics / Re: Fragment shader issue [possible bug]
« on: October 29, 2015, 10:39:54 am »
Do you know if gl_FragCoord is also in a 0-1 range for sf::RectangleShape? Thanks for the reply!

I think so.
Check out function Shape::updateTexCoords(), file Shape.cpp

Or you could tell pretty quick if you put a breakpoint in your code, and examine the m_vertices data member of your RectangleShape.

Looks like it's using the actual window space values for the frag coord in that function and in the vertice data. I believe that's what the GLSL manual says is how it's suppose to behave so something else must be causing this.

3
Graphics / Re: Fragment shader issue [possible bug]
« on: October 29, 2015, 08:51:21 am »
I just had a very quick look.  But my first guess is that gl_FragCoord is in a different range in your project than it is for the glslsandbox example you linked to.

If you're using a sf::Sprite, gl_FragCoord x and y will be in the range of 0 to 1.

Your shader is comparing this to the "resolution" value.  I don't know what you've got that set to, but I'm guessing screen resolution, or the size of the sprite (or both).

If this is the case, you're comparing stuff in screen space (resolution) to stuff in texture space (gl_FragCoord), and that's kinda apples and oranges.  You'll need to convert both values to use the same coordinate space to have any meaningful comparison between them.

I see. The resolution vec2 is just the size of the texture, in this case I am rendering using a sf::RectangleShape that is set to the size of the window. Do you know if gl_FragCoord is also in a 0-1 range for sf::RectangleShape? Thanks for the reply!

4
Graphics / Fragment shader issue [possible bug]
« on: October 29, 2015, 03:16:00 am »
Hello, so I created a fragment shader which can be viewed here for the desired correct effect: http://glslsandbox.com/e#28532.0

Now 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:
Code: [Select]
/*
 * 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.

5
General / Re: Multiple function crashes - need help!
« on: April 01, 2013, 01:41:32 am »
I have solved the problem.

I usually compile my projects with a structure alignment of 1 byte but the SFML libraries were being compiled with the default alignment. Recompiling the SFML libraries with the structure alignment that I use has fixed my issue.

6
General / Multiple function crashes - need help!
« on: March 30, 2013, 06:29:58 am »
Hi,

I am creating a game and have gotten to the point of drawing stuff on the screen now. However, I am getting crashes across multiple functions including RenderWindow::clear and RenderWindow::draw.

I have built SFML and my program in debug mode to trace where things are going wrong. (It's getting an access violation error trying to read memory at 0x00000008) Both functions seem to crash when calling a function called activate, seen here:

Code: [Select]
void RenderTarget::draw(const Vertex* vertices, unsigned int vertexCount,
                        PrimitiveType type, const RenderStates& states)
{
    // Nothing to draw?
    if (!vertices || (vertexCount == 0))
        return;

    if (activate(true)) // <-------- crashes here
    {

Code: [Select]
////////////////////////////////////////////////////////////
void RenderTarget::clear(const Color& color)
{
    if (activate(true)) // <----------- crashes here
    {

Furthermore, I have traced that function down to a function called GlContext::setActive as seen here:

Code: [Select]
bool GlContext::setActive(bool active)
{
    if (active)
    {
        if (this != currentContext)
        {
            // Activate the context
            if (makeCurrent())
            {
                // Set it as the new current context for this thread
                currentContext = this;
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            // This context is already the active one on this thread, don't do anything
            return true;
        }
    }
    else
    {
        if (this == currentContext)
        {
            // To deactivate the context, we actually activate another one so that we make
            // sure that there is always an active context for subsequent graphics operations
            return getInternalContext()->setActive(true);
        }
        else
        {
            // This context is not the active one on this thread, don't do anything
            return true;
        }
    }
}

I'm assuming one of the checks here is wrong or something like that. Some more info:

Compiler: Visual C++ 2012
Version: Compiled from the git repository. (3/30/2013)
Graphics card: AMD Radeon HD 6850

The source code I am using to reproduce the error: (Uncomment the clear/draw calls to test each one, they both crash)

Code: [Select]
// untitled.cpp
// Written by Snail

#include <iostream>

#include <sfml/graphics.hpp>

#include <constants.hpp>
#include <untitled.hpp>

int main(int number_of_arguments, char **arguments)
{
sf::RenderWindow window(sf::VideoMode(800, 600), PROGRAM_NAME);

window.setVerticalSyncEnabled(true);

sf::Clock elapsed_time;
sf::Event event;

sf::Sprite player;
sf::Texture texture;

if(!texture.loadFromFile("sprite.png"))
std::cout << "Could not load sprite.png" << std::endl;

player.setTexture(texture);
player.setPosition(100, 100);

sf::Time fps;
sf::Time one_second = sf::seconds(1.0);
sf::Time zero = sf::seconds(0.0);

while(window.isOpen())
{
if(elapsed_time.getElapsedTime() >= one_second)
{
std::cout << fps.asSeconds() << std::endl;

elapsed_time.restart();
fps = zero;
}
else
fps += elapsed_time.getElapsedTime();

while(window.pollEvent(event))
{
switch(event.type)
{
case sf::Event::Closed:
window.close();

break;

case sf::Event::KeyPressed:
switch(event.key.code)
{
case sf::Keyboard::Escape:
window.close();

break;

default:
break;
}

break;

default:
break;
}
}

window.clear(sf::Color(255, 255, 255));
//window.draw(player);
window.display();
}

return 0;
}

If anyone has any insight into this, please let me know. Thanks!

Pages: [1]