summaryrefslogtreecommitdiff
path: root/Runtime/Export/UnityEngineCamera.txt
blob: 92a79308913ab0f11cf3e7e5fc0564a94b049653 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
C++RAW

#include "UnityPrefix.h"
#include "Configuration/UnityConfigure.h"
#include "Runtime/Scripting/ScriptingExportUtility.h"
#include "Runtime/Camera/Camera.h"
#include "Runtime/Camera/RenderManager.h"
#include "Runtime/Misc/GameObjectUtility.h"
#include "Runtime/Graphics/ScreenManager.h"
#include "Runtime/Graphics/CubemapTexture.h"
#include "Runtime/GfxDevice/GfxDevice.h"
#include "Runtime/Scripting/Scripting.h"

CSRAW
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Collections;

namespace UnityEngine
{

// Rendering path of a [[Camera]].
ENUM RenderingPath
	// Use Player Settings.
	UsePlayerSettings = -1,

	// Vertex Lit.
	VertexLit = 0,

	// Forward Rendering.
	Forward = 1,

	// Deferred Lighting.
	DeferredLighting = 2
END


// Transparent object sorting mode of a [[Camera]].
ENUM TransparencySortMode
	// Default sorting mode.
	Default = 0,

	// Perspective sorting mode.
	Perspective = 1,

	// Orthographic sorting mode.
	Orthographic = 2
END


// A Camera is a device through which the player views the world.
CLASS Camera : Behaviour

	// *undocumented* deprecated
	OBSOLETE warning use Camera.fieldOfView instead.
	CSRAW public float fov { get { return fieldOfView; } set { fieldOfView = value; } }
	// *undocumented* deprecated
	OBSOLETE warning use Camera.nearClipPlane instead.
	CSRAW public float near { get { return nearClipPlane; } set { nearClipPlane = value; } }
	// *undocumented* deprecated
	OBSOLETE warning use Camera.farClipPlane instead.
	CSRAW public float far { get { return farClipPlane; } set { farClipPlane = value; } }

	// The field of view of the camera in degrees.
	AUTO_PROP float fieldOfView GetFov SetFov

	// The near clipping plane distance.
	AUTO_PROP float nearClipPlane GetNear SetNear

	// The far clipping plane distance.
	AUTO_PROP float farClipPlane GetFar SetFar


	// Rendering path.
	AUTO_PROP RenderingPath renderingPath GetRenderingPath SetRenderingPath

	// Actually used rendering path (RO).
	CUSTOM_PROP RenderingPath actualRenderingPath { return self->CalculateRenderingPath(); }

	// High dynamic range rendering
	AUTO_PROP bool hdr CalculateUsingHDR SetHDR

	// Camera's half-size when in orthographic mode.
	AUTO_PROP float orthographicSize GetOrthographicSize SetOrthographicSize

	// Is the camera orthographic (''true'') or perspective (''false'')?
	AUTO_PROP bool orthographic GetOrthographic SetOrthographic


	// Transparent object sorting mode.
	AUTO_PROP TransparencySortMode transparencySortMode GetSortMode SetSortMode


	OBSOLETE planned Use orthographic instead
	CSRAW public bool isOrthoGraphic { get { return orthographic; } set { orthographic = value; } }

	// Camera's depth in the camera rendering order.
	AUTO_PROP float depth GetDepth SetDepth

	// The aspect ratio (width divided by height).
	AUTO_PROP float aspect GetAspect SetAspect

	// This is used to render parts of the scene selectively.
	AUTO_PROP int cullingMask GetCullingMask SetCullingMask

	// The event mask used by the camera.
	AUTO_PROP int eventMask GetEventMask SetEventMask

	// The color with which the screen will be cleared.
	AUTO_PROP Color backgroundColor GetBackgroundColor SetBackgroundColor


	// Where on the screen is the camera rendered in normalized coordinates.
	AUTO_PROP Rect rect GetNormalizedViewportRect SetNormalizedViewportRect

