Playmat - A Mode 7 Library

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
yetneverdone
Party member
Posts: 351
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: Playmat - A Mode 7 Library

Post by yetneverdone » Wed Jan 04, 2017 9:02 am

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?

User avatar
pgimeno
Party member
Posts: 1909
Joined: Sun Oct 18, 2015 2:58 pm
Location: Valencia, ES

Re: Playmat - A Mode 7 Library

Post by pgimeno » Wed Jan 04, 2017 12:07 pm

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.

User avatar
Davidobot
Party member
Posts: 1149
Joined: Sat Mar 31, 2012 5:18 am
Location: Game-Dev. Land
Contact:

Re: Playmat - A Mode 7 Library

Post by Davidobot » Wed Jan 04, 2017 1:26 pm

yetneverdone wrote:wow, very awesome. Possible to make doom-esque fps?
Ahum..
My library:
LovelyMoon

Check out my current project:
Raycaster

Oh hey, I have a website now!

User avatar
hatninja
Prole
Posts: 30
Joined: Sun Apr 07, 2013 1:31 am
Contact:

Re: Playmat - A Mode 7 Library

Post by hatninja » Wed Jan 04, 2017 10:09 pm

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!

User avatar
alberto_lara
Party member
Posts: 331
Joined: Wed Oct 30, 2013 8:59 pm

Re: Playmat - A Mode 7 Library

Post by alberto_lara » Wed Jan 04, 2017 10:16 pm

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 102 times
EDIT 2: The map image has to be a square, right?
LÖVE Projects: GOOi, Süsse and Katsudö
Thank you for taking the time to read this

User avatar
hatninja
Prole
Posts: 30
Joined: Sun Apr 07, 2013 1:31 am
Contact:

Re: Playmat - A Mode 7 Library

Post by hatninja » Thu Jan 05, 2017 12:00 am

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!

User avatar
alberto_lara
Party member
Posts: 331
Joined: Wed Oct 30, 2013 8:59 pm

Re: Playmat - A Mode 7 Library

Post by alberto_lara » Thu Jan 05, 2017 3:46 am

EDIT: It is now fixed! You can check out the newest version at github!
Thanks!
LÖVE Projects: GOOi, Süsse and Katsudö
Thank you for taking the time to read this

User avatar
raidho36
Party member
Posts: 1953
Joined: Mon Jun 17, 2013 12:00 pm

Re: Playmat - A Mode 7 Library

Post by raidho36 » Thu Jan 05, 2017 9:14 pm

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.

User avatar
dmalves
Prole
Posts: 3
Joined: Thu Aug 25, 2016 10:53 pm

Re: Playmat - A Mode 7 Library

Post by dmalves » Thu Jan 05, 2017 10:29 pm

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.

User avatar
alberto_lara
Party member
Posts: 331
Joined: Wed Oct 30, 2013 8:59 pm

Re: Playmat - A Mode 7 Library

Post by alberto_lara » Fri Jan 06, 2017 4:49 am

I'm using NES zelda map, twice (8192 × 1408 pixels), rendering 1024 sprites and it is still 60 FPS, nice!

Image
LÖVE Projects: GOOi, Süsse and Katsudö
Thank you for taking the time to read this

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 8 guests