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

Pages: [1]
1
Graphics / Re: GLSL Interpolate between 2 colours
« on: July 16, 2018, 04:20:02 pm »
Hi Laurent,

Thanks for pointing me towards the mix function, it was exactly what i was looking for to implement this functionality. I feel like i'm finally starting to pick up on some shader techniques :D Thanks a lot for your help.

Just in case it might help anyone, here's the shader i'm using for my day/night cycle.

uniform sampler2D texture;
uniform sampler2D lightmap;

uniform vec4 nighttime;
uniform vec2 resolution;
uniform float theta;
uniform float ambientIntensity;

uniform vec3 daytime;

void main()
{
    float timeOfDay = (0.5 * sin(theta) + 0.5);
    vec4 diffuse = texture2D(texture, gl_TexCoord[0].xy);

    vec2 lightcoord = (gl_FragCoord.xy / resolution.xy);
    vec4 light = texture2D(lightmap, lightcoord);
       
    //offset by 0.2 so ambientColour is never 0
    vec3 ambientColour = mix(nighttime.rgb, daytime, timeOfDay + 0.2);
    vec3 intensity = (ambientColour + (light.rgb * mix(ambientIntensity, 0, timeOfDay)));

    vec3 result = diffuse.rgb * intensity;

    gl_FragColor = vec4(result, diffuse.a);
}

2
Graphics / [SOLVED] GLSL Interpolate between 2 colours
« on: July 16, 2018, 11:43:02 am »
Hello,

This is somewhat related to my recent question regarding lightmap shaders.

I have a value of ambient lighting to represent a night-time colour.

I would like to fade this over time following to white representing a peak daytime colour.

I want to use the value of 0.5 * sin(theta) + 0.5 to fade between the two colours inside my shader; in order to implement a simple day/night cycle, my intention:

void main()
{
    vec3 white = vec3(1, 1, 1);
    vec3 ambientLight = vec3(0.2, 0.2, 0.2);
   
    //interpolate based on current value of 0.5 * sin(theta) + 0.5
    vec3 timeOfDayColor = InterpolateColour(ambientLight, WHITE);

    //rest of shader...
}

I have been trying to find a straightforward tutorial on how to interpolate between white and my ambient light colour to implement the
InterpolateColour
method above, however i have had no success, could anyone help me or point me in the right direction?

Thanks

3
Graphics / Re: Lightmap Shader + scrolling screen
« on: July 13, 2018, 09:55:46 am »
I figured it out, it turned out to be quite an easy solution.

I actually missed a line from the code that i posted which has probably confused the situation, my actual game object rendering method is:

public void RenderDrawable(Drawable drawable)
{
    _window.SetView(View);// this is the line that was missing from my original post.
    _window.Draw(drawable, States);
}

Now the solution was to set this same view on the lightmap render texture:

public void RenderLights(IEnumerable<Sprite> lights)
{
    _renderTexture.Clear(Color.Transparent);

    //adding this resulted in the light sources rendering to their original position
    //when scrolling
    _renderTexture.SetView(View);

    foreach (var light in lights)
    {
        _renderTexture.Draw(light);
    }
    _renderTexture.Display();

    States.Shader.SetUniform("lightmap", _renderTexture.Texture);
}

Thanks for your suggestion verdog, it led me to attempt this, although to be completely honest, i'm not exactly sure why this works, since it is the view that is scrolling. I would've thought the lightmap would've scrolled with it.

I appreciate you taking the time to help  :)

4
Graphics / Re: Lightmap Shader + scrolling screen
« on: July 12, 2018, 05:40:50 pm »
Hi Verdog,

Thanks for your reply, it seems that is exactly what's happening, i'm just unsure how to correct the shader to take into account the original position of the light sources, or is this something that would be done as part of the main program and not in the shader?

5
Graphics / [SOLVED] Lightmap Shader + scrolling screen
« on: July 10, 2018, 03:41:03 pm »
Hello,

I am attempting to implement my first lighting shader using a lightmap for some spotlights by rendering to a render texture and then blending this render texture over the game world for and additional amibent lighting effect, which is working nicely. (I am using SFML.Net)

The problem i'm having is with my scrolling View. When the view scrolls, the lights remain rendered in the same position and scrolling with the view, rather than being rendered in their original position.

