1, Scnlight Introduction
Used to add light sources, connect to a node illuminate the scene, you can add different lights to the scene, simulating a realistic environment.
2, four kinds of light introduction
Add a box cube, a tube cylindrical pipe, and a floor, and the object is a white model when there is no light:
The four lights are ambient, omni, directional and point, as well as a light-field network and a fluorescent probe. After adding different lights, the effect is as follows:
// Light Type Enumeration @property (nonatomic, copy) Scnlighttype type;
Foundation_extern ScnlighttypeConstScnlighttypeambient;//Ambient light: ambient light is the source of control of the overall brightness of the scene Ambient. Foundation_extern ScnlighttypeConstScnlighttypeomni;//Omni Light: Bright light in the daytime sky-the sun-basically the almighty lightFoundation_extern ScnlighttypeConstscnlighttypedirectional;//directional Lights (directional light): This type emits parallel light in a particular direction. Foundation_extern ScnlighttypeConstScnlighttypespot;//Point Light: This type of light is also directional, but the light is emitted from a single point in the space and Sopt with a cone. Foundation_extern ScnlighttypeConstScnlighttypeies api_available (MacOS (10.12), iOS (10.0), tvOS (10.0));//The optical domain network is a three-dimensional representation of the luminance distribution of the light source, which is stored in the ies file. Https://baike.baidu.com/item/%E5%85%89%E5%9F%9F%E7%BD%91/86200?fr=aladdinFoundation_extern ScnlighttypeConstScnlighttypeprobe api_available (MacOS (10.12), iOS (10.0), tvOS (10.0));//fluorescence probe https://baike.baidu.com/item/%e8%8d%a7%e5%85%89%e6%8e%a2%e9%92%88/2698663
- Omni-directional Light (Scnlighttypeomni): For example the sun. (1) on the original model to add a full range of light white! )
- Ambient light (scnlighttypeambient): The source used to control the overall brightness of the scene. Note that ambient light needs to be added to other lights before it works! (2) in the original omni-directional light based on the addition of an environmental light ocean blue! )
- Directional Light (scnlighttypedirectional): Light is parallel to the ray. (3) Add a directional light orange red on the above basis! )
- Note the orange-red arrow is the direction of light emission.
- Point Light Source (Scnlighttypespot): A single point is emitted and expanded with a cone. Use it for more focused light sources, such as in a crazy nightclub chase scene, police helicopters are tracking cars fleeing robbers. (4) Remove other lights add point light source red
- Attached: Simple description of light coordinates
- 1, is selected time-varying yellow;
- 2, X-axis-red arrow, y-axis-green arrow, z-axis-Blue arrow (right method);
- 3, the screen moves the selected angle area, the rotation is selected the edge of the angle area;
3. Introduction to other APIs
// Initialize + (instancetype) light;
- Modify the appearance of light light
//Light Type Enumeration@property (nonatomic, copy) scnlighttype type;//Light Color@property (nonatomic, retain)IDcolor;//Color Temperature//Kelvin Temperature. The renderer multiplies the color of the light by the color produced by the temperature of the light. The default is 6500 (pure white). Can be made into animations. @property (nonatomic) cgfloat temperature api_available (MacOS (10.12), iOS (10.0), tvOS (10.0));//light intensity, luminous flux//This intensity is used to adjust the color of the light. When used with physics-based materials, it corresponds to luminous flux, expressed in lumens (LM). The default is 1000. Can be made into animations. @property (nonatomic) cgfloat intensity api_available (MacOS (10.12), iOS (10.0), tvOS (10.0));//The data describing the illumination environment in each direction of the light detector. //at present, spherical harmonics are only supported by optical probes (scnlighttypeprobe). The data is an array of 27 32-bit floating-point values, containing three non-intersecting datasets corresponding to the red, green, and blue coefficients. @property (nonatomic, copy,ReadOnly) NSData *sphericalharmonicscoefficients api_available (MacOS (10.13), iOS (11.0), tvOS (11.0), watchOS (4.0));
// Light name @property (nonatomic, copy, nullable) NSString *name;
- Managing Light Attenuation
//The intensity of light begins to weaken the distance. Can be made into animations. //use only type Point light scnlighttypespot and omni-directional light Scnlighttypeomni, default is 0@property (nonatomic) cgfloat attenuationstartdistance api_available (MacOS (10.10));//The intensity of light is completely weakened by the distance//use only type Point light scnlighttypespot and omni-directional light Scnlighttypeomni, default is 0@property (nonatomic) cgfloat attenuationenddistance api_available (MacOS (10.10));//specifies the attenuation between the start and end falloff distances. 0 represents a constant attenuation, 1 linear attenuation, 2 two attenuation////Use only type Point light scnlighttypespot and omni-directional light source Scnlighttypeomni, default is 2, can animate@property (nonatomic) cgfloat attenuationfalloffexponent api_available (MacOS (10.10));
- Manage the range of spotlights
//You can define a tapered illumination area for a spotlight with a position and direction (from the node that contains the light) and an angle that specifies the width of the cone. In addition, the lighting area can smoothly transition from full illumination to no illumination. This property determines the width of the entire illumination area. //The default value is 0.0, which specifies that only the center of the area where the spotlight is illuminated is fully illuminated. @property (nonatomic) cgfloat spotinnerangle api_available (MacOS (10.10));//This property determines the width of the converted area. The default value is 45.0. @property (nonatomic) cgfloat spotouterangle api_available (MacOS (10.10));//in the terminology of photography and stage lighting, Gobo (also known as flag or cookie) is a template, gel, or other object placed in front of the light source, which forms or beams. //change the appearance of the spotlight by changing the content properties of the object that is permanently assigned to the property. As with other material properties, you can use a color or image, or a core animation layer that contains animated content, as a lighting gobo. //This property applies only to lights with a type attribute of spot. @property (Nonatomic,ReadOnly, nullable) Scnmaterialproperty *gobo api_available (MacOS (10.9));
- Manage Shadows of Light casts
//whether casting shadows is supported//only light-type point light scnlighttypespot and directional light scnlighttypedirectional are supported@property (nonatomic) BOOL Castsshadow;//Specifies the color of the sink's shadow (Cgcolorref or NSColor). The default is black. Can be made into animations. //on iOS 9 or before MacOS 10.11 or earlier, the default is black 50% transparent. @property (nonatomic, retain)IDShadowcolor;//Specifies the sample radius used to render the receiver shadow. The default value is 3.0. Can be made into animations@property (nonatomic) cgfloat Shadowradius;//Specifies the size of the shadow map. //the larger the shadow map, the more accurate the shadow, but the slower the calculation. If set to {0,0}, the size of the shadow map is automatically selected. The default is {0}. @property (nonatomic) cgsize shadowmapsize api_available (MacOS (10.10));//Specify the number of samples per fragment to calculate the shadow map. The default value is 0. //at MacOS 10.11 or earlier, Shadowsamplecount defaults to 16. On iOS 9 or before, the default is 1.0. //In MacOS 10.12, IOS 10, and later, when Shadowsamplecount is set to 0 o'clock, the default sample count is selected based on the platform. @property (nonatomic) Nsuinteger shadowsamplecount api_available (MacOS (10.10));//Specifies the pattern used to cast shadows. The default is Scnshadowmodeforward. @property (nonatomic) scnshadowmode Shadowmode api_available (MacOS (10.10));/*enumeration Scnshadowmode @abstract casts Shadows when Shadow mode is set to Scnshadowmodeforward, shadows are calculated when lighting is calculated. In this mode, only the alpha component of the shadow color is used to change the illumination contribution. When Shadow mode is set to Scnshadowmodedeferred shadow, it is applied as a post procedure. The shadow is mixed on the final image and can be any color. However, most of the time is less efficient than scnshadowmodeforward, unless a scene has a lot of overdraft. When Shadow mode is set to scnshadowmodemodulated, the light no longer illuminates the scene, it casts only shadows. Therefore, setting the light color has no effect. In this mode, Gobos plays the role of a shadow projector: The Gobo image is modulated by a fragment of the Shadow receiver. A typical usage is an image that uses a radial gradient (black to white) that is projected into a character (and uses the categorybitmask of light and nodes to exclude characters from the Shadow receiver). */typedef ns_enum (Nsinteger, Scnshadowmode) {Scnshadowmodeforward=0, scnshadowmodedeferred=1, scnshadowmodemodulated=2} api_available (MacOS (10.10));//The amount of correction applied to the shadow//It is multiplied by an implementation-specific value to create a constant depth offset. Default is 1.0@property (nonatomic) cgfloat Shadowbias api_available (MacOS (10.10));//Specifies the positive projection used to render from directed light to the shadow map. The default is 1. //directional light scnlighttypedirectional only for light type@property (nonatomic) cgfloat Orthographicscale api_available (MacOS (10.10));//specifies the minimum distance between the light and the surface to cast shadows. //if a surface is closer to the light than the minimum distance, then the surface will not be obscured. The proximity value must be different from 0. Can be made into animations. The default is 1. @property (nonatomic) cgfloat znear api_available (MacOS (10.10));//Specifies the maximum distance between the light and the visible surface to cast shadows. //If a surface is far above the maximum distance from the light, then the surface will not be obscured. Can be made into animations. The default is 100. @property (nonatomic) cgfloat Zfar api_available (MacOS (10.10));
- Select the node to be illuminated by the light
// determines the node category that will be lit by the receiver. The default setting is all bit sets. It defines which category the light belongs to. @property (nonatomic) Nsuinteger categorybitmask api_available (MacOS (10.10));
// Specify the ies file to determine the shape, orientation, and light intensity. The default is zero. @property (nonatomic, retain, nullable) Nsurl *iesprofileurl api_available (MacOS (10.12), iOS (10.0 ), tvOS (10.0));
//Specifies whether shadow mapping projection should be done automatically or manually by the user. The default value is yes. @property (nonatomic) BOOL automaticallyadjustsshadowprojection api_available (MacOS (10.13), iOS (11.0), tvOS (11.0), watchOS (4.0));//Specifies the maximum distance from the viewpoint that the shadow of the received light is not computed. The default is 100.0. @property (nonatomic) cgfloat maximumshadowdistance api_available (MacOS (10.13), iOS (11.0), tvOS (11.0), watchOS (4.0));//when enabled, only the back of the shadow Caster is rendered. I don't think so. @property (nonatomic) BOOL forcesbackfacecasters api_available (MacOS (10.13), iOS (11.0), tvOS (11.0), watchOS (4.0));//use the sample distribution of the master render to better fit the shadow effect. I don't think so. @property (nonatomic) BOOL sampledistributedshadowmaps api_available (MacOS (10.13), iOS (11.0), tvOS (11.0), watchOS (4.0));//Specifies the number of different shadow mappings that will be computed for the received light. The default is 1. The largest is 4. @property (nonatomic) Nsuinteger shadowcascadecount api_available (MacOS (10.13), iOS (11.0), tvOS (11.0), watchOS (4.0));//specifies a factor that interpolates between a linear split (0) and a logarithmic partition (1). The default value is 0.15. @property (nonatomic) cgfloat shadowcascadesplittingfactor api_available (MacOS (10.13), iOS (11.0), tvOS (11.0), watchOS (4.0));
iOS Development Scenekit Framework--scnlight.h