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

Author Topic: Sigvatr's Newbie Thread  (Read 21283 times)

0 Members and 1 Guest are viewing this topic.

Sigvatr

  • Newbie
  • *
  • Posts: 32
    • MSN Messenger - msn@sigvatr.com
    • AOL Instant Messenger - SigvatrAIM
    • View Profile
    • http://www.sigvatr.com
Sigvatr's Newbie Thread
« Reply #15 on: September 14, 2009, 05:07:59 pm »
Hey guys,

I have been doing some great work so far. I have written an algorithm that converts height maps into normal maps very quickly and actually extends upon the height map concept by using more than a single color channel in the height map file to allow me to use additional parameters.

Anyway, on to my questions.

1) I am trying to implement normal mapping into my game (obviously, since I made a height map to normal map converter), but I have a few misunderstandings about how SFML implements GLSL. If I am correct, the PostFX class is the SFML link to GLSL functionality. It says that the PostFX class only applies shaders to the entire screen. I'm not interested in doing this, however, I only need to apply the shader to specific parts of the screen, including sprites and such which will have an alpha channel (which makes this a little bit messy). Is there a way to apply shaders without the PostFX class, or without applying it to the whole screen?

2) Is it possible to compile shader files into your program and not have them stored outside of the .exe?

3) Does anyone have a decent understanding of how 2d normal mapping with point lighting works in general? I've been surfing the web trying to figure out how to implement normal mapping but most tutorials cater towards a specific language or don't use GLSL (I'm using C++).

Thanks guys,
- Sig

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sigvatr's Newbie Thread
« Reply #16 on: September 14, 2009, 07:02:30 pm »
Hi

1) This will be possible in SFML 2. However you should be able to use fragment shaders in 1.5, as SFML doesn't reset this kind of states when rendering drawables.

2) Yes, just like any other resource. Have a look at the wiki for some useful code (search "DAT files") ;)
Laurent Gomila - SFML developer

Sigvatr

  • Newbie
  • *
  • Posts: 32
    • MSN Messenger - msn@sigvatr.com
    • AOL Instant Messenger - SigvatrAIM
    • View Profile
    • http://www.sigvatr.com
Sigvatr's Newbie Thread
« Reply #17 on: September 14, 2009, 08:02:17 pm »
I'm having a problem using the PostFX class, the output from all of my effects are flipped upside down. I can even input a raw image and it will spit it out flipped vertically.

I'm not sure if this is a bug, a problem with my graphics card and/or drivers or an intentional feature.

Have you ever heard of this happening before?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sigvatr's Newbie Thread
« Reply #18 on: September 14, 2009, 08:05:20 pm »
Can you show an example?
Laurent Gomila - SFML developer

Sigvatr

  • Newbie
  • *
  • Posts: 32
    • MSN Messenger - msn@sigvatr.com
    • AOL Instant Messenger - SigvatrAIM
    • View Profile
    • http://www.sigvatr.com
Sigvatr's Newbie Thread
« Reply #19 on: September 14, 2009, 08:50:13 pm »
My drivers are out of date, I will get back to you once I have updated them and restarted.

Basically, the shader output was flipped vertically for some reason. It's that simple. Not an 180 degree rotation but an actual flip.

Sigvatr

  • Newbie
  • *
  • Posts: 32
    • MSN Messenger - msn@sigvatr.com
    • AOL Instant Messenger - SigvatrAIM
    • View Profile
    • http://www.sigvatr.com
Sigvatr's Newbie Thread
« Reply #20 on: September 14, 2009, 08:59:06 pm »
Alright, turns out it wasn't my drivers, the PostFX output is still flipped upside down.

Aside from the fact that it is upside down it renders perfectly.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sigvatr's Newbie Thread
« Reply #21 on: September 14, 2009, 09:03:38 pm »
Ok, so now you can show me your source code / effect ;)
Laurent Gomila - SFML developer

Sigvatr

  • Newbie
  • *
  • Posts: 32
    • MSN Messenger - msn@sigvatr.com
    • AOL Instant Messenger - SigvatrAIM
    • View Profile
    • http://www.sigvatr.com
Sigvatr's Newbie Thread
« Reply #22 on: September 14, 2009, 09:15:33 pm »
Haha ok.

What I am concerned about is whether or not this is simply a problem on my computer or some other peoples, so that when I release my game some people will have flipped images and some won't.

MAIN.CPP
Code: [Select]
#include <SFML/Graphics.hpp>
#include "type_conversion.h"

using namespace sf;
using namespace std;