	// Where on the screen is the camera rendered in pixel coordinates.
	AUTO_PROP Rect pixelRect GetScreenViewportRect SetScreenViewportRect

	// Destination render texture __(Unity Pro only)__.
	AUTO_PTR_PROP RenderTexture targetTexture GetTargetTexture SetTargetTexture

	CUSTOM private void SetTargetBuffersImpl(out RenderBuffer color, out RenderBuffer depth)
	{
		self->SetTargetBuffersScript(1, color, depth);
	}

	CUSTOM private void SetTargetBuffersMRTImpl(RenderBuffer[] color, out RenderBuffer depth)
	{
		int count = GetScriptingArraySize(color);
		if (count < 1 || count > kMaxSupportedRenderTargets)
		{
			ErrorString ("Invalid color buffer count for SetTargetBuffers");
			return;
		}

		self->SetTargetBuffersScript(count, Scripting::GetScriptingArrayStart<ScriptingRenderBuffer>(color), depth);
	}

	CSRAW public void SetTargetBuffers(RenderBuffer colorBuffer, RenderBuffer depthBuffer)
	{
		SetTargetBuffersImpl(out colorBuffer, out depthBuffer);
	}

	CSRAW public void SetTargetBuffers(RenderBuffer[] colorBuffer, RenderBuffer depthBuffer)
	{
		SetTargetBuffersMRTImpl(colorBuffer, out depthBuffer);
	}


	// How wide is the camera in pixels (RO).
	CUSTOM_PROP float pixelWidth { return self->GetScreenViewportRect ().Width(); }
	// How tall is the camera in pixels (RO).
	CUSTOM_PROP float pixelHeight { return self->GetScreenViewportRect ().Height(); }

	// Matrix that transforms from camera space to world space (RO).
	AUTO_PROP Matrix4x4 cameraToWorldMatrix GetCameraToWorldMatrix

	// Matrix that transforms from world to camera space.
	AUTO_PROP Matrix4x4 worldToCameraMatrix GetWorldToCameraMatrix SetWorldToCameraMatrix

	// Make the rendering position reflect the camera's position in the scene.
	AUTO void ResetWorldToCameraMatrix ();


	// Set a custom projection matrix.
	AUTO_PROP Matrix4x4 projectionMatrix GetProjectionMatrix SetProjectionMatrix

	// Make the projection reflect normal camera's parameters.
	AUTO void ResetProjectionMatrix ();

	// Revert the aspect ratio to the screen's aspect ratio.
	AUTO void ResetAspect ();

	// Get the world-space speed of the camera (RO).
	AUTO_PROP Vector3 velocity GetVelocity

	// How the camera clears the background.
	AUTO_PROP CameraClearFlags clearFlags GetClearFlags SetClearFlags

	// Transforms /position/ from world space into screen space.
	AUTO Vector3 WorldToScreenPoint (Vector3 position);

	// Transforms /position/ from world space into viewport space.
	AUTO Vector3 WorldToViewportPoint (Vector3 position);


	// Transforms /position/ from viewport space into world space.
	AUTO Vector3 ViewportToWorldPoint (Vector3 position);

	// Transforms /position/ from screen space into world space.
	AUTO Vector3 ScreenToWorldPoint (Vector3 position);


	// Transforms /position/ from screen space into viewport space.
	AUTO Vector3 ScreenToViewportPoint (Vector3 position);

	// Transforms /position/ from viewport space into screen space.
	AUTO Vector3 ViewportToScreenPoint (Vector3 position);


	// Returns a ray going from camera through a viewport point.
	CUSTOM Ray ViewportPointToRay (Vector3 position) { return self->ViewportPointToRay (Vector2f (position.x, position.y)); }

	// Returns a ray going from camera through a screen point.
	CUSTOM Ray ScreenPointToRay (Vector3 position) { return self->ScreenPointToRay (Vector2f (position.x, position.y)); }


