After a week of research regarding tessellation I managed to build a edge length based tessellation shader based on example shaders I found on the internetz.
I have another shader with working shadows. Now I want to combine both…
I understand how the flow through both shader works and tessellation itself works flawless, shadows too. But now I have a bit of a problem to understand how to attach the tessellation shader to unitys shadow pipeline.
Is it the way to go to expand the unityCG and AutoLight cginc files? (which would be ok)
also adding a shadow collector and caster pass.
I have unity 4 and 5 on my hands but I guess it makes no difference, right?
I’m currently working on it but I have the feeling this is not thought through. Could someone with more knowledge check the above thread and explain if that’s how it should be done? Is there definitely no support for something like TRANSFER_VERTEX_TO_FRAGMENT(o) for a hull - domain shader right now and in the near future?
But I have another question: why does the shader doesn’t render “multi_compile_fwdadd” correctly?
If I only output the Forward Add Pass like that
...
// forward add pass
Pass {
Name "FORWARDADD"
Tags {"LightMode" = "ForwardAdd"}
//Blend One One
//Blend Zero One // only ambient
Blend One Zero // only direct light
CGPROGRAM
#pragma target 5.0
#pragma vertex VS
#pragma fragment PS
#pragma hull HS
#pragma domain DS
#pragma multi_compile_fwdadd
#pragma fragmentoption ARB_precision_hint_fastest
#pragma only_renderers d3d11
//----------------------------------------------------------
#define UNITY_PASS_FORWARDADD
#include "UnityCG.cginc"
#include "cginc/DwarfMines_UnityCG.cginc"
#include "AutoLight.cginc"
#include "cginc/DwarfMines_AutoLight.cginc"
//#include "Lighting.cginc"
//----------------------------------------------------------
sampler2D _MainTex;
//-------------------------------------------------------
uniform half _DisplacementFactor;
uniform half _StaticTessellationFactor;
uniform half _MaxDynamicTesselation;
#include "cginc/DwarfMines_Tessellation.cginc"
//-------------------------------------------------------
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS(PixelInputType v) : COLOR
{
float4 returnColor = float4(0.0, 1.0, 0.0, 1.0);
float atten = LIGHT_ATTENUATION(v); // This gets you the attenuation + shadow value.
float3 lightDirection;
if (0.0f == _WorldSpaceLightPos0.w) // directional light?
lightDirection = normalize(float3(_WorldSpaceLightPos0.xyz));
else // point or spot light
lightDirection = normalize(float3(_WorldSpaceLightPos0.xyz - v.pos.xyz));
float lightIntensity = saturate(dot(v.normal_w,lightDirection));
if(lightIntensity > 0.0f)
returnColor += lightIntensity;
float3 diffuse = tex2D (_MainTex, v.uv).rgb;
returnColor.rgb = atten*lightIntensity;
return saturate(returnColor);
}
ENDCG
} // end pass "forward add"
//-----------------------------
I get this behaviour
(center sphere is a reference with my working shader without tessellation)
What I expect: see the red light illuminate the plane and the 2nd sphere with attenuation and whatnot.