shader graph messes up the texture (Unity 2D) - unity3d

i am trying to make a glow shader but. when i add that _MainTex property this happens:-
shaded
shaded wireframe
I tried changing the mesh type to full rect but when i do that this happenfull rect mesh types :-
I don't know whats the problem plzz help , i am new to shader graph and i am using "sprite shader graph unlit" i also tried with but same problem . here's my shader graph :-shader Graph

The Sample Texture 2D node returns a vec4, but your Fragment output only accepts a vec3 and thus ignores the alpha information.
If you want the shader to also use the alpha values of your texture, you should plug the A output of the Sample Texture 2D node into the Alpha input of the Fragment.
You are currently returning the color values of the texture for all pixels and not filtering by alpha.
If this does not work, check if you have to enable translucency for the shader.

Related

How to remove anti-aliasing artifacts inside the object's material HLSL shader (Unity)

I am trying to create a shader that would blend a background's texture with the 3d object's texture. The background texture is a render texture from another camera. I pass it to the shader of the foreground object.
The idea is to achieve an effect of various blendings on the 3d object "in the front".
The fragment shder looks like this:
fixed4 frag(v2f i) : SV_Target
{
float4 color_from_background = tex2D(_BackTex, float2(i.pos.x / _ScreenParams.x, i.pos.y / _ScreenParams.y)); //A
fixed4 surfcol = tex2D(_MainTex, i.uv);
fixed4 c = BlendMode_Multiply(color_from_background,fixed4(surfcol.rgb,surfcol.a * _Transparency));
return c;
}
It kind of works...
Unfortunately due to imprecisions in the division in the line marked with "//A" - I get visible artifacts along the object's edges. In this line I sample the background texture for the blending's input, How to solve that? First thing that comes to my mind is anti-aliasing. But I dont know how to implement it here. I tried to change sampling levels and filtering of the textures but it does not solve the problem.
I attach image that shows the problem. At the top part you can see the artifacts when using the shader. At the bottom the actual object with non-opaque material.
The solution to this is disabling the anti-aliasing in the project settings globally OR in the target render texture settings and camera settings. I only had it off in the target render texture which was not enough

Shader: Mesh Renderer and Sprite Renderer are not respecting sorting order

I have a fbx model that uses Unity's mobile unlit shader and another sprite that uses a custom shader. I have checked that they are both in the same renderer queue, however, they don't draw in respect of the sorting order but of the depth only.
When I have sorting order of the sprite renderer set to 100 and sorting order of the mesh renderer set to 0, I'm expecting to see the sprite drawn in front of the model, regardless of the depth. But that's not what I am getting.
Currently, the 3D model is using Unity's built-in mobile unlit shader (https://github.com/TwoTailsGames/Unity-Built-in-Shaders/blob/master/DefaultResourcesExtra/Mobile/Mobile-Lightmap-Unlit.shader),
and my custom sprite shader has these flags set in a SubShader block:
Lighting Off
Cull Off
ZWrite Off
BlendOp [_OpColor]
Blend [_SrcFactor] [_DstFactor]
Please let me know if there are ways to achieve this?

Using a sprite to mask 3D objects in Unity

I have a png image that I want to work as a transparent mask, where it will be completely transparent in the scene but 3D objects behind it would not be shown (similar to a sprite mask, but needs to work with 3D objects).
So I added the image as a sprite (point - no filter) in my 3D scene and I have a shader already applied to the sprite material, but it is not working properly. Looks like the pixels are not being "cut correctly" in the borders.
I'm using this approach since the unity built-in "2D sprite mask" only affects objects using Sprite Renderer (as explained here https://docs.unity3d.com/Manual/class-SpriteMask.html), but I want it to affect 3D objects.
So this is the shader:
Shader "Masked/Mask" {
SubShader {
Tags {"Queue" = "Geometry+10" }
ColorMask 0
ZWrite On
Pass {}
}
}
This is the sprite to work as the mask (png image):
sprite mask
And these are the result that I want vs. what Im getting:
results compared
Im not good with shaders, so I would like to know if there is a change in the code that can be made in order to improve the result. I've already tried different formats for the sprite image (png, tif, compressions), but the results are the same.
I've done something similar using 'transparent' 3D occluders and render priorities, I imagine it would be similar with sprites...
Render non-occludable geometry (including Sprite) {"Queue" = "Geometry"}
Render occludable geometry {"Queue" = "Geometry+1"}
Strictly speaking, your occluder (the sprite) only needs to render to the depth (Z) buffer if it's always transparent.

Unity Repeat UV Coordinates On Quadtree Shaderforge

As u can see in the image, on larger tiles (n > 1) the texture should be repeated as long as the current rect size.. i don't know how i can achieve this!
FYI, im getting the tile texture id with the alpha value of the vertex color.
Here the shader im using..
[UPDATE]
Thanks for clarifying the uv coordinates, unfortunately that doesn't answer my question. Take a look at the following pixture...
Your shader is fine; it's actually the vertex UVs that are the problem:
So for all rectangles the uv coordinates are as following [0, 0] / [0, rect.height] / [rect.width, 0] / [rect.width, rect.height]. So the uvs are going beyond 1
Your shader is designed to support the standard UV space, in which case you should replace rect.width and rect.height with 1.
By using UV coords greater than one, you're effectively asking for texels outside of the specified texture. When used with a texture atlas, that means you're asking for texels outside of the specified tile -- in this case, those happen to be white, and that's what you're seeing in the rendered output.
Tiling with an atlas texture
Updating because I missed an important detail: you want a tiling material.
Usually, UVs interpolate linearly:
For tiling, you essentially want more of a "sawtooth" output:
For a non-atlas texture, you can adjust material scale/wrap settings and call it done. For an atlas texture, it's possible but you'll end up with a shader and/or geometry that aren't quite standard.
The "most standard" solution would be if your larger quads are on a separate mesh from the smaller ones:
Add a float material param named uv_scale or some such
Add a Multiply node that scales incoming UVs by uv_scale
Pass output from that into a Frac node
Pass output from that into the UV Tile node
Pseudocode is roughly: uv = frac(uv * uv_scale)
If you need all of your quads to be in the same mesh, you end up needing non-standard geometry:
Change your UVs again (going back to rect.width and rect.height)
Add a Frac node before the UV Tile node
This is a simpler shader change, but has the downside that your geometry will no longer be cleanly supported in other shaders.
Thanks rutter!
i've implemented your solution into my shader and now it works perfectly!
so for everyone looking for this here is the shader im using now
Cheers, M

How to do texture mapping in openglES? ( Mapping 2D face into a 3D mesh )

I need to convert a 2D face image to a 3D image. For this I thought of using texture mapping with openglES. I tried a lot googling to find some samples I couldnt get any. Can some one guide me to do this?
Input: 2D image
Output : 3D image
Platform : ios
As you know, OpenGL is using 3D or 2D vertices that has a few attributes such as position, normal value, color, texture coordinate. So you should set these values first and you can render.
In ES 2.0 clearly you have to give these values to Vertice Shader
and then you have to transfer two values texture coordinate , normal value to Fragment Shader
and then in Fragment Shader, you can control these values with sampler texture for rendering your face object.
If you work In IOS, It's going to be very help .
Explanation :
http://ofps.oreilly.com/titles/9780596804824/chtextures.html
Source Code :
http://www.developers-life.com/iphone-3d-samples.html