SceneKit shader modifiers are ideal for this kind of task.
You can see the frames of the final result here .
Fragment Shader Modifier

_lightingContribution.diffuse
(RGB (vec3
), , ), ( - ), , .
, , . , ( GLSL
, Metal
, )
uniform sampler2D emissionTexture;
vec3 light = _lightingContribution.diffuse;
float lum = max(0.0, 1 - (0.2126*light.r + 0.7152*light.g + 0.0722*light.b));
vec4 emission = texture2D(emissionTexture, _surface.diffuseTexcoord) * lum;
_output.color += emission;
- ( )
_lightingContribution.diffuse
( ) - , " "
- UV- ( , )
- ( , )
, Swift.
emission.contents
, SCNMaterialProperty
let emissionTexture = UIImage(named: "earthEmission.jpg")!
let emission = SCNMaterialProperty(contents: emissionTexture)
, setValue(_:forKey:)
earthMaterial.setValue(emission, forKey: "emissionTexture")
- , . , setValue
.
, , :
let shaderModifier =
"""
uniform sampler2D emissionTexture;
vec3 light = _lightingContribution.diffuse;
float lum = max(0.0, 1 - (0.2126*light.r + 0.7152*light.g + 0.0722*light.b));
vec4 emission = texture2D(emissionTexture, _surface.diffuseTexcoord) * lum;
_output.color += emission;
"""
earthMaterial.shaderModifiers = [.fragment: shaderModifier]
footage .
, , "". lightNode.light?.intensity
2000 , , . , , .
, , _lightingContribution
- , , ambient
specular
( Metal
):
struct SCNShaderLightingContribution {
float3 ambient;
float3 diffuse;
float3 specular;
} _lightingContribution;