Variations in sprite shape textures - unity3d

I am currently trying out how to work with sprite shapes. I know how we can put different textures on different angles but Suppose i wanted to make variations with different images(sprites) on a single surface. For example, i want to make spots with puddle textures on a grass plain land. How will i do that?
I tried adding different textures in different angles but I couldn't figure out how i can change the repeating texture and make variations in a single surface in a sprite shape.

Related

Painting Polygon Shaped Areas on Terrain/Surface/Ground in Unity

I have a set of 2D polygon shapes, each one with a varying amount of points that are determined at runtime.
I need to draw (or "paint") these polygons on top of a surface.
I also need to fill in the areas of each polygon with a specific color that is also determined at runtime.
The polygons only really need to be drawn once, however solutions that would allow me to update/change the colors would be nice.The project will be built for WebGL.
The polygons are to mark of specific areas on a surface so they shouldn't repeat.
Polygons can overlap with eachother
What are the different/best solutions that may help me achieve this?
Am also open to suggestions and further reading
I'm a relative Beginner to Unity but a somewhat experienced programmer and know a slight bit about shader programming.
By polygons I don't mean geometry I just mean a regular shapes I would like to paint on to a surface. Its just that I will always have polygons with a varying amount of points that are loaded in at runtime.
First, u need to split the surface into that polygon then u need to have materials on them and the code that specifies the colour should update the colour of the material which is on that specific polygon. Creating materials could be done in code to avoid a lot of work in a simple loop.

How to blend textures on 2 objects

I am writing a topdown shooter, where the player constantly moves to the right to progress. I cubes (plates) that are used as the floor as the player advances through the game.
Each plate has a different texture - snow, grass, etc - which I choose at random.
The question - how do I blend the textures on one plate with the following plate. I assume I will have to spawn them overlapping, but I don't know what technique to use to gradually transition from one to the other.
I'm not looking for a full written solution, just a nudge in the right direction so I can look up the right terms to start learning how to do this.
Vertex Colors: You could color each cube with vertex colors, but that would typically limit you to 3 or 4 different textures to blend between... Also the transition is hard when the cubes are just overlapping. If you have a single object (consisting of connected cubes) you could make use of the blended vertex colors.
The texture blending can be achieved like this:
Vertex Colors blue and black, you can see the blending between the areas (blurry gradient)
If you blend like this:
You will get this:
And if you also use a height-map + PBR maps, it can look like this:
I guess this approach is very limiting to the number of possible blocks.
Tiles:
Like in 2D Tile Editors, you need to model/texture different objects to use between your cubes. Example:
Grass Cube - Transition Cube - Sand Cube
And then you need a transition Cube for every possible transition.
The amount of required transitions grows fast when you add base blocks!
Tiles Source Kenney.nl
That could be combined with Wave Function Collapse which was used in TownScaper.

How to texture mesh? Shader vs. generated texture

I managed to create a map divided in chunks. Each one holding a mesh generated by using perlin noise and so on. The basic procedural map method, shown in multiple tutorials.
At this point i took a look at surface shader and managed to write one which fades multiple textures depending on the vertex heights.
This gives me a map which is colored smoothly.
In tutorials i watched they seem to use different methods to texture a mesh. So in this one for example a texture is generated for each mesh. This texture will hold a different color depending on the noise value.This texture is applied to the mesh and after that the mesh vertices are displaced depending on the z-value.
This results in a map with sharper borders between the colors giving the whole thing a different look. I believe there is a way to create smoother transitions between the tile-colors by fading them like i do in my shader.
My question is simply what are the pro and cons of those methods. Let's call them "shader" and "texture map". I am lost right now, not knowing in which direction to go.

Sprite Kit Physics Body Complex Shape - Spritekit

I have this situation: http://mokainteractive.com/example.png
I'd like to move the white ball inside the red track and detect wherever the balls touch the limit of the red track.
Which is the best solution? I have to create multiple transparent shape along the borders? Do you have other ideas?
thanks so much
In iOS8 you can create a single physics body for that kind of shape.
Make a texture of your shape with p.e. Adobe Illustrator and use this method:
init(texture texture: SKTexture!,alphaThreshold alphaThreshold: CFloat,size size: CGSize) -> SKPhysicsBody
The SKTexture is your shaped image. The body is defined by the colored pixels.
The alphaThresHold: The minimum alpha value for texels that should be part of the new physics body.
The Size is clear I think.
The texture is analyzed and all invisible pixels around the egg are ignored and only the color pixels are interpreted as the body of the SKPhysicsNode. You should use too many of these because they are very expensive to calculate for the Physics Engine.
Variations of this method are found in the SpriteKit Class Reference.
To your problem. Make an inverse texture of your area which should be transparent and pass it as texture to the physics body. It will be analyzed and a body around the free zone is created.
You cannot create a single physics body for that kind of shape.
Using bodyWithPolygonFromPath: will only allow you to create a convex polygonal path which obviously does not work for your shape.
I think you have 3 options here:
Use a number of bodyWithPolygonFromPath: bodies (probably the hardest to do and time consuming).
Use a number of various size bodyWithRectangleOfSize: bodies (not so hard but time consuming).
Use only straight lines in your image and use bodyWithRectangleOfSize: (the easiest and fastest). If you choose this option remember you are still free to rotate your straight lines to various angles.

How to use a different texture on intersecting part of 2 quads

I'm looking for a way to dynamically change a part of a Quad that has a SpriteRenderer attached to it. Let's say I have a red Quad and a blue Quad, and then I drag one onto the other (fast or slow), the intersecting part should be colored using a green sprite. This illustration shows the scenario I'm trying to solve.
Can someone please help me with this?
You have two options:
First, if your mid color will be the correct mixture of other two color, in this case it would be yellow, you can use Mobile Particle/Additive or Mobile Particle/Multiply Shaders.
In a second way, you can write your own shader that takes the intersection area as parameter and paint your textures according to parameters.