Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / perspective stretching/distortion of sprites? set sprite texture coord?

Author
Message
Randy Lahey
13
Years of Service
User Offline
Joined: 3rd Jan 2013
Location:
Posted: 3rd Jan 2013 17:50 Edited at: 4th Jan 2013 14:53
hi, im trying to stretch a sprite into perspective, i.e. shrink the top and stretch the bottom:
like this, square
[]
to this:
_
/_\

is it possible with the "set sprite coord 0,0,0,0" command?
i cannot get it to work right, guess i dont really understand how the UV values work, been trying stuf like this:

anybody care to help with this?

-alternative i could use a textured plain, rotate to perspective and grab image, but this seems to slow as i need it many times per frame

edit:attached is an image of pasted sprites picturing blue or green squares, after the above code has been used, they are strangely misshaped
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Jan 2013 23:49
I see what you mean.

You could try using plains and the 3D commands instead, I suppose.

I tried this, but as you say, it doesn't quite work (simple test image attached):

Randy Lahey
13
Years of Service
User Offline
Joined: 3rd Jan 2013
Location:
Posted: 4th Jan 2013 14:50
thank you for posting a good example of what im trying to do, green gandalf

using 3d plains is not gonna be fast enough, but maybe theres a third aproach? maybe some kinda sprite-plugin has this function?

ive spent more time on this problem than id like to admidt, cant tell if this really IS a difficult thing to do, or im just to newb

any help would really be apreciated!
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 4th Jan 2013 16:13 Edited at: 4th Jan 2013 16:15
Quote: "using 3d plains is not gonna be fast enough"


How so? By using the vertexdata commands to edit the vertex positions of the plain, you'll easily be able to get enough speed.

The only problem I see with 3D plains is that you can't stretch one vertex so it overlaps a face.

There are two approaches that I can think of right now.

1) Manually transform and interpolate the pixels using memblocks.
2) If you want a fast solution, write a shader and use it in combination with Image Kit. [EDIT] In particular look at Sven B's post here.

TheComet

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 4th Jan 2013 18:18
Quote: "im trying to stretch a sprite into perspective"


How come? What's the mission? Isometric world? Special Effects?

Quote: "using 3d plains is not gonna be fast enough"


Sprites are 3D plains projected in 2D; same speed. Plains are faster if used in the same object; more so in the same limb.

Randy Lahey
13
Years of Service
User Offline
Joined: 3rd Jan 2013
Location:
Posted: 4th Jan 2013 18:49
the goal is to make a procedural planet generator, the problem i am having is regarding the heightmap creation.

in short; i need to correct the spherical distortion of the map.

i have a lot of .png files containing different shapes with transparency, i paste them onto an image, wich is then used as a heighmap, to shape a sphere.
its very fast, and i think it looks pretty good, to me at least, as specialy when combined with something like perlin noise map.
kinda like spore's planets, -in a crude newb version of course


heres an example of how im pasting sprites to a map, might be a little messy:<



i would like this work on-the-fly, and its quick to paste a sprite, but if i have to unlock pixel, set image, rotate object, grab image, make sprite, lock pixel, before pasting each sprite, to get the right perspective, i THINK it would be slow? havent tried, since it seems like a "clumsy" aproach?
but i dunno, i am a beginner at this whole thing
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 5th Jan 2013 00:47
Cool.

I just see myself using a 3D mesh for this kind of thing. There is no wrong or right way; working directly with pixels is viable but a bit dated.

As a 3D orientated DBP user; I think creating a multi vertex grid and simply distorting its vertices to form the sphere map is an automated way of making texture effect; you can even use high-level shaders; you even get 8 layers of images to play without without losing a single frame of performance. This lets the engine do the main work.

If not 3D, then I would look up the sphere mapping algorithm on the forums or in another programming language and reproduce that in DBP using Advanced2D which has rapid drawing capabilities.

Hope it goes well

Randy Lahey
13
Years of Service
User Offline
Joined: 3rd Jan 2013
Location:
Posted: 6th Jan 2013 15:40
thecomet:
Quote: "There are two approaches that I can think of right now.

