A large gameplay element of my game is orbiting around planets with a ship, and I use grids that are distorted like a space time field to illustrate that to make orbiting easier for the player. Here is a screenshot of what I have so far…
Right now, however, this is done by shifting the vertices of several grid pieces, planes that are stitched together in the editor window. This is pretty inefficient, as even the planes that need to be updated (the ones that are unaffected lie dormant) have to run through each of their vertices every frame to see where they should be stretched.
A friend mentioned that this would be enormously faster if I did this with a fragment shader. Now, I’m fairly new to programming and haven’t really used shader lab or cg before. I would very greatly appreciate any help with this, if someone could walk me through it or had the time to even write a rudimentary shader for me.
The shader needs to expand the texture near gameObjects in the world, and should expand more or less based on the strength of the object, which would be assigned in a separate script attached to that gameObject. The alpha of the plane would need to increase (become less opaque) as the amount of stretch decreased, and would eventually fade to be completely transparent.
Depending how dense the plane is, you might be better doing this in the vertex shader.
I need to write a grass shader anyway, that my character can brush out the way as she walks past and I think the system’d be similar (pass in a world coordinate and a radius, make the verts avoid the point) so I’ll give it a go.
thank you so much… the plane should be about as dense as it is in that picture. (8x8 polygons each object) maybe a little more. also, it’s highly critical that I can control the number of points to be avoided and the radius of each from outside the shader.
if this helps at all, in the function in my script that I have now has 5 values…
r, the radius to be effected
amp, the amplitude of how much it should pull the vertices
exp, the exponent that factors how the pull looks (convex if exponent is lower than 1, concave if exponent is higher than 1) and how the steepness of the curve.
x, which is irrelevant to you, just determines the x coordinate of the point that is affecting the grid
z, which works the same way as x on the z axis
there shouldn’t need to be that many points in any plane at a given time…maybe 5 or 6? There are going to be a lot of small pieces to the grid instead of one large mesh. However, I don’t understand why there would be a limited amount of points, that doesn’t make sense
alright. well, It’s worth a shot at least. I wouldn’t be able to tell you how to do it from there, because my script uses an array for every object on that current grid piece. I don’t think it will matter if its not able to detect an unlimited amount of items in front of it, but the current solution right now is as optimized as I believe it can be, so i think its definitely worth trying
Just a suggestion but what if you rendered a warp vector to a render texture via something like an additive sprite/plane then used that to warp your screen?
You could have as many influencing objects as you like until the fill-rate becomes too much. My guess is though you might get away with a render texture thats half your full screen rez or less.
thanks for the help guys. And yes, I have pro. Which of these snippets would you guys recommend using with the grid? Is there any way I can get them to handle more than one object? That is crucial.
update: works perfectly. I only wish there was a way I could set the radius and falloff of the alpha…right now its a bit of a harsh line for something small like the player object.
What other options do I have, since I’m using pro and the game is orthographic?