Request: Faux Parallax Shader (2D)

For questions about using Classic.

Post » Wed Dec 16, 2009 6:46 am

Ok, unless it's PHP or mySQL related, I can't program worth shit. I've tried to learn how to create shaders, read tutorial after tutorial but it just ain't happening, they all seem to miss out the actual part where you want the shader to do something and instead focus on setting it up. Yeah no good.

So I'm making this request for someone to write an .fx shader for construct, using the following guidelines and information. It does nothing that shouldn't already be possible within the program, and even uses some known limitations to its advantage.


For someone experienced in writing .fx shaders, it should be childsplay. For someone like me, it's up there with reading C++ for dummies over the weekend and then writing an MMORPG from scratch - not gonna end well. :)

Credit and stuff like that, you wrote it, you get all the credit. I've just made this request is all, and really want to see one done, as I do have a great need for it lol. So anyone who cares about getting credit where it's due, don't worry on that score. Sell it as your idea afterwards and make millions all to yourself, lol.


Since a simplified version of this shader requires no depth, or 3D. I think it could work.

What it does/should do
Think of it (in this sense) as a self contained miniature parallax effect, because essentially that's what it is. But it must only work on the layer it's on, ignoring transparent area's of the layer (as is my understanding from what Ashley has said, a shader will not effect anything beyond their bounding box, which is perfect for this).

You have your image, for example a brick wall. This is the colorful pretty image the player sees. Above that you have a bog standard height map, black is the lowest point, white is the highest point, again nothing spectacular or never done before in construct. Set that one up to always follow the position of the brick wall.

The shader would then be applied to the height-map image, like with other available shaders. For it to work correctly, you would then have to tell it via an event, where the center point's X and Y is located in relation to the display window as well as the "imagined" depth of the height map.

This is where the fun begins - as the sprite moves away from the center point, the shader uses the grayscale height-map to push, drag and pull on the pixels below it. Each shade of gray moving slightly slower than the value above it. With the white 255,255,255 pixels moving the fastest, while the black ones don't move at all. This then in turn causes some pixels to be squashed (vanish to the eye) while others are stretched. If used carefully, this gives the impression of thinking you can see more of one side than the other.

Yeah, it's a down right dirty cheap trick, but it can work really well if it's not abused. Not only would you have your regular layers moving at different speeds with a nice parallax effect, but your chosen objects would also appear to have a kind of depth to them also.

Event Options
Besides the usual on/off options, the shader should have the following available:

Center point X
Center point Y

These two options above tell the shader where the optimum point is for viewing the image with no distortion. Generally this would be the exact center of the display screen, but in many cases you might want it to follow the Y level of the player, or even control it by the mouse.

Depth Z
No, this isn't asking for depth in a 2D world. What this would do is basically tell the shader how fast to distort the white pixels in relation to the other shades of gray. A larger Depth Z would result in a faster distortion as the object moved away or toward the center point, while a lower depth would result in a more subtle distortion. Unfortunately I can't do the math for this bit, would be something like "move X pixels Y distance for every Z pixels away from the center point" ? I think, yeah something like that. ;)

Limitations
The user would have to fine tune the shader to their game, as screen size and sprite size would have a big part to play in getting it right. What depth Z setting would work for one game, could look terrible for another. Remember, the pixels are just being stretched and shrunk, so eventually at a certain distance, the entire sprites texture will be stretched beyond recognition by the shader.. Obviously you want this to happen off screen, so the player can't see it.

It wont make everything 3D, it's still a 2D trick and is only capable of creating a subtle effect which would be ruined by overdoing it (such as increasing the depth too high in the attempt to try make something look 3D). It'll break and result in badly stretched underlying sprite textures if the depth is too high. A rule of thumb would be the perceived distance between the pure black area's and the pure white area's should not be too great. Walls, deep surface textures etc. are fine, views from above a city with tall buildings are not.

It could bugger up collision detection in some cases (unless using containers and another object as the collision box), and IMO should just be used on background tiles and sprites for best effect.

It probably wont work on lower DirectX pixel shader versions. But as it's nothing more than a visual effect and not related to gameplay, I don't see that as a concern.

Like with using normal maps or shaders in general, it does practically double everything it's being used for. Though because the effect doesn't have to be pixel perfect, you can get away with using height-maps that are half or three quarters smaller than your sprites texture and still get a good result.

-

I'll note that it is similar to the sprite's distort options, however I've had little luck in finding useful tips on using distort maps, especially for creating something like this, and a shader would just do it all much more easily, at least that is my understanding of distort maps.. unless someone wants to make a cap doing exactly what my request for a shader would do *hint hint* lol. Though bare in mind, this shader effect would be usable on many, many, many different sprites of different shapes and sizes and appearance. Could a distort map also be used in such a way too, without it taking forever to create. While distort maps have their uses, I think this would be something best left to the proposed shader effect.
B
3
S
2
G
3
Posts: 628
Reputation: 2,531

Post » Wed Dec 16, 2009 7:20 am

Couldn't you just create a mesh out of the heightmap and be done with it?
B
16
S
8
G
4
Posts: 136
Reputation: 3,144

Post » Wed Dec 16, 2009 7:25 am

[quote="Daiz":10f2fa4z]Couldn't you just create a mesh out of the heightmap and be done with it?[/quote:10f2fa4z]

