30 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
| // #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Cameras.gdshaderinc"
 | |
| 
 | |
| #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Transform.gdshaderinc"
 | |
| 
 | |
| bool cameraContainsLayerIndex( int layerIndex, uint _CAMERA_VISIBLE_LAYERS )
 | |
| {
 | |
|   uint layer = uint( 1 << ( layerIndex - 1 ) );
 | |
|   return ( _CAMERA_VISIBLE_LAYERS & layer ) == layer;
 | |
| }
 | |
| 
 | |
| bool cameraHasOnlyLayerIndex( int layerIndex, uint _CAMERA_VISIBLE_LAYERS )
 | |
| {
 | |
|   uint layer = uint( 1 << ( layerIndex - 1 ) );
 | |
|   return _CAMERA_VISIBLE_LAYERS == layer;
 | |
| }
 | |
| 
 | |
| float cameraDistanceLocal( vec3 localPosition, vec3 _CAMERA_POSITION_WORLD, mat4 _MODEL_MATRIX )
 | |
| {
 | |
|   vec3 worldPosition = localToWorld( localPosition, _MODEL_MATRIX );
 | |
| 
 | |
|   return length( worldPosition - _CAMERA_POSITION_WORLD );
 | |
| }
 | |
| 
 | |
| float cameraDistanceAmount( vec3 localPosition, vec3 _CAMERA_POSITION_WORLD, mat4 _MODEL_MATRIX, float close, float far )
 | |
| {
 | |
|   float distance = cameraDistanceLocal( localPosition, _CAMERA_POSITION_WORLD, _MODEL_MATRIX );
 | |
|   float mapped = ( distance - close ) / ( far - close );
 | |
|   return clamp( mapped, 0, 1 );
 | |
| }
 |