Hi,
Im currently working on creating more advanced shaders (in my opinion), but I am not a graphics programmer by trade.
The release of Unity 4, with DX11 was timed perfectly for my project, so I am very grateful for that and trying to use it to the greatest extent possible. But I am unable to combine my vertex/surface shader with the tessellation.
The tessellation works if I remove everything from my void surf() below “//mask” and my “, out Input o” from my void vert().
The problem is that I need this for my second procedural uv channel.
The shader also works without the “tessellate:tessEdge tessphong:_Smoothness” pragmas.
Anyone an idea what I am doing wrong? The warning I am getting is:
Shader warning in ‘Example/OceanShaderShort’: Program ‘tessvert_surf’, ‘vert’: no matching 1 parameter function (compiling for d3d11) at line 9
and some " implicit truncation of vector type" warnings which I don’t get when I turn off the tessellation.
Shader "Example/OceanShaderShort"
{
Properties
{
_Diffuse("_Diffuse", 2D) = "white" {}
_StartBV ("Vert Blending start", float) = 5
_EndBV ("Vert Blending end", float) = 1
_StartBM ("Mask Blending start", float) = 6
_EndBM ("Mask Blending end", float) = 1
_StartBW ("Wave Blending start", float) = 7
_EndBW ("Wave Blending end", float) = 1
_TerrainScale("_TerrainScale", float) = 1
_BaseTerrain("_UVmask", 2D) = "black" {}
_TerrainTypeWater("_Terrain Type Water", 2D) = "black" {}
_TerrainTypeWater_N("_Terrain Type Water_N", 2D) = "black" {}
_TerrainTypeWater_S("Specular", Range(0,1)) = 0.1
_TerrainTypeWater_SB("Specular Start", Range(0,1)) = 0.1
_EdgeLength ("Edge length", Range(2,50)) = 5
_Smoothness ("Phong Strengh", Range(0,1)) = 0.5
}
SubShader
{
Tags
{
"Queue"="Transparent+1"
"IgnoreProjector"="False"
"RenderType"="Opaque"
}
Blend SrcAlpha OneMinusSrcAlpha
Cull Back
ZWrite Off
ZTest LEqual
ColorMask RGBA
Fog{
}
CGPROGRAM
#pragma exclude_renderers gles
#pragma surface surf BlinnPhongEditor vertex:vert tessellate:tessEdge tessphong:_Smoothness
#pragma target 5.0
#include "Tessellation.cginc"
#include "UnityCG.cginc"
sampler2D _Diffuse;
sampler2D _BaseTerrain;
sampler2D _TerrainTypeWater;
sampler2D _TerrainTypeWater_N;
float _TerrainScale;
float _TerrainTypeWater_S;
float _TerrainTypeWater_SB;
struct EditorSurfaceOutput {
half3 Albedo;
half3 Normal;
half3 Emission;
half3 Gloss;
half Specular;
half Alpha;
};
struct appdata {
float4 vertex : POSITION;
float3 normal : NORMAL;
float2 texcoord : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
float4 tangent : TANGENT;
};
float _Smoothness;
float _EdgeLength;
float4 tessEdge (appdata v0, appdata v1, appdata v2)
{
return UnityEdgeLengthBasedTessCull (v0.vertex, v1.vertex, v2.vertex, _EdgeLength, 0.0);
}
struct Input {
float4 meshUV;
float3 blendVal;
};
float _StartBV;
float _EndBV;
float _StartBM;
float _EndBM;
float _StartBW;
float _EndBW;
void vert (inout appdata v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
float Pi = 3.1415926535;
float4x4 rotationMatrix = float4x4(cos(0.5*Pi), -sin(0.5*Pi), 0.0, 0.0,
sin(0.5*Pi), cos(0.5*Pi), 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
float3 vertexR = mul(rotationMatrix,v.vertex.xyz) ;
float radius = distance(vertexR.xyz, mul(_Object2World, float3(0,0,0)));
float2 polarUV = float2(atan2(vertexR.y,vertexR.x),acos(vertexR.z/radius)*2);
polarUV = polarUV*float2(0.1,0.1);
o.meshUV.xy = (v.texcoord.xy);
o.meshUV.zw = (polarUV);
v.texcoord1.xy = polarUV;
float distRangeV = clamp((_StartBV-(distance(mul (_Object2World, v.vertex).xyz, _WorldSpaceCameraPos.xyz)))*(1/(_StartBV-_EndBV)),0,1);
float distRangeM = clamp((_StartBM-(distance(mul (_Object2World, v.vertex).xyz, _WorldSpaceCameraPos.xyz)))*(1/(_StartBM-_EndBM)),0,1);
float distRangeW = clamp((_StartBW-(distance(mul (_Object2World, v.vertex).xyz, _WorldSpaceCameraPos.xyz)))*(1/(_StartBW-_EndBW)),0,1);
o.blendVal.x = distRangeV;
o.blendVal.y = distRangeM;
o.blendVal.z = distRangeW;
}
inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
{
half3 spec = light.a * s.Gloss;
half4 c;
c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
c.a = s.Alpha;
return c;
}
inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
{
half3 h = normalize (lightDir + viewDir);
half diff = max (0, dot ( lightDir, s.Normal ));
float nh = max (0, dot (s.Normal, h));
float spec = pow (nh, s.Specular*128.0);
half4 res;
res.rgb = _LightColor0.rgb * diff;
res.w = spec * Luminance (_LightColor0.rgb);
res *= atten * 2.0;
res *= s.Alpha;
return LightingBlinnPhongEditor_PrePass( s, res );
}
void surf (Input IN, inout EditorSurfaceOutput o)
{
o.Normal = float3(0.0,0.0,1.0);
o.Alpha = 1;
o.Albedo = 0.0;
o.Emission = 0.0;
o.Gloss = 0;
o.Specular = 0;
//mask
float4 BlendP0 = tex2D(_BaseTerrain,(IN.meshUV).xy);
//start diffuse
float4 WaterA = tex2D(_TerrainTypeWater,((IN.meshUV.xy)*_TerrainScale));
float4 WaterB = tex2D(_TerrainTypeWater,((IN.meshUV.zw)*_TerrainScale));
float4 LerpPWat = lerp(WaterA,WaterB,BlendP0.w);
//Normals
float4 TerNwatA = tex2D(_TerrainTypeWater_N,((IN.meshUV.xy)*_TerrainScale));
float3 UnpackNormalwatA = float3(UnpackNormal(TerNwatA));
float4 TerNwatB = tex2D(_TerrainTypeWater_N,((IN.meshUV.zw)*_TerrainScale));
float3 UnpackNormalwatB = float3(UnpackNormal(TerNwatB));
float3 LerpPwatN = lerp(UnpackNormalwatA,UnpackNormalwatB,BlendP0.w);
o.Albedo = LerpPWat.xyz;
o.Normal = normalize(LerpPwatN);
o.Alpha = IN.blendVal.x*lerp(BlendP0.y,BlendP0.x,IN.blendVal);
o.Gloss = lerp(_TerrainTypeWater_SB,_TerrainTypeWater_S,IN.blendVal.x);
}
ENDCG
}
Fallback "Diffuse"
}




