Fog Layer

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
 
m (Text replace - "</javascript>" to "</syntaxhighlight>")
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
[[Category: Camera]]
 
[[Category: Camera]]
 
[[Category: MonoBehaviour]]
 
[[Category: MonoBehaviour]]
[[Category: Javascript]]
+
[[Category: JavaScript]]
 
Author: Joachim Ante
 
Author: Joachim Ante
 
==Description==
 
==Description==
This
+
This script lets you enable and disable fog per camera.
 +
 
 +
For changing more render settings, see [[CameraRenderSettings]]
  
 
==Usage==
 
==Usage==
Add this script to  
+
Attach the script to the camera you want to have fog enabled or disabled.
 
+
Then click on the enabled checkbox in the title of the inspector to turn fog on or off for this camera.
You might want to change Vector3.back to Vector3.front, depending on the initial orientation of your object.
+
 
+
==Technical Discussion==
+
Note that the script doesn't simply point the object at the camera.  Instead, it makes the object point in the same direction as the camera's forward axis (that is, the direction the camera is looking in).  This might seem intuitively wrong, but it's actually correct for the one-point-perspective world of realtime computer graphics.
+
  
 
==Javascript- FogLayer.js==
 
==Javascript- FogLayer.js==
<javascript>
+
<syntaxhighlight lang="javascript">
 
/*
 
/*
 
  This script lets you enable and disable per camera.
 
  This script lets you enable and disable per camera.
Line 34: Line 32:
 
@script AddComponentMenu ("Rendering/Fog Layer")
 
@script AddComponentMenu ("Rendering/Fog Layer")
 
@script RequireComponent (Camera)
 
@script RequireComponent (Camera)
</javascript>
+
</syntaxhighlight>

Latest revision as of 20:52, 10 January 2012

Author: Joachim Ante

[edit] Description

This script lets you enable and disable fog per camera.

For changing more render settings, see CameraRenderSettings

[edit] Usage

Attach the script to the camera you want to have fog enabled or disabled. Then click on the enabled checkbox in the title of the inspector to turn fog on or off for this camera.

[edit] Javascript- FogLayer.js

/*
 This script lets you enable and disable per camera.
 By enabling or disabling the script in the title of the inspector, you can turn fog on or off per camera.
*/
 
private var revertFogState = false;
 
function OnPreRender () {
	revertFogState = RenderSettings.fog;
	RenderSettings.fog = enabled;
}
 
function OnPostRender () {
	RenderSettings.fog = revertFogState;
}
 
@script AddComponentMenu ("Rendering/Fog Layer")
@script RequireComponent (Camera)
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox