Page 2 of 3

Re: Playmat - A Mode 7 Library

Posted: Wed Jan 04, 2017 9:02 am
by yetneverdone
I've tried the demo, and sort of change the code to see the effects. Pretty cool and simple! it's like raycasting(is it?) more in-depth explanation to each function perhaps will help alot?

Re: Playmat - A Mode 7 Library

Posted: Wed Jan 04, 2017 12:07 pm
by pgimeno
Jasoco wrote:What version of Löve do you have? What GPU and drivers? It worked for me on 0.10.2.
I know for a fact it's a GLSL compiler optimization thing, i.e. GPU drivers. I use nVidia proprietary drivers 340.96. It's easy to reproduce on any version of LÖVE. It's just something that any shader author should be aware of, if they want their shaders to work in all drivers.

Code: Select all

shader = love.graphics.newShader[[
  extern float unused;
  vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords)
  {
    vec4 texturecolor = Texel(texture, texture_coords);
    return texturecolor * color;
  }
]]
shader:send("unused", 1)

Code: Select all

Error: main.lua:9: Shader uniform 'unused' does not exist.
A common error is to define but not use the variable.
stack traceback:
	[C]: in function 'send'
	main.lua:9: in main chunk
	[C]: in function 'require'
	[string "boot.lua"]:429: in function <[string "boot.lua"]:275>
	[C]: in function 'xpcall'
The OpenGL wiki warns about it here: https://www.khronos.org/opengl/wiki_ope ... iveUniform

Here's a request to keep the values with a special pragma, for debugging: https://www.opengl.org/discussion_board ... -debugging

Even this code, which uses the extern variable but multiplies it by 0.0, errors out, because the compiler is smart enough to know that multiplying a value by 0.0 makes the value irrelevant, and optimizes it out:

Code: Select all

shader = love.graphics.newShader[[
  extern int unused;
  vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords)
  {
    vec4 texturecolor = Texel(texture, texture_coords);
    return texturecolor * color * (unused * 0.0 + 1.0);
  }
]]
shader:send("unused", 3);
The error message comes from LÖVE, almost surely because the LÖVE authors are well aware of that problem. Perhaps a better treatment by LÖVE would be that Shader:send doesn't raise an error when the uniform doesn't exist, but returns a status instead, like the GLSL wiki suggests.

Re: Playmat - A Mode 7 Library

Posted: Wed Jan 04, 2017 1:26 pm
by Davidobot
yetneverdone wrote:wow, very awesome. Possible to make doom-esque fps?
Ahum..

Re: Playmat - A Mode 7 Library

Posted: Wed Jan 04, 2017 10:09 pm
by hatninja
yetneverdone wrote:it's like raycasting(is it?) more in-depth explanation to each function perhaps will help alot?
It's actually more like 3d projection, but instead of an actual z value, the screen's y-position is used.
The further up the screen, the further the points on the texture.

z = screen_y
x/z
y/z

That is basically the core to how it all works, but i don't think i can explain it better than that!

Re: Playmat - A Mode 7 Library

Posted: Wed Jan 04, 2017 10:16 pm
by alberto_lara
Thanks! I was looking for something like this :)

EDIT: I've changed the map for a bigger one and it seems weird now, am I doing something wrong?
Playmat.love
(145.07 KiB) Downloaded 196 times
EDIT 2: The map image has to be a square, right?

Re: Playmat - A Mode 7 Library

Posted: Thu Jan 05, 2017 12:00 am
by hatninja
EDIT 2: The map image has to be a square, right?
For now, yes.
I'm already working on it right now, so hopefully it'll be fixed quite soon!

EDIT: It is now fixed! You can check out the newest version at github!

Re: Playmat - A Mode 7 Library

Posted: Thu Jan 05, 2017 3:46 am
by alberto_lara
EDIT: It is now fixed! You can check out the newest version at github!
Thanks!

Re: Playmat - A Mode 7 Library

Posted: Thu Jan 05, 2017 9:14 pm
by raidho36
pgimeno wrote: The error message comes from LÖVE, almost surely because the LÖVE authors are well aware of that problem. Perhaps a better treatment by LÖVE would be that Shader:send doesn't raise an error when the uniform doesn't exist, but returns a status instead, like the GLSL wiki suggests.
It's impossible to tell whether the variable was nuked by compiler or never existed there in the first place, not without potentially extremely complex and computationally intensive static analysis. If it failed to set shader variable silently, you'd stuck for much longer with typos in variable names. The way it works now is the best possible compromise.Additionally, for the cases where you deliberately want to ignore fatal errors, there is the "pcall" function which I can't get to work over LÖVE's internal exception throws so yeah nevermind that.

Re: Playmat - A Mode 7 Library

Posted: Thu Jan 05, 2017 10:29 pm
by dmalves
I changed the beginning of the shader to

extern Image map;
extern float x;
extern float y;
extern number zoomx;
extern number zoomy;
extern number fov;
extern number offset;
extern int wrap;


and I was able to make it work on Linux and Android 6. I took a screenshot from Android 6 on landscape image mode.

Image

It looks like that uniforms shouldn't be initialized on the shader.

Re: Playmat - A Mode 7 Library

Posted: Fri Jan 06, 2017 4:49 am
by alberto_lara
I'm using NES zelda map, twice (8192 × 1408 pixels), rendering 1024 sprites and it is still 60 FPS, nice!

Image