Don't know how, and how complex would that be to do with a large number of very different looking images? Some could be walls, some bark on tree's, some rocks in the ground, some window frames, some weird looking plants. I couldn't find much info on mesh/distort but by the looks of it you have to plot out the intersecting points of a grid across an image, that would be nigh on impossible for something like this :(
B
3
S
2
G
3
Posts: 628
Reputation: 2,531

Post » Wed Dec 16, 2009 9:19 am

You have to create the heightmap via some means anyway, so you could just write a simple construct app for yourself that makes meshes based on heightmaps and then saves them so that they can be loaded at runtime.
B
16
S
8
G
4
Posts: 136
Reputation: 3,144

Post » Wed Dec 16, 2009 10:00 am

[quote="Daiz":1w2rmb4q]You have to create the heightmap via some means anyway, so you could just write a simple construct app for yourself that makes meshes based on heightmaps and then saves them so that they can be loaded at runtime.[/quote:1w2rmb4q]

Ok scratch everything I had just written in this reply and had to delete after finding a mesh editor in the tools directory. Ok so meshes basically do (I think) what I'm looking for. Only loading a mesh in makes no difference to the sprite, so any changes made in the mesh editor are ignored. Unless you have to then edit each and every column and row in a sprite by hand.. ouch, considering the number of colums and rows that would be required per sprite.

Yeah, a shader will just be so much easier and more logical, even if the final effect wont be as pronounced as it would by using meshes, I'm afraid they're not an option until there's some documentation about them and a way to do hundreds of sprites automatically using height maps.

Thanks though, I'm sure I'll find a use for meshes with something else, they do look useful, just impractical by the looks of it for this kind of thing. :( Shame though, they could have done an awesome job otherwise. :(
B
3
S
2
G
3
Posts: 628
Reputation: 2,531

Post » Wed Dec 16, 2009 9:59 pm

[quote:24iqqnos]Credit and stuff like that, you wrote it, you get all the credit[/quote:24iqqnos]
:lol: I think that goes without saying. Otherwise I need to call my lawyer, some people owe me!
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Wed Dec 16, 2009 10:04 pm

Also, a shader makes it VERY slow.

Really. It's slow, even in modern hardware. For that performance, I'd rather go full 3D.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Wed Dec 16, 2009 10:25 pm

mmf2 has this in an extension I think, parallaxer object I think.
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Wed Dec 16, 2009 11:19 pm

[quote="Davioware":3vbtagju]mmf2 has this in an extension I think, parallaxer object I think.[/quote:3vbtagju]

How well does it work in that? Hmm just checked it out on youtube, works fast, and shows it can be done, well something similar to meshes anyways.

The shader request just distorts the image depending on brightness (height map) and distance from a point.

[quote="Madster":3vbtagju]Also, a shader makes it VERY slow.

Really. It's slow, even in modern hardware. For that performance, I'd rather go full 3D.[/quote:3vbtagju]

I think that's just the case for the parallax occlusion shaders. This one would basically do what the distort shader does, only differently. Meshes would work great if the tools were there, but currently for what I need, they're not practical (they'd work fine in a shoot-em-up or top down game tho). I can't create something that converts height maps to .mesh files. I wouldn't even know where to begin. Each one would be different shapes.

Though saying that, even meshes would have issues, as it would be effectively making displacement mapping for everything, and anyone in 3D could tell you that's a killer for real time, hence the creation of shaders to approximate the effect of there being more polygons than there is. A mesh wouldn't have the polygon resolution to capture the difference in height between stones in a wall or the knarly shapes found in the bark of a tree like the shader could. Even though using meshes would allow for better looking depth, and even interesting effects such as overhanging objects, arches and so on (from the side) that change position convincingly.

Bleah, it's not fair, lol!

Doing them by hand would be out of the question for a few reasons

1 ) too many of them (talking well over a thousand or more - no not on screen all at once, hehe)

2 ) matching the edges of each sprite up using the mesh tool, can't be done by hand, would result in lots of gaps and constant refining to the point it would never be done. While #1 isn't too bad, #2 would ruin all the hard work and effort.

I do agree that meshes WOULD work better, and ultimately look better. But unless someone can come up with a way to convert height maps to mesh files (which would IMO be the best method of "modeling" mesh files in construct), then for what I need, a shader like requested is still probably the only way to go.


There is one other option, that would be to create each level of object movement as a separate layer, but yeah, ouch ouch ouch, lol! There's going to be enough real parallax layers going on without adding 20+ per sprite, so that's like a worst case scenario hehe.
B
3
S
2
G
3
Posts: 628
Reputation: 2,531

Post » Thu Dec 17, 2009 12:10 am

[quote:2wb9vg16]I do agree that meshes WOULD work better, and ultimately look better. But unless someone can come up with a way to convert height maps to mesh files (which would IMO be the best method of "modeling" mesh files in construct), then for what I need, a shader like requested is still probably the only way to go.[/quote:2wb9vg16]

Here ya go....
[url:2wb9vg16]http://guicon.110mb.com/structure/index.php?act=page&id=2[/url:2wb9vg16]
Shitty host... is shitty, so here's the direct link
[url:2wb9vg16]http://files.getdropbox.com/u/666516/terrastruct.exe[/url:2wb9vg16]
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests