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 GalaTyler · Oct 02, 2017 at 11:31 PM · texturedownloadcubemap

Create a cubemap at runtime from a downloaded 360 texture

How do you take a texture downloaded at runtime and apply those pixels to a cubemap?

If you import the texture into Unity, you can change the "Texture Shape" to be cube, resulting in a skybox-compatible cubemap. How can I accomplish this with a downloaded texture at runtime?

alt text

Here's an example of the kind of texture I want to convert into a cubemap:

alt text

importsettingsexample.png (53.4 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by GalaTyler · Oct 03, 2017 at 05:47 PM

After a few more hours of research, I came across this thread which contained a shader which allowed to me accomplish what I was looking for:

https://forum.unity.com/threads/equirectangular-background-shader.364287/

It's a shader that can be used as a skybox material which takes a latlong texture. Here's the code, credited to bgolus of the Unity forums:

 Shader "Skybox/Equirectangular" {
 Properties {
     _Tint ("Tint Color", Color) = (.5, .5, .5, .5)
     [Gamma] _Exposure ("Exposure", Range(0, 8)) = 1.0
     _Rotation ("Rotation", Range(0, 360)) = 0
     [NoScaleOffset] _Tex ("Panorama (HDR)", 2D) = "grey" {}
 }
  
 SubShader {
     Tags { "Queue"="Background" "RenderType"="Background" "PreviewType"="Skybox" }
     Cull Off ZWrite Off
  
     Pass {
      
         CGPROGRAM
         #pragma vertex vert
         #pragma fragment frag
  
         #include "UnityCG.cginc"
  
         sampler2D _Tex;
         half4 _Tex_HDR;
         half4 _Tint;
         half _Exposure;
         float _Rotation;
  
         float4 RotateAroundYInDegrees (float4 vertex, float degrees)
         {
             float alpha = degrees * UNITY_PI / 180.0;
             float sina, cosa;
             sincos(alpha, sina, cosa);
             float2x2 m = float2x2(cosa, -sina, sina, cosa);
             return float4(mul(m, vertex.xz), vertex.yw).xzyw;
         }
      
         struct appdata_t {
             float4 vertex : POSITION;
         };
  
         struct v2f {
             float4 vertex : SV_POSITION;
             float3 texcoord : TEXCOORD0;
         };
  
         v2f vert (appdata_t v)
         {
             v2f o;
             o.vertex = mul(UNITY_MATRIX_MVP, RotateAroundYInDegrees(v.vertex, _Rotation));
             o.texcoord = v.vertex.xyz;
             return o;
         }
  
         fixed4 frag (v2f i) : SV_Target
         {
             float3 dir = normalize(i.texcoord);
             float2 longlat = float2(atan2(dir.x, dir.z) + UNITY_PI, acos(-dir.y));
             float2 uv = longlat / float2(2.0 * UNITY_PI, UNITY_PI);
             half4 tex = tex2D (_Tex, uv);
             half3 c = DecodeHDR (tex, _Tex_HDR);
             c = c * _Tint.rgb * unity_ColorSpaceDouble.rgb;
             c *= _Exposure;
  
             return half4(c, 1);
         }
         ENDCG
     }
 }  
  
  
 Fallback Off
  
 }
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
avatar image
0

Answer by Joy0023 · Jul 07, 2019 at 01:17 PM

Can't change the mainTexture runtime

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

93 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 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 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 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 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

Setting cubemap faces as rendertexture 0 Answers

What is the best way to optimize cubemaps for skyboxes? 0 Answers

Texture on instantiated asset bundle sometimes black only on iPhone 0 Answers

mipmapCount for Cubemap and Texture3D 1 Answer

Cubemap texture resolution problem 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