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

Pages: [1]
1
Graphics / Re: Rotating Texture
« on: March 06, 2013, 01:05:48 am »
I'm trying to make a small Mode 7 project (And yes, I know it's not real 3D) http://en.wikipedia.org/wiki/Mode_7

It's looking good, but I need to rotate the texture (Not the sprite) so that it can be navigated in this mode, if you understand what I'm trying to say.

Hey Aaron,

Who doesn't like Mode 7? :) I actually did something similar in Processing a while back, so it was easy to reuse the code to work with my current application. It's GLSL, I hope you don't mind:

// Mode 7 Shader
uniform sampler2D Buf1;                    
uniform float Sin1, Cos1, Sin2, Cos2;

vec2 RepeatXY(in vec2 XY){
        return vec2(mod(XY.x, 1.0), mod(XY.y, 1.0));
}

void main(void)
{
        vec2 uv = gl_TexCoord[0].st;
       
        float Scale = 128.0;
        float Distance = -2.0;
        float LookY = -0.3;
       
        vec2 warped;
       
        // perform Mode 7 transformation on uvs
        warped = vec2( (uv.x-0.5)/(uv.y+LookY-0.5), 1.0/(uv.y+LookY-0.5) - Distance)/Scale;
       
        // rotate the new uvs
        warped = vec2(Sin1*warped.x, Sin2*warped.x) + vec2(Cos1*warped.y, Cos2*warped.y);
       
        // set the uvs to repeat in space
        warped = RepeatXY(warped);
 
        // horizon check
        if(uv.y < 0.5 - LookY)
                // sample the input texture with new uvs
                gl_FragColor = texture2D(Buf1, warped);
        else
                // sky
                gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
}

and in your C++ program:

Mode7Shader.SetParameter("Sin1", sin(Time*Val));
Mode7Shader.SetParameter("Cos1", cos(Time*Val));
Mode7Shader.SetParameter("Sin2", sin(Time*Val + 0.5*3.1415926535897932384626433832795));
Mode7Shader.SetParameter("Cos2", cos(Time*Val + 0.5*3.1415926535897932384626433832795));
 

Where "Time" if a float counting by +1.f every frame, and "Val" is any small float. You can substitute "Time*Val" for just one float describing the rotation.

It's not set up for anything but y-rotation and basic movement, but it should give you something to work with.

Hope it helps!

[attachment deleted by admin]

2
Ha! Behind the times I am. I may have to download the latest version.

I see texture wrapping can now be enabled with setRepeated(), but render textures have no such support. I thought I could do something like in this post: http://en.sfml-dev.org/forums/index.php?topic=5016.0 , but the RenderTexture class has no Bind() function.

I'd also like to enable float render textures, but it's the same problem again.

3
This is definitely not SFML 2. In SFML 2, functions use camelCase naming, members have the "m_" prefix, sf::Shader handles vertex and fragment shaders, and the "myFragmentShader" member doesn't exist anymore.

Hmm, something's not adding up. A while back I downloaded the source for version 2, I can't remember when. Anyway, inside that .zip is a directory named "LaurentGomila-SFML-e5d6353." This is what I've been building the libraries from.

The list of modifications from 1.6 to 2.0 seem to indicate that I am indeed using the latter version. For instance, I use "EnableVerticalSync,"  and "sf::Shader" in my programs. I can also build static libraries instead dynamically linked ones.

Maybe I am not using the latest version of SFML 2.0, but some earlier draft?

4
I may have found a solution:

case sf::Keyboard::L:

  ShaderMain.myFragmentShader.clear();

  if (ShaderMain.LoadFromFile(gfx.ShaderMainFile))
  {
    ShaderIsValid = true;
    cout << "shader loaded.\n";
  }
  else
    ShaderIsValid = false;

  Buf1.Clear();
  Buf2.Clear();

  ShaderMain.SetParameter("offset", 1.f/(float)gfx.w, 1.f/(float)gfx.h);
  ShaderMain.Bind();

break;
 

As it turns out the render textures must be cleared, one-time parameters must be reset, and the shader bound. I'm sure something else will crop up, but I think I have it covered now ;) Speak up if I'm doing something horribly wrong   ;D

5
OK, so I made "std::string  myFragmentShader" in "SFML/Graphics/Shader.hpp" public, and it is working, but not correctly.

Here's what I'm doing in my main file:

case sf::Keyboard::L:

  // clearing the shader string
  ShaderMain.myFragmentShader.clear();

  // loading
  if (ShaderMain.LoadFromFile(gfx.ShaderMainFile))
    ShaderIsValid = true;
  else
    ShaderIsValid = false;

  // this checks out
  cout << ShaderMain.myFragmentShader;

break;
 

For testing purposes I am using a noise shader that just fills the screen with random values. I'm feeding it a random number to offset the noise to behave like TV static. There is a uniform sampler declared in the shader that isn't being used in the C++ program, so I know that the shader was loaded successfully when I see an error pertaining to said unused uniform sampler. If an attempt to load the shader fails, the screen will go blank.

When reloading the shader, strange things are occurring:
  • I do not receive an error about the unused uniform sampler
  • the screen isn't going blank like it would if the shader couldn't be loaded
  • the static suddenly stands still, as if the parameter I am feeding it isn't changing
  • the program continues happily as if nothing is wrong

Was it a bad idea to make myFragmentShader public?

6
You might want to read this. :)

I'm already using SFML 2.0. Or are you suggesting that I downgrade to 1.6?

I see a private method, "std::string  myFragmentShader," in which I'm tempted to make public just so I can clear its contents at will :)

7
Thanks guys. Here's what I have:

if (!ShaderMain.LoadFromFile(gfx.ShaderMainFile))
  ShaderIsValid = false;
else
  ShaderIsValid = true;
 

I don't think I need a contingency shader after all.

So now I'm experiencing another problem. When I attempt to reload the shader, SFML appears to be adding the existing shader code to what was loaded before. For instance, the first error message I get is this: "'Buf1' conflicts with previous declaration at 0(1)." The other errors mention other variables, eventually arriving at main().

I need to be able to clear ShaderMain's contents in order to reload it from a file.

8
Hi,

I'm developing a small app for producing generative art. Since I wish to load shaders while the program is running, I'll need some way to prevent the program from crashing if/when the shaders contain any errors. Ideally, a simple default shader would be loaded and a message displayed whenever a shader program is not compiled successfully. The CompileProgram() method looks promising, but is private.

Could anyone point me in the right direction so I can get this working? Compiling SFML is no problem.

-Strobe

9
Feature requests / Graphics: full 16-bit grayscale support
« on: September 18, 2011, 07:35:06 pm »
Quote from: "Laurent"
Quote
loading 16-bit data directly into images and textures

From which file format?


From 16-bit grayscale PNGs, since they are generally the easiest format to work with.

Quote
Support for 16-bits pixel components requires support for different formats (I mean, from the public API point of view), which I'm still not sure about.
And before 16-bits floating-point formats, there are other formats that are more important to support : 8 bits luminance, YUV, ARGB, ... ;)


Ah, OK. That's all right  8) I'll probably check out the Visualization Library before I make an HF utility.

BTW Laurent, I'm very happy with SFML; it's a real joy to use! Thanks for all your hard work  :)

10
Feature requests / Graphics: full 16-bit grayscale support
« on: September 17, 2011, 01:09:35 am »
Hi!

I would eventually like to develop some height_field utilities with SFML, but as you may already know, height maps produce the best results when they are in a 16-bit format; 8-bit just really doesn't cut it.

My goal is to use the height maps in POV-Ray, though there are plenty of other programs supporting 16-bit grayscale images. I know how to produce 16-bit values using the red/green channels of an 8-bit image, but that format can be difficult to manipulate in POV. I'd like to avoid unnecessary conversions, especially if I make my utility publicly available.

sf::Image seems to be the only way to save images, and it appears to only accept 8-bit values.

16-bit grayscale support would include:
    * loading 16-bit data directly into images and textures
    * floating point textures (and, consequently, GLSL shaders)
    * drawing 16-bit data to render textures, using sprites
    * saving 16-bit grayscale PNG images


Since SFML is a multimedia library--and not only used for authoring games--this feature request doesn't seem entirely unreasonable :D

~Strobe

11
Graphics / SFML 2 Water Shader Problem
« on: August 26, 2011, 11:59:21 pm »
Quote from: "easy"

1. Render the scene to a texture
2. Pass this texture (or a part of it) to the shader
3. Draw the shaded surface


^This will most definitely work, provided the last step involves the texture being drawn to another target: either a composite layer or the window, but never to the same texture or to a texture recycled back into the source.

I think the OP might be seeing a runaway feedback effect(*), which probably accounts for the flickering. Even worse, when you apply a shader to a texture using the same texture as a source, you get that "undefined behavior" as mentioned here: http://www.opengl.org/wiki/GLSL_:_common_mistakes#Sampling_and_Rendering_to_the_Same_Texture

(*Feedback is often a desired property. Milkdrop, for instance, uses feedback in almost all of its presets. To use it properly, you need two textures that you can ping-pong between.)

12
Graphics / A Problem with PostFX and GLSL Functions (v1.6)
« on: August 20, 2011, 12:32:00 am »
Yes! Got 2.0 compiled (which was a surprisingly painless process), and everything is as it should be. Had a difficult patch while trying to compile a program, but I played Tower of Hanoi with the linked libraries until I found the right order.

GLSL shaders now seem to be working as they should 8) Thanks again for everything, Laurent!

13
Graphics / A Problem with PostFX and GLSL Functions (v1.6)
« on: August 19, 2011, 07:27:17 pm »
Gah! Thank you  :oops:

14
Graphics / A Problem with PostFX and GLSL Functions (v1.6)
« on: August 19, 2011, 06:55:58 pm »
Alright, I'll give it a try.

BTW, I tried wrapping code and quote tags around text in my post, but they didn't do anything. But now, there they are. Thanks, if that was your doing :)

15
Graphics / A Problem with PostFX and GLSL Functions (v1.6)
« on: August 19, 2011, 02:50:55 am »
Hi,

I'm trying to implement a simple function in my GLSL shader program, but am met with errors. The version of SFML I am using is 1.6, with Code::Blocks 10.05 for Windows (MinGW).

Here's the offending code:

Code: [Select]
// shader.sfx
texture Img1

float foo(in float fubar)
{
return(fubar);
}

effect
{
_out = Img1(_in);
}


and here are the errors:

Quote
Post-effect error : invalid declaration (should be "[type][name]")
> {
Failed to compile post-effect :
(0) : error C0000: syntax error, unexpected $end at token "<EOF>"
(0) : error C0501: type name expected at token "<null atom>"


I suspect SFML isn't properly parsing the shader source. One reason for my belief is that it won't accept the ';' terminator at the end of variable declarations. Another is how this will work:

Code: [Select]
effect
{
_out = Img1(_in);
}


but this will not:

Code: [Select]
effect {
_out = Img1(_in);
}


I've tried not adding ';' at the end of the return line, and also removing 'in,' among other things.

Should I be using SFML 2.0?

thx,

~Strobe

Pages: [1]
anything