Question by
Guedez · Jun 15, 2017 at 04:49 PM ·
shadergraphicsshadowsinstancing
Inconsistent Shadows in DrawMeshInstancedIndirect
As seen in the Webm, the shadows are inconsistent whenever they want to draw or not. I have tried a lot of thing but couldn't single out what's the cause of the bug. I have no idea what's causing this, so for now I will only post the relevant Update method that calls DrawMeshInstancedIndirect and the whole shader.
Update Method:
private void Update() {
if (argsBuffer != null) {
int lodLevel = getLodLevel();
UnityEngine.Rendering.ShadowCastingMode shadowCastingMode = drawShadows ? UnityEngine.Rendering.ShadowCastingMode.TwoSided : UnityEngine.Rendering.ShadowCastingMode.Off;
Graphics.DrawMeshInstancedIndirect(baseMesh[lodLevel], 0, material, bounds, argsBuffer, 0, null, shadowCastingMode, receiveShadows);
} else {
GetComponent<MapObject>().requiresUpdate = true;
}
}
InstancedGrassShader.shader:
Shader "Custom/InstancedGrassShader" {
Properties{
_MainTex("Texture", 2D) = "white" {}
_Cutout("Cutout", Range(0,1)) = 0.5
_Length("Lenght", Range(0,1)) = 0.5
_Width("Width", Range(0.05,1)) = 0.125
_LeafFormat("LeafFormat", Range(0,4)) = 0
_WidthDecrease("Width Decrease", Range(0,1)) = 1
_Gravity("Gravity", Range(0.01,1)) = 0.5
_Bend("Bend", Range(0.01,1)) = 0.5
_Direction("Direction", Range(-1,1)) = 0
}
SubShader{
Tags {"Queue" = "AlphaTest"}
Cull Off
ZWrite On
CGPROGRAM
#pragma target 3.0
#pragma surface surf WrapLambert vertex:vert alphatest:_Cutout addshadow interpolateview halfasview fullforwardshadows nolightmap
#pragma instancing_options procedural:setup
#include "UnityCG.cginc"
#ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
StructuredBuffer<float4> transformOne;
StructuredBuffer<float4> transformTwo;
StructuredBuffer<float4> transformThree;
#endif
void setup()
{
#ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
float4 v0 = transformOne[unity_InstanceID];
float4 v1 = transformTwo[unity_InstanceID];
float4 v2 = transformThree[unity_InstanceID];
unity_ObjectToWorld._11_12_13_14 = v0;
unity_ObjectToWorld._21_22_23_24 = v1;
unity_ObjectToWorld._31_32_33_34 = v2;
unity_ObjectToWorld._41_42_43_44 = float4(0, 0, 0, 1);
#endif
}
sampler2D _MainTex;
float _Length;
float _Width;
float _WidthDecrease;
float _Gravity;
float _Bend;
float _Direction;
float _LeafFormat;
struct Input {
float2 uv_MainTex;
float3 viewDir;
};
void vert(inout appdata_full v) {
v.vertex.x -= ((v.texcoord.x - .5f) * pow(v.texcoord.y, 1 + _LeafFormat)) * _WidthDecrease;
v.vertex.x = lerp(0, v.vertex.x, _Width);
float zgrav = lerp(0, cos((v.texcoord.y)*3.14f) - 1, _Gravity) / 2;
float ygrav = -lerp(-v.vertex.y, -sin(v.texcoord.y*3.14f) / 2, _Gravity);
v.vertex.y = lerp(ygrav, 0, _Bend);
v.vertex.z = lerp(zgrav, lerp(0,-1, v.texcoord.y), _Bend);
v.texcoord.x = v.vertex.x + 0.5;
}
half4 LightingWrapLambert(SurfaceOutput s, half3 lightDir, half atten) {
return float4 (s.Albedo * _LightColor0.rgb * (2 * atten), s.Alpha);
}
float3 n = float3(0, 0, 1);
void surf(Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
o.Normal = (dot(IN.viewDir, n) > 0 ? n : -n);
o.Alpha = tex2D(_MainTex, IN.uv_MainTex).a;
}
ENDCG
}
Fallback "Diffuse"
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612124239im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
[URP] Transp Shadergraph has shadows? 2 Answers
GPU Instancing works strangely on android 0 Answers
shader graph messes up the texture (2D) 0 Answers