Page 1 of 2

Scripted Textures

Posted: Tue Sep 10, 2019 4:33 am
by Marisa the Magician
Interest for this kind of thing has resurfaced again. You may remember the horrendous hack that was phantombeta implementing the psx fire as a camera texture displaying a grid of sectors changing color. Someone really needs to put an end to this madness and actually make this. I don't know if I could, though, it sounds like such a monumental task and I don't have enough time to work on anything like that. The way I'm thinking about it would involve moving all the 2d drawing code back to the DCanvas class, then make it so the Screen.* API works on instances of it rather than on the global screen framebuffer (which would be moved to the zscript globals, for backwards compatibility). Obviously ANIMDEFS would have to be expanded for creating these, just like it does for camera textures.

There really shouldn't be any concerns over performance when it comes to this, since we'd be using the renderer's own facilities for drawing, rather than working on raw pixels.

Re: Scriptable Canvas Textures

Posted: Tue Sep 10, 2019 6:41 am
by Graf Zahl
Forget the canvas, that part will never work. The 2D drawing is completely hardware accelerated, the canvas is just a software buffer.

This is certainly doable but will require quite a bit of backend work - and if you want software renderer support some exporting facility of the created texture

Re: Scriptable Canvas Textures

Posted: Sun Jan 24, 2021 8:36 am
by Marisa the Magician
OK, massive frustration with a gross hack involving camera textures not working properly depending on the map has forced me to bump this thread. WE ABSOLUTELY NEED THIS.

Re: Scriptable Canvas Textures

Posted: Sun Jan 24, 2021 8:49 am
by Graf Zahl
We need *what*? You got to be a bit more precise about your intents.

Re: Scriptable Canvas Textures

Posted: Sun Jan 24, 2021 8:54 am
by Nash
I think what Marisa is saying is that people have been abusing camera textures to approximate scriptable textures (with varying degrees of success) and we all know what happens when features are used in ways they're not designed to do, therefore she's suggesting proper, Unreal Engine-style scriptable textures.

Re: Scriptable Canvas Textures

Posted: Sun Jan 24, 2021 9:35 am
by Graf Zahl
The suggestion says "scriptable canvas texture', so this needs clarification.

Re: Scriptable Canvas Textures

Posted: Sun Jan 24, 2021 10:09 am
by Rachael
I think a better name for this thread would be "Scriptable Textures" - which would work for both canvas and materials (i.e. object or geometry textures).

Re: Scripted Textures

Posted: Sun Jan 24, 2021 12:00 pm
by Marisa the Magician
Changed the thread title.

What I'm proposing, in simpler terms, is textures that can be drawn to from ZScript, like one would do drawing on the screen itself.

Re: Scripted Textures

Posted: Mon Jul 25, 2022 11:34 am
by Marisa the Magician
Well, it's been some time, but I guess this one can be closed as [Added].

Absolutely huge thanks to dpJudas for making the dream come true. :cheers:

Re: Scripted Textures

Posted: Mon Jul 25, 2022 11:55 am
by Gez
So, technically, could the PSX fire sky be implemented this way now? What would the code look like?

Re: Scripted Textures

Posted: Mon Jul 25, 2022 1:10 pm
by Marisa the Magician
Probably a lot of calls to drawtexture with a 1x1 pixel texture. :wink:

Re: Scripted Textures

Posted: Mon Jul 25, 2022 1:18 pm
by Graf Zahl
ZScript may be too slow to do textures that are programmatically generated per pixel. Even in the best of cases it may be too slow even with JIT due to all the range checks

Re: Scripted Textures

Posted: Mon Jul 25, 2022 1:35 pm
by Rachael
For per-pixel we can reduce range checks to one check by allowing a special per-pixel texelation command to have a single one-dimensional addressing scheme which will access the entire texture. That should increase the speed of per-texel scripting a little bit. Bonus: cast it to an unsigned integer to reduce the checking even further since negatives will then always fail the check.

Re: Scripted Textures

Posted: Mon Jul 25, 2022 2:42 pm
by Major Cooke
And out of curiosity, how does one do this now? I'd love to see an example!

Or the main functions can work.

Re: Scripted Textures

Posted: Mon Jul 25, 2022 3:17 pm
by Nash
From the pull request thread by dpJudas:
This adds support for creating canvas textures in ANIMDEFS using same syntax as for camera textures (except the keyword is canvastexture instead).

On the zscript side the texture can be drawn into using the following method:

Code: Select all

Canvas canvas = TexMan.GetCanvas("mycanvastexture");
canvas.Clear(0, 0, 64, 128, Screen.PaletteColor(123));
canvas.DrawText(bigfont, Font.CR_ORANGE, 0, 0, "HELLO!");