1) Manually transform and interpolate the pixels using memblocks.
2) If you want a fast solution, write a shader and use it in combination with Image Kit. [EDIT] In particular look at Sven B's post here.
"

1)that might be a good solution, i will attempt that if i dont find something simpler.
2)i havent gotten as far as to even understand shaders yet, so dont really know the possibilities they create, but they are powerfull things i gather

Chris Tate:
Quote: "Sprites are 3D plains projected in 2D; same speed. Plains are faster if used in the same object; more so in the same limb."

i didnt realize that, but how whould i get that 3d object onto an image/texture, at about the same speed? get image from camera?

Quote: "As a 3D orientated DBP user; I think creating a multi vertex grid and simply distorting its vertices to form the sphere map is an automated way of making texture effect; you can even use high-level shaders; you even get 8 layers of images to play without without losing a single frame of performance. This lets the engine do the main work.
"

that sounds intriguing! can i ask you to explain a bit more?
-do you mean; first i create my image as before, then texture a multi vertex grid, which is then "corrected" by moving its vertex, and then grab that image to use as a texture/heightmap.
that could work, but i imagine it would create seams along the side of the sphere, but maybe that could be corrected for when pasting the sprites.

sorry for asking all this, but i fear i might be missing the obvious:/
i only have a basic understanding of whats possible with dbp, and i thought this was a simple task, with the "set sprite coord" command.

i really appreciate you all helping, thank you
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 6th Jan 2013 20:57
No problem whatsoever. I am snowed under at the moment and cannot provide a comprehensive explanation; it's best to break down the task and break your questions into smaller problems.

There are three ways I would go about this; if anyone knows a better way then let us know.

The first is the fastest way because it uses the graphics card, not the CPU. To go about this you might require a copy of Dark Shader. You need to apply shaders to a camera. (I am not sure if vanilla DBP ships with Camera Effects). You would texture a camera, and apply a vertex shader to it. The vertex shader could apply spheremapping or what ever you come up with. You'd need to understand shaders; but if you do not, you can always get help right here; just ask. Its an excuse to learn HLSL, a good investment.

The second way would be easier to understand but is not quite as clean as the first way. With this, you use the Matrix1utilities plugin to create a plane with multiple vertices which you can manipulate by simply changing their coordinates using Vertex Data commands. (A grid). This grid is then set to overlap a camera using the Quad.FX file in your DBP installation folder (somewhere?). You then use Set Camera To Image if you want to apply the texture to an object.

I believe you could also use bitmaps. Bitmap 0 stores camera 0's output, and Bitmap -1 stores camera 1's output; anyway...

The third way is TheComets suggestion; which is to manipulate the pixels in the texture using memblocks. But you need to find the sphere mapping algorithm. This is pure CPU labour so is not the fastest, but may be fast enough.



Comet also mentioned ImageKit, but I do not know much about ImageKit, although I use its filters.

If I were you, I'd choose method one if you want this to be a long term solution; otherwise go for method 2 or 3. Personally, method 2 is easiest.

Here is method 2;
1: Create the plane with N number of grid cells using Matrix1.
2: Texture the plane.
3: Lock the vertex data
4: Move the vertices to form sphere; or simply apply desired distortion.
5: Project the plane to the desired camera using the Quad.FX file (or simply project it from the camera using 3D commands such as [Set Object To Camera Orientation])
6: Ensure that the camera is set to an image using [Set Camera To Image]. That image is your texture.

Randy Lahey
13
Years of Service
User Offline
Joined: 3rd Jan 2013
Location:
Posted: 9th Jan 2013 13:26
thank you for your explanations and suggestions, im gonna have a go at it in the weekend, hope i can figure it out, you certainly helped!

method 2 seems pretty straight forward, but ive never heard of "quad.FX"
Quote: "
5: Project the plane to the desired camera using the Quad.FX file
"

if you have the time or know of any pseudo or example, it would be really helpfull -gonna try searching some more in the weekend

again, thank you
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 9th Jan 2013 18:47
If you purchased DarkSOURCE or DarkSHADER, they come with demonstrations. Also, there are fullscreen demos in the shader pack.

Login to post a reply

Server time is: 2026-07-08 05:58:33
Your offset time is: 2026-07-08 05:58:33