- Home /
Question by
marchall_box · Oct 06, 2016 at 12:25 AM ·
c#procedural meshprocedural generationprocedural-generation
How to render procedurally generated mesh to be rendered as 2 sided?
Hi,
I have created code to generate mesh procedurally with C# but it is rendering only from 1 side. How do I modify this to be rendered as 2 sided?
thanks,
Comment
Answer by Namey5 · Oct 06, 2016 at 12:42 AM
You would need to use a custom shader. The following shader will work, although it is a simplified version of the Standard shader because I don't know what shader you would otherwise be using/what features.
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
Shader "Custom/Double Sided"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Texture", 2D) = "white" {}
_Smoothness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0
}
SubShader
{
Tags { "RenderType"="Opaque" }
Cull Off
CGPROGRAM
#pragma surface surf Standard vertex:vert
#pragma target 3.0
sampler2D _MainTex;
half _Smoothness;
half _Metallic;
fixed4 _Color;
struct Input {
float2 uv_MainTex;
};
void vert (inout appdata_full v) {
float3 worldPos = mul (unity_ObjectToWorld, v.vertex);
float3 worldNorm = UnityObjectToWorldNormal (v.normal);
float3 viewDir = worldPos - _WorldSpaceCameraPos;
v.normal *= dot (viewDir, worldNorm) > 0 ? -1 : 1;
}
void surf (Input IN, inout SurfaceOutputStandard o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Smoothness = _Smoothness;
o.Metallic = _Metallic;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
}
Your answer
Follow this Question
Related Questions
Mesh generation issue (C#) 1 Answer
Procedural Mesh From Random List Of Veritces 2 Answers
Why do I get this weird mesh error when I have a mesh over 250 by 250? 1 Answer
Procedural mesh with texture atlas, how to get rid of material artifacts? 0 Answers
How to darken a procedurally added texture (explained below) 0 Answers