Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by kornica3d · Oct 27, 2016 at 08:32 PM · shadersnormals

Double sided geometry.

Is there a way to set mesh to display both sides? i know i can model it to have both sides but is this the only way?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by tanoshimi · Oct 27, 2016 at 08:35 PM

Just set CULL OFF in the shader.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kornica3d · Oct 28, 2016 at 03:20 PM 0
Share

And where is that property?? Cannot find it in Standard $$anonymous$$etallic shader...

avatar image tanoshimi kornica3d · Oct 29, 2016 at 08:18 AM 0
Share

It's not an exposed property - you just add it at the top of your shader program (replacing the CULL BAC$$anonymous$$ that's probably there already).

https://docs.unity3d.com/$$anonymous$$anual/SL-Pass.html

avatar image kornica3d · Oct 29, 2016 at 04:44 PM 0
Share

excellent. Any other tips how to access that? because if i have to script the whole shader not sure how to do it...

avatar image
1

Answer by Zitoox · Oct 27, 2016 at 11:22 PM

I have a Script here. I don't know if it's going to work, but you could give it a try. Create a new script in java and then insert the code below. Then you just need to attach the script to the object that you want to have double sides.

Javascript:

 #pragma strict
 
 function Start () {
     var mesh = GetComponent(MeshFilter).mesh;
     var vertices = mesh.vertices;
     var uv = mesh.uv;
     var normals = mesh.normals;
     var szV = vertices.length;
     var newVerts = new Vector3[szV*2];
     var newUv = new Vector2[szV*2];
     var newNorms = new Vector3[szV*2];
     for (var j=0; j< szV; j++){
         // duplicate vertices and uvs:
         newVerts[j] = newVerts[j+szV] = vertices[j];
         newUv[j] = newUv[j+szV] = uv[j];
         // copy the original normals...
         newNorms[j] = normals[j];
         // and revert the new ones
         newNorms[j+szV] = -normals[j];
     }
     var triangles = mesh.triangles;
     var szT = triangles.length;
     var newTris = new int[szT*2]; // double the triangles
     for (var i=0; i< szT; i+=3){
         // copy the original triangle
         newTris[i] = triangles[i];
         newTris[i+1] = triangles[i+1];
         newTris[i+2] = triangles[i+2];
         // save the new reversed triangle
         j = i+szT; 
         newTris[j] = triangles[i]+szV;
         newTris[j+2] = triangles[i+1]+szV;
         newTris[j+1] = triangles[i+2]+szV;
     }
     mesh.vertices = newVerts;
     mesh.uv = newUv;
     mesh.normals = newNorms;
     mesh.triangles = newTris; // assign triangles last!
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kornica3d · Oct 29, 2016 at 04:20 PM 0
Share

I dont think this works because I am instancing a prefab... $$anonymous$$aybe i could call it once i instance a prefab

avatar image kornica3d · Oct 29, 2016 at 04:43 PM 0
Share

also its a skinned mesh and i dont think it has a mesh filter :/

avatar image
1

Answer by Perimetric · Oct 29, 2016 at 05:03 PM

Just add the "Cull off " property in the subshader.

Like this:

 Shader "Custom/Double-Sided" {
     Properties {
         _Color ("Color", Color) = (1,1,1,1)
         _MainTex ("Albedo (RGB)", 2D) = "white" {}
         _Glossiness ("Smoothness", Range(0,1)) = 0.5
         _Metallic ("Metallic", Range(0,1)) = 0.0
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         LOD 200
         Cull off
 
         CGPROGRAM
         #pragma surface surf Standard fullforwardshadows
         #pragma target 3.0
 
         sampler2D _MainTex;
 
         struct Input {
             float2 uv_MainTex;
         };
 
         half _Glossiness;
         half _Metallic;
         fixed4 _Color;
 
         void surf (Input IN, inout SurfaceOutputStandard o) {
             fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
             o.Albedo = c.rgb;
             o.Metallic = _Metallic;
             o.Smoothness = _Glossiness;
             o.Alpha = c.a;
         }
         ENDCG
     }
     FallBack "Diffuse"
 }
 

 
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

I'm computing my surface normals in the fragment program - so why does Unity still require per-vertex normals/tangents? 1 Answer

Can I retrieve per face normals instead of per vertex normals in vertex shader? 1 Answer

World Space material Stretching when object is rotated. 0 Answers

Dual Normal Shader for Unity?! 0 Answers

Reflections not seamless 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges