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 Mesh 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.
– Bunny83I'm not sure if this would work, but you could try clamping the velocity of the ball when it hits the floor. rigidbody.velocity = (rigidbody.velocity.normalised * bounciness) this should keep the reflection of the bounce but you get to control the velocity at which the ball hits the ground and so each bounce will be the same height. you could either add this to OnTriggerEnter or OnCollisionEnter. you might want to make a trigger thats slightly larger than the actual mesh so it has time to change the velocity before collision. again not sure if this will work but its worth a shot
– Paricus