My spotlights are sprites which remain in the same position throughout, which leads me to the conclusion that the issue lies with either the render texture used as the lightmap or the shader itself.

Any help would be greatly appreciated, this is one of my first attempts at lighting techniques, so i'm at a loss.

I'm using the standard passthrough vertex shader, so i don't specify one in my Shader instance.

my lighting fragment shader:

uniform sampler2D texture;
uniform sampler2D lightmap;

uniform vec4 ambient;
uniform vec2 resolution;

void main()
{
        vec4 diffuse = texture2D(texture, gl_TexCoord[0].xy);
        vec2 lightcoord = (gl_FragCoord.xy / resolution.xy);
        vec4 light = texture2D(lightmap, lightcoord);

        vec4 ambientLight = ambient;

        //ambientLight.a is used as intensity to pass through as vec4
        vec3 ambientColour = ambientLight.rgb * ambientLight.a;
        vec3 intensity = ambientColour + light.rgb;

        vec3 result = diffuse.rgb * intensity;

    gl_FragColor = vec4(result, diffuse.a);
}

Rendering:
public class RenderSystem : IDisposable
    {
        private readonly RenderWindow _window;
        public View View { get; }
        private RenderTexture _renderTexture;
        private Sprite _lightmap;

        public RenderStates States { get; set; }

        public RenderSystem(RenderWindow window, IUiLayer uiLayer)
        {
            _window = window;
            _renderTexture = new RenderTexture(_window.Size.X, _window.Size.Y);
            _lightmap = new Sprite(_renderTexture.Texture);

            UiLayer = uiLayer;
            View = new View((Vector2f)_window.Size / 2, (Vector2f)_window.Size);
        }

        public void RenderLights(IEnumerable<Sprite> lights)
        {
            _renderTexture.Clear(Color.Transparent);
            foreach (var light in lights)
            {
                _renderTexture.Draw(light);
            }
            _renderTexture.Display();

            States.Shader.SetUniform("lightmap", _renderTexture.Texture);
        }

        public void RenderDrawable(Drawable drawable)
        {
            _window.Draw(drawable, States);
        }
}
 

Render Method in my game loop:

public void Render()
{
    RenderSystem.RenderDrawable(_levelSprite);
    RenderSystem.RenderLights(_lights);

    foreach(Sprite gameObject in _gameObjects)
    {
        RenderSystem.RenderDrawable(gameObject);
    }
}
 

Initialisation of RenderSystem.States pre-gameloop:
public void Initialise()
{
    //Sig: Shader.FromString(string vertexShader, string geometryShader, string fragmentShader);
    Shader shader = Shader.FromString(null, File.ReadAllText("lighting.frag"), null);
    RenderSystem.States = new RenderStates(shader);
    RenderSystem.States.Shader.SetUniform("ambient", new Vec4(161, 93, 30, 167));
    RenderSystem.States.Shader.SetUniform("resolution", new Vec2(640, 480));
}
 

6
General / Re: RPG Sprites - Equipment and spritesheets
« on: June 25, 2018, 10:00:46 am »
Thanks for your suggestions, they are both interesting concepts and i look forward to having a play around with them when i'm ready to implement this part of my game :D

7
General / RPG Sprites - Equipment and spritesheets
« on: June 20, 2018, 10:28:35 am »
Hi there!

As a first time poster to the forum, let me start off saying how amazing of a library SFML is, I have been using it for a number of years now to do some small-scale projects and loved using it every time.

I have turned my attention to creating an RPG using an ECS architecture (architecture not really relevant here). I'm just wanting to iron some particular detail out before i start to implement it and that is how to go about having characters equipping different items (armour, weapons etc.)

How would i go about implementing this using spritesheets? I'm not much of an artist and have been using open source spritesheets for my characters so far.

Would i need a set of spritesheets for each character for each item they can equip? - This method seems extremely inefficient and very hard to manage, but i can't think of how this can be achieved.

The only other alternative would be to have a single spritesheet for each character and just have equipment (other than weapons for combat purposes) provide no sprite change and just augment character stats.

Any help would be greatly appreciated.

Thanks again.

Pages: [1]
anything