RenderToCubemap SkyBox problem

Hi,
I having problem rendering the sky box when rendering cubemap (with RenderTexture and render to cubemap).
I use a script to render my cubemap on the fly (see code below) and when looking the cubemap we can see that skybox is not rendered correctly (up and down faces lookes strange)

using UnityEngine;
using System.Collections;


[ExecuteInEditMode()]  
[AddComponentMenu("Mutsu/AutoEnvMap")]
public class autoEnvMap : MonoBehaviour {

	public int _cubeMapSize = 256;
	public LayerMask _layerMask;	
	
	private GameObject _cubeCam;
	private RenderTexture _cubeMap;
	

	// --------------------------------------------------------

	void LateUpdate () {
		
		// Get the CubemapCamera in the scene.
		_cubeCam = GameObject.Find("CubemapCamera");
		
		if (!_cubeCam) { // If there is no CubemapCamera create One
			_cubeCam = new GameObject("CubemapCamera",typeof(Camera)); 
			_cubeCam.camera.transform.rotation = Quaternion.identity;
			_cubeCam.camera.renderingPath = RenderingPath.Forward;
			_cubeCam.camera.nearClipPlane = 0.001f;
			_cubeCam.camera.farClipPlane = 100f;
			_cubeCam.camera.enabled = false;			
		}
		// set the camera position and the objects layer to be rendered
		_cubeCam.camera.transform.position = transform.position;
		_cubeCam.camera.cullingMask = _layerMask;
		
		
		if(!_cubeMap){ // check for the RenderTexture and create one if needed.
			_cubeMap = new RenderTexture(_cubeMapSize, _cubeMapSize, 16);
			// Set the RenderTexture to be a Cubemap that is PowerOfTwo and use MipMap
			_cubeMap.isCubemap = true;			_cubeMap.isPowerOfTwo = true;
			_cubeMap.useMipMap = true;			_cubeMap.filterMode = FilterMode.Trilinear;
			_cubeMap.wrapMode = TextureWrapMode.Clamp;
		}
		
		// Select the face of the cube to render and render 
		int faceToRender = 1 << (Time.frameCount % 6); // here it's "one face per frame" 
		_cubeCam.camera.RenderToCubemap (_cubeMap, 63);

		// Check for the "_Cube" property in all the object's materials 
		for (int imat = 0; imat < this.renderer.sharedMaterials.Length ; imat++) {
			if (this.renderer.sharedMaterials[imat].HasProperty("_Cube")){
				this.renderer.sharedMaterials[imat].SetTexture("_Cube", _cubeMap);
			}		
		}		
	}
	
	void OnDisable () {
		DestroyImmediate (_cubeCam);
		DestroyImmediate (_cubeMap);
	}	
}

any idea ?

thanks…

450300--15698--$cubeSky.jpg

hint : if I force t FOV to 90…the up and down side are OK…but the problem is now visible on the left and right side …

OK,I’ve fixed the problem,
I just need to force “camera.aspect” to 1 so there won’t be any seam on the Mip level0 :slight_smile:

thanks every one… sorry to bother…

1 Like