	// The first enabled camera tagged "MainCamera" (RO).
	CUSTOM_PROP static Camera main
	{
		return Scripting::ScriptingWrapperFor(FindMainCamera());
	}

	// The camera we are currently rendering with, for low-level render control only (Read Only).
	CUSTOM_PROP static Camera current { return Scripting::ScriptingWrapperFor (GetCurrentCameraPtr()); }

	// Returns all enabled cameras in the scene.
	CUSTOM_PROP static Camera[] allCameras
	{
		const RenderManager::CameraContainer& onscreen  = GetRenderManager ().GetOnscreenCameras ();
		const RenderManager::CameraContainer& offscreen = GetRenderManager ().GetOffscreenCameras ();

        unsigned camCount = onscreen.size () + offscreen.size();

        int curCameraI = 0;

		ScriptingArrayPtr scriptingcams = CreateScriptingArray<ScriptingObjectPtr>(GetScriptingManager ().GetCommonClasses ().camera, camCount);

	    for (   RenderManager::CameraContainer::const_iterator camIter = onscreen.begin () ;
	            camIter != onscreen.end() ;
	            ++camIter, ++curCameraI
	        )
	    {
		    Scripting::SetScriptingArrayElement (scriptingcams, curCameraI, Scripting::ScriptingWrapperFor (*camIter));
		}

	    for (   RenderManager::CameraContainer::const_iterator camIter = offscreen.begin () ;
	            camIter != offscreen.end() ;
	            ++camIter, ++curCameraI
	        )
	    {
		    Scripting::SetScriptingArrayElement (scriptingcams, curCameraI, Scripting::ScriptingWrapperFor (*camIter));
		}

		return scriptingcams;
	}


	// *undocumented* DEPRECATED
	OBSOLETE warning use Camera.main instead.
	CSRAW public static Camera mainCamera { get { return Camera.main; } }
	//*undocumented* DEPRECATED
	OBSOLETE warning use Screen.width instead.
	CUSTOM float GetScreenWidth () { return GetScreenManager ().GetWidth ();	}
	//*undocumented* DEPRECATED
	OBSOLETE warning use Screen.height instead.
	CUSTOM float GetScreenHeight () { return GetScreenManager ().GetHeight (); }

	//*undocumented* DEPRECATED
	OBSOLETE warning Camera.DoClear is deprecated and may be removed in the future.
	CUSTOM void DoClear () {
		self->Clear ();
	}


	// OnPreCull is called before a camera culls the scene.
	CSNONE void OnPreCull ();

	// OnPreRender is called before a camera starts rendering the scene.
	CSNONE void OnPreRender ();

	// OnPostRender is called after a camera has finished rendering the scene.
	CSNONE void OnPostRender ();

	// OnRenderImage is called after all rendering is complete to render image
	CSNONE void OnRenderImage (RenderTexture source, RenderTexture destination);


	// OnRenderObject is called after camera has rendered the scene.
	CSNONE void OnRenderObject ();


	// OnWillRenderObject is called once for each camera if the object is visible.

	CONVERTEXAMPLE
	BEGIN EX
	function OnWillRenderObject() {
		// Tint the object red for identification if it is
		// being shown on the overhead mini-map view.
		if (Camera.current.name == "MiniMapcam") {
			renderer.material.color = Color.red;
		} else {
			renderer.material.color = Color.white;
		}
	}
	END EX
	///
	CSNONE void OnWillRenderObject();

	// Render the camera manually.
	CUSTOM void Render () {
		self->StandaloneRender( Camera::kRenderFlagSetRenderTarget, NULL, "" );
	}

	// Render the camera with shader replacement.
	CUSTOM void RenderWithShader (Shader shader, string replacementTag) {
		self->StandaloneRender( Camera::kRenderFlagSetRenderTarget, shader, replacementTag );
	}