// Normal Mapping Test
int main()
{
    /* Create window */
RenderWindow SYS(VideoMode(512, 512, 32), "Annihilator", 1, WindowSettings(24, 8, 0));
SYS.SetFramerateLimit(0);
SYS.UseVerticalSync(0);

    /* Declare clocks */
    Clock SystemClock;
Clock ClockSeconds;

/* Load System Font */
Font System;
if(!System.LoadFromFile("systemfont.ttf"))
{
return EXIT_FAILURE;
}
String SystemFont("Frame Processing Time: 0.0000ms", System, 15.882f);

/* Load normal map */
Image *NormalMapImage = new Image;
NormalMapImage->LoadFromFile("normalmap.png");

/* Load shader */
PostFX *NormalMap = new PostFX;
NormalMap->LoadFromFile("normalmapping.sfx");
NormalMap->SetTexture("NormalMap", NormalMapImage);
int mouseX;
int mouseY;

// Test area


    // Main loop
    while(SYS.IsOpened())
    {
        /* Receive input */
        Event Event;
        while(SYS.GetEvent(Event))
        {
            /* Escape key pressed */
if( ( Event.Type == Event::KeyPressed ) && ( Event.Key.Code == Key::Escape ) ) { SYS.Close(); }

/* Mouse moved */
if( Event.Type == Event::MouseMoved ) { mouseX = Event.MouseMove.X; mouseY = Event.MouseMove.Y;  }
}
/* Determine light positiong */
NormalMap->SetParameter( "lightPosition", float(mouseX), float(mouseY) );

/* Clear screen */
        SYS.Clear( Color( 128, 128, 128 ) );

/* Render shader */
SYS.Draw(*NormalMap);

/* Render text */
SystemFont.SetColor(Color(0, 0, 0));
SystemFont.SetPosition(3,-3);
SYS.Draw(SystemFont);
SystemFont.SetColor(Color(255, 255, 255));
SystemFont.SetPosition(2,-4);
SYS.Draw(SystemFont);

        /* Render buffer to screen */
        SYS.Display();

/* Reset clock */
if ( ClockSeconds.GetElapsedTime() >= 0.5 )
{
SystemFont.SetText("Frame Processing Time: " + FloatToString( SystemClock.GetElapsedTime() * 1000 ) + "ms");
ClockSeconds.Reset();
}
Sleep( 1.000f / 60.000f - SystemClock.GetElapsedTime() );
SystemClock.Reset();
    }
    return EXIT_SUCCESS;
}


NORMALMAPPING.SFX (this doesn't actually normal map yet, it just renders the original texture)
Code: [Select]
texture NormalMap
vec2 lightPosition

effect
{
    // Get the value of the current screen pixel
    vec4 pixel = NormalMap(_in);

    // ...
    float red = pixel.r;

    // ...
    _out = vec4(pixel.r,pixel.g,pixel.b,255);
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sigvatr's Newbie Thread
« Reply #23 on: September 14, 2009, 10:49:21 pm »
Your code looks ok. Which version of SFML are you using? Did you try the post-fx sample from the SDK? As far as I know the images are not flipped in it.
Laurent Gomila - SFML developer

Sigvatr

  • Newbie
  • *
  • Posts: 32
    • MSN Messenger - msn@sigvatr.com
    • AOL Instant Messenger - SigvatrAIM
    • View Profile
    • http://www.sigvatr.com
Sigvatr's Newbie Thread
« Reply #24 on: September 14, 2009, 10:50:44 pm »
1.5. Yes, I tried that sample. Everything gets flipped for some reason and as far as I am aware there is no way to flip a PostFX object.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sigvatr's Newbie Thread
« Reply #25 on: September 14, 2009, 10:51:31 pm »
What is your configuration?
Laurent Gomila - SFML developer

Sigvatr

  • Newbie
  • *
  • Posts: 32
    • MSN Messenger - msn@sigvatr.com
    • AOL Instant Messenger - SigvatrAIM
    • View Profile
    • http://www.sigvatr.com
Sigvatr's Newbie Thread
« Reply #26 on: September 14, 2009, 11:02:44 pm »
Er, I don't know what you mean :/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sigvatr's Newbie Thread
« Reply #27 on: September 15, 2009, 12:27:15 am »
Graphics card, driver, OS, CPU, ...
Laurent Gomila - SFML developer

Sigvatr

  • Newbie
  • *
  • Posts: 32
    • MSN Messenger - msn@sigvatr.com
    • AOL Instant Messenger - SigvatrAIM
    • View Profile
    • http://www.sigvatr.com
Sigvatr's Newbie Thread
« Reply #28 on: September 15, 2009, 03:51:03 pm »
EN9800 GT with latest drivers, XP Service Pack 3, Intel Core 2 Quad CPU Q6600 @ 2.40GHz, 3.00 GB of RAM.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sigvatr's Newbie Thread
« Reply #29 on: September 15, 2009, 03:57:48 pm »
As far as I know, you're the only one to report this kind of issue about post-effects :?
Laurent Gomila - SFML developer

 

anything