- Home /
Weird shader thing
Hi,
I'm making a terrain blending shader that uses 2 blendmaps , for now i'm just testing one. But when i just use:
o.Albedo = b1;
b1 being the first blendmap it only gives me a solid red like ii only takes the first pixel of the blendmap.
Here's the full shader:
Shader "Terrain/6lyr_2tex_terrain" {
Properties
{
_blend1 ("Blendmap 1", 2D) = "white" {}
_blend2 ("Blendmap 2", 2D) = "white" {}
_Layer1 ("Layer1", 2D) = "white" {}
_Layer1n ("Layer 1 normal", 2D) = "white" {}
_Layer2 ("Layer2", 2D) = "white" {}
_Layer2n ("Layer 2 normal", 2D) = "white" {}
_Layer3 ("Layer3", 2D) = "white" {}
_Layer3n ("Layer 3 normal", 2D) = "white" {}
_Layer4 ("Layer4", 2D) = "white" {}
_Layer4n ("Layer 4 normal", 2D) = "white" {}
_Layer5 ("Layer5", 2D) = "white" {}
_Layer5n ("Layer 5 normal", 2D) = "white" {}
_Layer6 ("Layer6", 2D) = "white" {}
_Layer6n ("Layer 6 normal", 2D) = "white" {}
}
SubShader
{
Tags { "Queue"="Geometry" "RenderType" = "Opaque"}
Cull Back
CGPROGRAM
#include "UnityCG.cginc"
#pragma surface surf Standard
#pragma target 3.0
sampler2D _blend1;
sampler2D _blend2;
sampler2D _Layer1;
sampler2D _Layer1n;
sampler2D _Layer2;
sampler2D _Layer2n;
sampler2D _Layer3;
sampler2D _Layer3n;
sampler2D _Layer4;
sampler2D _Layer4n;
sampler2D _Layer5;
sampler2D _Layer5n;
sampler2D _Layer6;
sampler2D _Layer6n;
struct Input {
float2 uv_Blend : TEXCOORD0;
float2 uv_Layer1 : TEXCOORD1;
float2 uv_Layer2 : TEXCOORD2;
float2 uv_Layer3 : TEXCOORD3;
float2 uv_Layer4 : TEXCOORD4;
float2 uv_Layer5 : TEXCOORD5;
float2 uv_Layer6 : TEXCOORD6;
};
void surf (Input IN, inout SurfaceOutputStandard o)
{
float4 b1 = tex2D (_blend1, IN.uv_Blend);
float4 b2 = tex2D (_blend2, IN.uv_Blend);
float4 l1 = tex2D (_Layer1, IN.uv_Layer1);
float4 l2 = tex2D (_Layer2, IN.uv_Layer2);
float4 l3 = tex2D (_Layer3, IN.uv_Layer3);
float3 l1n = UnpackNormal(tex2D (_Layer1n, IN.uv_Layer1));
float3 l2n = UnpackNormal(tex2D (_Layer2n, IN.uv_Layer2));
float3 l3n = UnpackNormal(tex2D (_Layer3n, IN.uv_Layer3));
float4 l4 = tex2D (_Layer4, IN.uv_Layer4);
float4 l5 = tex2D (_Layer5, IN.uv_Layer5);
float4 l6 = tex2D (_Layer6, IN.uv_Layer6);
float3 l4n = UnpackNormal(tex2D (_Layer4n, IN.uv_Layer4));
float3 l5n = UnpackNormal(tex2D (_Layer5n, IN.uv_Layer5));
float3 l6n = UnpackNormal(tex2D (_Layer6n, IN.uv_Layer6));
o.Albedo = l1.rgb * b1.r;
o.Albedo += l2.rgb * b1.g;
o.Albedo += l3.rgb * b1.b;
o.Alpha = 1;
o.Normal = (l1n.rgb * b1.r) + (l2n.rgb * b1.g) + (l3n.rgb * b1.b);
//o.Albedo = b1;
}
ENDCG
}
FallBack "Diffuse"
}
And when trying to blend it only shows the first layer fully, nothing else. Since Unity5 i find that some simple shader things don't work anymore.
You use 7 different texture coordinates? Unity's $$anonymous$$esh class only supports 4. How you you set the texture coordinates? Are you sure that you provide the correct UV data in each channel? Usually one channel is enough so your code is a bit confusing.
Still when removing all the Texcoords it's not working , i only use one UV0 channel so that's not the problem , uv's are also correctly unwrapped in max but stil the terrain gives me only the first texture and nothing else.
Well, try this ins$$anonymous$$d:
o.Albedo = IN.uv_Blend;
or whatever UV channel you use now. This should give you a gradient. If it still is all red your UVs aren't right. $$anonymous$$ake sure your UVs are either inside the range 0.0 and 1.0 or set the textures wrapmode to "wrap" if you use values outside that range.
edit
If you're still not sure if the UV is setup correctly, you can put my UVViewer into an editor folder inside your project. You can open the viewer via the menu "Tools / B83 / UVViewer". Note when you open it the first time the script generates two shader and two materials inside the resources folder which are then reused each time you use it. If you don't need / want the viewer anymore just remove those as well.
If the UVViewer window is open you just have to select your object in the scene. You can pan with any mouse button and zoom with the scroll wheel. Holding CTRL while moving the mouse will display information of the closest vertex. It will also highlight the vertex in the scene view.
Answer by kilian277 · Jul 15, 2016 at 09:15 PM
Okay so i found the problem , really stupid one.
Turns out the uv variable i used was wrong i named the sampler2D _blend1 so in theory it should have been
float2 uv_blend1;
//and not
float uv_Blend;
Your answer
Follow this Question
Related Questions
Sprite texture incorrect 0 Answers
[Shader] How to use Blend SrcFactor DstFactor, SrcFactorA DstFactorA 1 Answer
Logical BlendOp not working 0 Answers
Writing a shader for a terrain? 0 Answers