本文整理汇总了C#中UnityEngine.Cubemap类的典型用法代码示例。如果您正苦于以下问题:C# Cubemap类的具体用法?C# Cubemap怎么用?C# Cubemap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Cubemap类属于UnityEngine命名空间,在下文中一共展示了Cubemap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: capture
public void capture(ref Cubemap targetCube, Transform at, bool HDR)
{
if( targetCube == null ) return;
GameObject go = new GameObject("_temp_probe");
go.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideAndDontSave;
go.SetActive(true);
Camera cam = go.AddComponent<Camera>();
if( at != null ) {
go.transform.position = at.position;
}
if(HDR) {
Shader.EnableKeyword("MARMO_RGBM");
Shader.DisableKeyword("MARMO_RGBA");
Shader.SetGlobalFloat("_GlowStrength", 0f);
Shader.SetGlobalFloat("_EmissionLM", 0f);
cam.SetReplacementShader(Shader.Find("Hidden/Marmoset/RGBM Replacement"),"RenderType");
}
cam.RenderToCubemap(targetCube);
targetCube.Apply(false);
if(HDR) {
cam.ResetReplacementShader();
Shader.DisableKeyword("MARMO_RGBM");
Shader.EnableKeyword("MARMO_RGBA");
}
GameObject.DestroyImmediate(go);
}
示例2: DirectionalCubemap
public static void DirectionalCubemap()
{
int faceSize = 8;
Cubemap cube = new Cubemap(faceSize, TextureFormat.RGB24, false);
// For each side
foreach (CubemapFace face in System.Enum.GetValues(typeof(CubemapFace))) {
Color[] pixels = new Color[faceSize * faceSize];
for (int x = 0; x < faceSize; ++x)
for (int y = 0; y < faceSize; ++y) {
int index = x + y * faceSize;
Vector3 dir = Utils.Cubemap.CubemapDirection(face,
(x+0.5f) / (float)faceSize - 0.5f,
(y+0.5f) / (float)faceSize - 0.5f);
pixels[index] = new Color(dir.x, dir.y, dir.z);
}
cube.SetPixels(pixels, face);
cube.Apply();
}
AssetDatabase.CreateAsset(cube, "Assets/BiasedPhysics/DirectionalCubemap.cubemap");
Debug.Log("Generated /BiasedPhysics/DirectionalCubemap.cubemap");
}
示例3: CreateSubMips
public static void CreateSubMips(Cubemap cube) {
AssetDatabase.StartAssetEditing();
int faceSize = cube.width;
string cubePath = AssetDatabase.GetAssetPath(cube);
//load all sub-assets
UnityEngine.Object[] mips = AssetDatabase.LoadAllAssetRepresentationsAtPath(cubePath);
if(mips != null) {
for(int i=0; i<mips.Length; ++i) {
if( mips[i] != null && AssetDatabase.IsSubAsset(mips[i]) ) UnityEngine.Object.DestroyImmediate(mips[i], true);
}
}
AssetDatabase.Refresh();
// skip mip level 0, its in the cubemap itself
faceSize = faceSize >> 1;
for( int mip = 1; faceSize > 0; ++mip ) {
// extract mipmap faces from a cubemap and add them as textures in the sub image
Texture2D tex = new Texture2D(faceSize, faceSize*6,TextureFormat.ARGB32,false);
tex.name = "mip"+mip;
for( int face = 0; face<6; ++face ) {
tex.SetPixels(0, face*faceSize, faceSize, faceSize, cube.GetPixels((CubemapFace)face,mip));
}
tex.Apply();
AssetDatabase.AddObjectToAsset(tex, cubePath);
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(tex));
faceSize = faceSize >> 1;
}
AssetDatabase.StopAssetEditing();
AssetDatabase.Refresh();
}
示例4: UpdateCubemap
public void UpdateCubemap(int faceMask = 63)
{
//if (!camera)
//{
// //var go = new GameObject("CubemapCamera", typeof(Camera));
// //go.hideFlags = HideFlags.HideAndDontSave;
// //go.transform.position = transform.position;
// //go.transform.rotation = Quaternion.identity;
// //camera = go.camera;
// //cam.cullingMask = 1 << Layer.level;
// //cam.farClipPlane = 1000; // don't render very far into cubemap
// camera.enabled = false;
//}
if (!cubemap)
{
cubemap = new Cubemap(512, TextureFormat.RGB24, false);
#if UNITY_EDITOR
UnityEditor.AssetDatabase.CreateAsset(cubemap, "Assets/cubemap.cubemap");
#endif
//rtex.isCubemap = true;
//rtex.hideFlags = HideFlags.HideAndDontSave;
//renderer.sharedMaterial.SetTexture("_Cube", rtex);
}
//cam.transform.position = transform.position+Vector3.up*40;//Camera.main.transform.position;
camera.RenderToCubemap(cubemap);
}
示例5: CopyTextureCube
private void CopyTextureCube(string texturePath, Cubemap cubemap, BabylonTexture babylonTexture)
{
if (!babylonScene.AddTextureCube(texturePath))
{
return;
}
try
{
foreach (CubemapFace face in Enum.GetValues(typeof(CubemapFace)))
{
var faceTexturePath = Path.Combine(babylonScene.OutputPath, Path.GetFileNameWithoutExtension(texturePath));
switch (face)
{
case CubemapFace.PositiveX:
faceTexturePath += "_px.jpg";
break;
case CubemapFace.NegativeX:
faceTexturePath += "_nx.jpg";
break;
case CubemapFace.PositiveY:
faceTexturePath += "_py.jpg";
break;
case CubemapFace.NegativeY:
faceTexturePath += "_ny.jpg";
break;
case CubemapFace.PositiveZ:
faceTexturePath += "_pz.jpg";
break;
case CubemapFace.NegativeZ:
faceTexturePath += "_nz.jpg";
break;
default:
continue;
}
var tempTexture = new Texture2D(cubemap.width, cubemap.height, TextureFormat.RGB24, false);
tempTexture.SetPixels(cubemap.GetPixels(face));
tempTexture.Apply();
// Flip faces in cube texture.
tempTexture = FlipTexture(tempTexture);
File.WriteAllBytes(faceTexturePath, tempTexture.EncodeToJPG());
}
}
catch (Exception ex)
{
Debug.LogException(ex);
}
var textureName = Path.GetFileNameWithoutExtension(texturePath);
babylonTexture.name = textureName;
babylonTexture.isCube = true;
babylonTexture.level = exportationOptions.ReflectionDefaultLevel;
babylonTexture.coordinatesMode = 3;
}
示例6: Initialize
public void Initialize(float landMinHeight, float landMaxHeight, float oceanHeight, Cubemap landHeightmap)
{
Material mat = renderer.sharedMaterial;
mat.SetVector("_MinMaxHeight_OceanHeight", new Vector4(landMinHeight, landMaxHeight, oceanHeight, 0.0f));
//mat.SetTexture("_LandCube", planet.renderer.sharedMaterial.GetTexture("_LandCube"));
mat.SetTexture("_LandCube", landHeightmap);
}
示例7: Awake
void Awake ()
{
material = GetComponent<Renderer>().material;
cubemap = (Cubemap)material.GetTexture("_Cube");
rendererArray = GetComponentsInChildren<Renderer>();
rotation = material.GetFloat("_Rotation");
bookArray = GetComponentsInChildren<Book>();
}
示例8: ExtractSkybox
public static void ExtractSkybox()
{
RenderSettings.skybox = null;
// get the camera reference.
Camera cameraObj = GameObject.Find ("AGF_CameraManager").GetComponent<AGF_CameraManager>().GetMainCamera();
AGF_AtmosphereManager atmosphereManager = GameObject.Find ("AGF_AtmosphereManager").GetComponent<AGF_AtmosphereManager>();
if(cameraObj.GetComponent<Skybox>().material.GetTexture("_Tex") == null)
return;
// step 1: create the target directory, if necessary.
string targetDirectory = Main.TrimEndFromString( Application.dataPath, "Assets" ) + sourceFolder + "/" + sceneFolder + "/Skyboxes";
if ( Directory.Exists( targetDirectory ) == false ){
Directory.CreateDirectory( targetDirectory );
}
// step 2: clear the old files, if they exist.
if ( File.Exists( targetDirectory + "/skyboxCubemap.cubemap" ) ){
AssetDatabase.DeleteAsset( sourceFolder + "/skyboxCubemap.cubemap" );
}
if ( File.Exists( targetDirectory + "/skyboxMaterial.mat" ) ){
AssetDatabase.DeleteAsset( sourceFolder + "/skyboxMaterial.mat" );
}
// step 3: copy over the cubemap from the camera.
Cubemap cubemapReference = (Cubemap)cameraObj.GetComponent<Skybox>().material.GetTexture("_Tex");
Cubemap skyboxCubemap = new Cubemap(cubemapReference.width, TextureFormat.RGB24, false);
EditorUtility.CopySerialized( cubemapReference, skyboxCubemap );
// step 4: create the cubemap asset.
AssetDatabase.CreateAsset( skyboxCubemap, sourceFolder + "/" + sceneFolder + "/Skyboxes/skyboxCubemap.cubemap" );
// AssetDatabase.ImportAsset( sourceFolder + "/" + sceneFolder + "/Skyboxes/skyboxCubemap.cubemap" );
// step 5: Create a temporary material, and link it up to the cubemap.
Material skyboxMaterial = new Material( cameraObj.GetComponent<Skybox>().material );
skyboxMaterial.SetTexture( "_Tex", (Cubemap)AssetDatabase.LoadAssetAtPath(sourceFolder + "/" + sceneFolder + "/Skyboxes/skyboxCubemap.cubemap", typeof(Cubemap) ) );
// step 6: create the material asset.
AssetDatabase.CreateAsset( skyboxMaterial, sourceFolder + "/" + sceneFolder + "/Skyboxes/skyboxMaterial.mat" );
// AssetDatabase.ImportAsset( sourceFolder + "/" + sceneFolder + "/Skyboxes/skyboxMaterial.mat" );
// Now that both the cubemap and material have been created, assign the material into the camera.
cameraObj.GetComponent<Skybox>().material = (Material)AssetDatabase.LoadAssetAtPath( sourceFolder + "/" + sceneFolder + "/Skyboxes/skyboxMaterial.mat", typeof(Material) );
// In addition, we need to add another camera script to control the skybox rotation, etc.
if ( cameraObj.GetComponent<AGF_SkyboxRotator>() == null ){
cameraObj.gameObject.AddComponent<AGF_SkyboxRotator>();
}
cameraObj.gameObject.GetComponent<AGF_SkyboxRotator>().autoRotate = atmosphereManager.GetCurrentSkybox().autoRotate;
cameraObj.gameObject.GetComponent<AGF_SkyboxRotator>().autoRotationSpeed = atmosphereManager.GetCurrentSkybox().autoRotationSpeed;
cameraObj.gameObject.GetComponent<AGF_SkyboxRotator>().rotation = atmosphereManager.GetCurrentSkybox().rotation;
cameraObj.gameObject.GetComponent<AGF_SkyboxRotator>().tint = atmosphereManager.GetCurrentSkybox().tint;
EditorUtility.SetDirty( cameraObj.gameObject );
}
示例9: InitializeMaterial
public void InitializeMaterial(int size, float minHeight, float maxHeight, float sandPercentage)
{
Material mat = renderer.sharedMaterial;
Heightmap = mat.GetTexture("_LandCube") as Cubemap;
mat.SetFloat("_InvLandDetail", 1.0f / size);
mat.SetVector("_MinMaxHeight_SandPercentage", new Vector4(minHeight, maxHeight, sandPercentage, 0.0f));
}
示例10: Update
void Update()
{
m_CurrMaterial = renderer.sharedMaterial;
if (m_CurrMaterial)
{
m_MapCurr = CheckDistance();
m_CurrMaterial.SetTexture("_Cubemap", m_MapCurr);
}
}
示例11: BuildSurfaceMesh
public static void BuildSurfaceMesh(ref MeshPlane mesh, ref Random rand)
{
var brush = Resources.Load("PlanetBuilding/SurfaceBrush");
if (brush == null)
{
Debug.LogError("Unable to load basic brush prefab");
return;
}
var rampTex = Resources.Load("Textures/PlanetRamp") as Texture;
if (rampTex == null)
{
Debug.LogError("Unable to load planet colour ramp");
return;
}
// Apply brush texture somehow
// * 0.1f
float brushBaseSize = 1.0f;
float brushSizeLarge = brushBaseSize * 0.2f;
float brushSizeSmall = brushBaseSize * 0.02f;
for (int i = 0; i < rand.Next(25, 75); ++i)
{
var go = (GameObject.Instantiate(brush) as GameObject);
var ch = go.transform.GetChild(0);
var brushScale = (float)(brushSizeSmall + (rand.NextDouble() * brushSizeLarge));
ch.localScale = new Vector3(brushScale, brushScale, brushScale);
go.transform.SetParent(mesh.transform);
go.transform.Rotate(
(float)rand.NextDouble() * 360.0f,
(float)rand.NextDouble() * 360.0f,
(float)rand.NextDouble() * 360.0f
);
}
var localCam = mesh.gameObject.AddComponent<Camera>();
localCam.cullingMask = PlanetBrushLayer;
localCam.fieldOfView = 90;
localCam.backgroundColor = Color.black;
Cubemap c = new Cubemap(2048, TextureFormat.ARGB32, false);
localCam.RenderToCubemap(c);
mesh.GetComponent<Renderer>().material.SetTexture("_Tex", c);
mesh.GetComponent<Renderer>().material.SetTexture("_PlanetRamp", rampTex);
Component.Destroy(localCam);
foreach ( Transform ch in mesh.transform ){
GameObject.Destroy(ch.gameObject);
}
}
示例12: CancelSelection
public void CancelSelection()
{
this.m_SelectedCubemap = null;
this.m_SelectedCubemapInfo = null;
this.m_SelectedShadowCubemapOwnerInfo = null;
this.m_SelectedLightIconIndex = -1;
this.m_SelectedShadowInfo = null;
this.m_HoveringCubeMapIndex = -1;
this.m_DragBeingPerformed = false;
}
示例13: Make
public static Cubemap Make(Camera camera)
{
Cubemap cmap = new Cubemap(4096, TextureFormat.ARGB32, false);
if (camera.RenderToCubemap(cmap))
{
return cmap;
}
return null;
}
示例14: Initialize
public static void Initialize()
{
m_ZeroAmbientProbe.Clear();
if (m_SkyboxMaterial == null)
{
m_SkyboxMaterial = new Material(Shader.Find("Skybox/Cubemap"));
}
if (m_ScreenQuadMesh == null)
{
m_ScreenQuadMesh = new Mesh();
m_ScreenQuadMesh.vertices = new Vector3[] { new Vector3(-1f, -1f, 0f), new Vector3(1f, 1f, 0f), new Vector3(1f, -1f, 0f), new Vector3(-1f, 1f, 0f) };
m_ScreenQuadMesh.triangles = new int[] { 0, 1, 2, 1, 0, 3 };
}
if (m_GBufferPatchMaterial == null)
{
m_GBufferPatchMaterial = new Material(EditorGUIUtility.LoadRequired("LookDevView/GBufferWhitePatch.shader") as Shader);
m_DrawBallsMaterial = new Material(EditorGUIUtility.LoadRequired("LookDevView/GBufferBalls.shader") as Shader);
}
if (m_LookDevCompositing == null)
{
m_LookDevCompositing = new Material(EditorGUIUtility.LoadRequired("LookDevView/LookDevCompositing.shader") as Shader);
}
if (m_DeferredOverlayMaterial == null)
{
m_DeferredOverlayMaterial = EditorGUIUtility.LoadRequired("SceneView/SceneViewDeferredMaterial.mat") as Material;
}
if (m_DefaultHDRI == null)
{
m_DefaultHDRI = EditorGUIUtility.Load("LookDevView/DefaultHDRI.exr") as Cubemap;
if (m_DefaultHDRI == null)
{
m_DefaultHDRI = EditorGUIUtility.Load("LookDevView/DefaultHDRI.asset") as Cubemap;
}
}
if (m_LookDevCubeToLatlong == null)
{
m_LookDevCubeToLatlong = new Material(EditorGUIUtility.LoadRequired("LookDevView/LookDevCubeToLatlong.shader") as Shader);
}
if (m_SelectionTexture == null)
{
m_SelectionTexture = new RenderTexture(250, 0x7d, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);
}
if (m_BrightestPointRT == null)
{
m_BrightestPointRT = new RenderTexture(250, 0x7d, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default);
}
if (m_BrightestPointTexture == null)
{
m_BrightestPointTexture = new Texture2D(250, 0x7d, TextureFormat.RGBAHalf, false);
}
}
示例15: Draw
public override void Draw()
{
GUILayout.BeginVertical();
GUILayout.Label( "Default:" );
GUILayout.EndVertical();
GUILayout.BeginVertical();
_defaultTexture = (DefaultTextureType)EditorGUILayout.EnumPopup( _defaultTexture );
GUILayout.EndVertical();
GUILayout.BeginVertical();
previewTexture = (Cubemap)EditorGUILayout.ObjectField( previewTexture, typeof(Cubemap), new[] { GUILayout.Width (60), GUILayout.Height (60) });
GUILayout.EndVertical();
}