	// Make the camera render with shader replacement.
	CUSTOM void SetReplacementShader (Shader shader, string replacementTag) {
		self->SetReplacementShader( shader, replacementTag );
	}
	// Remove shader replacement from camera.
	AUTO void ResetReplacementShader ();

	AUTO_PROP bool useOcclusionCulling GetUseOcclusionCulling SetUseOcclusionCulling

	// These are only used by terrain engine impostor rendering and should be used with care!
	//*undoc*
	CUSTOM void RenderDontRestore() {
		self->StandaloneRender( Camera::kRenderFlagDontRestoreRenderState | Camera::kRenderFlagSetRenderTarget, NULL, "" );
	}
	//*undoc*
	CUSTOM static void SetupCurrent (Camera cur)
	{
		if (cur)
		{
			cur->StandaloneSetup();
		}
		else
		{
			GetRenderManager ().SetCurrentCamera (NULL);
			RenderTexture::SetActive(NULL);
		}
	}


	// Render into a static cubemap from this camera.
	CSRAW public bool RenderToCubemap (Cubemap cubemap, int faceMask = 63) {
		return Internal_RenderToCubemapTexture( cubemap, faceMask );
	}

	// Render into a cubemap from this camera.
	CSRAW public bool RenderToCubemap (RenderTexture cubemap, int faceMask = 63) {
		return Internal_RenderToCubemapRT ( cubemap, faceMask );
	}


	CUSTOM private bool Internal_RenderToCubemapRT( RenderTexture cubemap, int faceMask )
	{
		RenderTexture* rt = cubemap;
		if( !rt )
		{
			ErrorString( "Cubemap must not be null" );
			return false;
		}
		return self->StandaloneRenderToCubemap( rt, faceMask );
	}
	CUSTOM private bool Internal_RenderToCubemapTexture( Cubemap cubemap, int faceMask )
	{
		Cubemap* cube = cubemap;
		if( !cube )
		{
			ErrorString( "Cubemap must not be null" );
			return false;
		}
		return self->StandaloneRenderToCubemap( cube, faceMask );
	}

	// Per-layer culling distances.
	CUSTOM_PROP float[] layerCullDistances
	{
		return CreateScriptingArray(self->GetLayerCullDistances(), 32, GetScriptingManager().GetCommonClasses().floatSingle);
	}
	{
		Scripting::RaiseIfNull(value);
		if(GetScriptingArraySize(value) != 32)
		{
			Scripting::RaiseMonoException(" Array needs to contain exactly 32 floats for layerCullDistances.");
			return;
		}
		self->SetLayerCullDistances(Scripting::GetScriptingArrayStart<float> (value));
	}

	// How to perform per-layer culling for a Camera.
	CUSTOM_PROP bool layerCullSpherical { return self->GetLayerCullSpherical(); } { self->SetLayerCullSpherical(value); }

	// Makes this camera's settings match other camera.
	CUSTOM void CopyFrom (Camera other) {
		const Camera* otherCam = other;
		if(!otherCam)
		{
			ErrorString( "Camera to copy from must not be null" );
			return;
		}

		self->CopyFrom (*otherCam);
	}

	// How and if camera generates a depth texture.
	CUSTOM_PROP DepthTextureMode depthTextureMode { return self->GetDepthTextureMode(); } { self->SetDepthTextureMode (value); }

	// Should the camera clear the stencil buffer after the lighting stage of the deferred rendering path?
	CUSTOM_PROP bool clearStencilAfterLightingPass { return self->GetClearStencilAfterLightingPass(); } { self->SetClearStencilAfterLightingPass (value); }

	CUSTOM internal bool IsFiltered (GameObject go) {
	#if UNITY_EDITOR
			return true;
//@TODO
//		return self->GetCuller().IsFiltered(*go);
	#else
		return true;
	#endif
	}
END


CSRAW }