- Home /
Line Renderer water reflection issue
I'm using Unity Pro 4.5. I've made a terrain with water:
As you see, there is a big straight white line jutting up out of the moat, into the sky. It's a line renderer I'm going to use as the basis for a lightning bolt. I'd like for the lightning to be able to strike the ground somewhere on the map and have its reflection appear in the water. (Seems like a trivial graphical feature, but I have other lightning-above-water effects in the game as well and it'd be awesome if it was doable).
The castle and skybox both reflect accurately, but not the line renderer. Any wisdom out there?
Sorry I don't have an answer, but I can confirm I have the same issue (in 4.3.4f1). Anyways, 4.5.1 is out by now, maybe you should try with it?
Answer by Matou · Jun 30, 2014 at 08:34 AM
Okay, I made a few tests and found a workaround.
Actually I think that linerenderer geometry is dynamically computed to match the orientation of the main camera (the polygons always face the main camera). However, when we use a water shader, the camera used for reflection doesn't recompute the linerenderer orientation. Thus, in the reflection we see the "other side" of the linerenderer. Sadly, most materials in Unity are only 1-sided.
A trick is to use a two-sided material shader, such as this one:
Shader "Custom/UnlitCutout2Sided"
{
Properties
{
_TintColor ("Tint Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans. (Alpha)", 2D) = "white" { }
_CutOff ("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader {
Tags { "Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
ZWrite On
Cull Off
AlphaTest Greater 0.5
Pass {
Lighting Off
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
float4 _TintColor;
half4 frag(v2f_img i):COLOR
{
return _TintColor*tex2D(_MainTex, i.uv);
}
ENDCG
}
}
Fallback "Transparent/Cutout/Diffuse"
}
You can use a lot of different shaders, the important part is "Cull Off" which renders both sides of a mesh. I don't know if Unity provides default 2-sided shaders, but, if it does, they should do the job as well.
Maybe it's not the best solution, but it kinda works for me. I hope it helps :)
Peace.
Hey, just wanted to tell you that worked great. Thanks dude.