Optimize Hdri panorama volume by mirroring in Unty

Source: Internet
Author: User
Tags acos cos sin

Panorama is Hdri map, can replace 6 side cubemap, traditional 3D software is widely used. General reflection probes, sky boxes, etc. will be used.

However, the volume is too large is a problem, in particular, the mobile side will control the size of the package, although it can be replaced by a spherical map of some environmental class map, but the scope of application is still limited.

This is done by mirroring the map size optimization, you can optimize the map to half the size, the disadvantage is that it will produce seams.

The original image is as follows (Network collection):

Final effect:

There are some equirectangular map conversion functions on GitHub, similar to spherical coordinates, which are directly take doctrine.

Reference:

Https://github.com/tolotratlt/UnityPhotosphericView

Https://github.com/Mapiarz/CubemapToEquirectangular

Tested to be mirrored by the X, Y axis. You first need to crop the original Hdri picture. Cut directly with Texture2d's resize.

Material mat =NewMaterial (Shader.find ("Hidden/convshader"));varRT = Rendertexture.gettemporary (NewRendertexturedescriptor (Tex.width, Tex.height, rendertextureformat.argb32)); Graphics.blit (Tex, RT, MAT);varInstancetex =Instantiate (Tex); Instancetex.resize (Instancetex.width, Instancetex.height/2); Instancetex.readpixels (NewRect (0,0, Instancetex.width, Instancetex.height),0,0); instancetex.apply (); ..

Note that there are two functions for converting panoramas, referring to the content on GitHub, and changing the constants to the built-in UNITY_PI.

float3 Uvtodir (float2 UV) {UV*=float2 (UNITY_TWO_PI, UNITY_PI); floattheta =uv.y; floatPhi =uv.x; FLOAT3 dir= FLOAT3 (0,0,0); Dir.x= sin (phi) * sin (theta) *-1; Dir.y= cos (theta) *-1; Dir.z= cos (phi) * sin (theta) *-1; returndir;} Float2 Dirtouv (float3 a_coords) {FLOAT3 A_coords_n=normalize (a_coords); floatLon =atan2 (a_coords_n.z, a_coords_n.x); floatLat =ACOs (A_COORDS_N.Y); FLOAT2 Spherecoords= Float2 (lon, LAT) * (1.0/unity_pi); returnFLOAT2 (1-(Spherecoords.x *0.5-0.5),1-SPHERECOORDS.Y);//must flip x}

After the conversion is to make changes in the display section, passing in a direction vector output panorama of the UV, in-house to do a mirror image repair

It is important to note that the output x is not 0-1 intervals, but 0-2, which is estimated due to the panorama width height of 2:1, which is simply fixed below.

The y-axis seams are more obvious and the error is adjusted manually. Set the compression of the map close mipmap, etc., the seam will alleviate a lot.

float2 Dirtouv (float3 a_coords) {FLOAT3 A_coords_n=normalize (a_coords); floatLon =atan2 (a_coords_n.z, a_coords_n.x); floatLat =ACOs (A_COORDS_N.Y); FLOAT2 Spherecoords= Float2 (lon, LAT) * (1.0/unity_pi); Float2 UV= FLOAT2 (1-(Spherecoords.x *0.5-0.5),1-spherecoords.y); //----------------------------uv.x-=1; if(Uv.x >0.5) uv.x=0.5-(Uv.x-0.5); uv.x*=2; //----------------------------Mirror X. //----------------------------Uv.y *=1.999; if(Uv.y <1) Uv.y*= -0.97; Elseuv.y*=1.03; //----------------------------Mirror Y.    returnUV;}

This is basically the case, and in many cases you need to cubemap to Hdri panorama, you can refer directly to the cubemaping mapping function on Wikipedia:

Https://en.wikipedia.org/wiki/Cube_mapping

Optimize Hdri panorama volume by mirroring in Unty

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.