Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Nils-Desle · Jan 04, 2015 at 05:04 PM · shader

Standard assets Skybox and cubemap are mirrored along X towards each other?

Hi,

I have a problem when using a skybox and an envmap created from the same images. When I try to use the envmap to create reflections of the skybox, the reflections are wrong, they are mirrored along the X-axis, as you can see in the following image:

alt text

I'm using Unity 4.5.4. The scene has a skybox created using the standard assets skybox Sunny 2 (with an extra sun drawn into it by myself) There's a single plane in the X-Z plane (so Y is still up), with the following (much simplified for this testcase) shader on it:

 Shader "My Water" 
 {
     Properties 
     {
       _EnvMap ("EnvMap", CUBE) = "envmap" {}
     }
 
     
     SubShader 
     {
       Cull off
       Tags { "Queue" = "Opaque" }
       CGPROGRAM
       #pragma surface surf BlinnPhong
       #pragma target 3.0
       
       struct Input 
       {
         float3 worldRefl;
         INTERNAL_DATA
       };
   
       samplerCUBE _EnvMap;
                   
       void surf (Input IN, inout SurfaceOutput o) 
       {
         o.Albedo = float4( 0.0, 0.0, 0.0, 0.0 );
         o.Emission = texCUBE (_EnvMap, WorldReflectionVector (IN, o.Normal)).rgb;
       }
       
       ENDCG
     } 
     
     Fallback "Diffuse"
 }
 

The envmap is created from the same textures as the skybox. One thing that's weird is that when you compare the properties of the skybox with the ones from the cubemap, you can see that their definitions of left and right are different. The skybox defines left as -X, and the cubemap defines left as +X, so that's probably the reason for the mismatch right there.

The question then becomes how to fix this? I'd rather not store two different sets of textures for the same thing (physically mirrored along X), so maybe I can fix it in the shader, by fiddling with the reflection normal? I tried some of that, but I don't know which space we're in by the time Unity calls the surface shader (model space, world space, camera space?) and could not get that to work.

Thanks Nils Desle

unity_problem_reflect.jpg (118.0 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Nils-Desle · Feb 12, 2015 at 12:09 PM

Unfortunately, no-one knew the answer to this one. Fortunately, I figured it out on my own! :) I'll post the solution here for future seekers...

The part where Emission is calculated should be:

 float3 reflected_normal = WorldReflectionVector (IN, o.Normal);
 reflected_normal = float3( -reflected_normal.x, reflected_normal.y, reflected_normal.z );
 o.Emission = texCUBE (_EnvMap, reflected_normal ).rgb;

So basically you flip the reflected normal along its X axis.

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

2 People are following this question.

avatar image avatar image

Related Questions

How to force the compilation of a shader in Unity? 5 Answers

Fading out a square 1 Answer

Is it possible to fake Global Illumination within textures? 1 Answer

Shader compilation fails for Wii-U 2 Answers

Unity 3 Problem: Legacy Lightmap Shaders don't seem to work. 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