Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by CupOfMayo · Aug 13, 2013 at 10:12 PM · meshsphereinvert

How do I invert normals of a sphere???

Hey, I want to create an atmosphere shader. I found someone used "sphere with the normals inverted" and using X - Ray Shader. (http://answers.unity3d.com/questions/45654/atmospheric-shader-help.html?sort=oldest) And I really want to do the same :) So my question is, How do I do that? I am Using this X - Ray Shader if you have to know: ftp://www.photonworkshop.com/photonworkshop.com/HostedFiles/Mobile-XrayEffect.shader

Comment
Add comment · Show 5
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 CupOfMayo · Aug 13, 2013 at 10:18 PM 0
Share

Oh btw. if it needs Script then JS would be welcome...

avatar image jiteshvm · Aug 13, 2013 at 10:36 PM 0
Share

You can do that from your 3D application directly or you could try this ReverseNormals

avatar image CupOfMayo jiteshvm · Aug 13, 2013 at 10:43 PM 0
Share

I already tried this. It doesn't invert xray shader tho...

avatar image flaviusxvii · Aug 13, 2013 at 10:37 PM 0
Share

http://lmgtfy.com/?q=unity3d+invert+normals

avatar image CupOfMayo · Aug 13, 2013 at 10:47 PM 0
Share

heh. Already went thru all of this stuff in google. If i would find something what works then i wont post here.

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by robertbu · Aug 13, 2013 at 11:34 PM

Here is an editor script that will produce an inverted sphere. Put it in your Assets/Editor folder of your project. Then GameObject > Create Other > Inverted Sphere...

 using UnityEngine;
 using UnityEditor;
 
 public class InvertedSphere : EditorWindow {
     private string st = "1.0";
  
     [MenuItem("GameObject/Create Other/Inverted Sphere...")]
     public static void ShowWindow() {
         EditorWindow.GetWindow(typeof(InvertedSphere));
     }
  
     public void OnGUI() {
         GUILayout.Label("Enter sphere size:");
         st = GUILayout.TextField (st);
         
         float f;
         if (!float.TryParse (st, out f))
             f = 1.0f;
         if (GUILayout.Button("Create Inverted Sphere")) {
             CreateInvertedSphere(f);
         }
     }
     
     private void CreateInvertedSphere(float size) {
         GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
         MeshFilter mf = go.GetComponent<MeshFilter>();
         Mesh mesh = mf.sharedMesh;
         
         GameObject goNew = new GameObject();    
         goNew.name = "Inverted Sphere";
         MeshFilter mfNew = goNew.AddComponent<MeshFilter>();
         mfNew.sharedMesh = new Mesh();
 
         
         //Scale the vertices;
         Vector3[] vertices = mesh.vertices;
         for (int i = 0; i < vertices.Length; i++)
             vertices[i] = vertices[i] * size;
         mfNew.sharedMesh.vertices = vertices;
         
         // Reverse the triangles
         int[] triangles = mesh.triangles;
         for (int i = 0; i < triangles.Length; i += 3) {
             int t = triangles[i];
             triangles[i] = triangles[i+2];
             triangles[i+2] = t;
         }
         mfNew.sharedMesh.triangles = triangles;
         
         // Reverse the normals;
         Vector3[] normals = mesh.normals;
         for (int i = 0; i < normals.Length; i++)
             normals[i] = -normals[i];
         mfNew.sharedMesh.normals = normals;
         
         
         mfNew.sharedMesh.uv = mesh.uv;
         mfNew.sharedMesh.uv2 = mesh.uv2;
         mfNew.sharedMesh.RecalculateBounds();
         
         // Add the same material that the original sphere used
         MeshRenderer mr = goNew.AddComponent<MeshRenderer>();
         mr.sharedMaterial = go.renderer.sharedMaterial;
         
         DestroyImmediate(go);
     }
 }
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 CupOfMayo · Aug 13, 2013 at 11:55 PM 0
Share

It is indeed inverting the sphere but still, it doesn't invert x - ray shader :/. Results after adding x - ray shader to InvertedSphere are exacly the same as without using InvertedSphere :/ Any Ideas why?

avatar image JPhilipp CupOfMayo · Feb 26, 2018 at 03:09 PM 0
Share

I'm running into the same problem, did you ever solve it?

avatar image
2

Answer by YoungDeveloper · Aug 13, 2013 at 10:42 PM

Here is a shader for back face rendering.

 Shader "Backfaced Bumped Diffuse" {
 Properties {
     _Color ("Main Color", Color) = (1,1,1,1)
     _MainTex ("Base (RGB)", 2D) = "white" {}
     _BumpMap ("Normalmap", 2D) = "bump" {}
 }
 
 SubShader {
     Tags { "RenderType"="Opaque" }
     LOD 300
     Cull Off
 
 CGPROGRAM
 #pragma surface surf Lambert
 
 sampler2D _MainTex;
 sampler2D _BumpMap;
 fixed4 _Color;
 
 struct Input {
     float2 uv_MainTex;
     float2 uv_BumpMap;
 };
 
 void surf (Input IN, inout SurfaceOutput o) {
     fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
     o.Albedo = c.rgb;
     o.Alpha = c.a;
     o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
 }
 ENDCG  
 }
 
 FallBack "Diffuse"
 }

To Use: In Unity Editor Right Click > Create > Shader, Name it Backface Bumped Diffuse, Open the shader with monodevelop and paste the code above, Now change your materials that are having issues to "Backface Bumped Diffuse".

Comment
Add comment · Show 1 · 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 CupOfMayo · Aug 13, 2013 at 11:04 PM 0
Share

I see, but that still don't change mt X - Ray Script. Take a look: alt text

So it supposed to looks like Halo, but only looks and Don't dissapear while camera is nearby. Hope you know what I mean.

inverting.png (98.1 kB)

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

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Metaball wiki script help 0 Answers

Applying a texture to a sphere 1 Answer

Cube meshes turn into spheres on Android export 0 Answers

Setting triangles failing 0 Answers

How do I guarantee a generated sphere's mesh is facing outward? 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