# Skybox and water not lit in Composition pass

**URL:** <https://forums.kodeco.com/t/skybox-and-water-not-lit-in-composition-pass/133171>\
**Category:** Metal by Tutorials\
**Created:** [February 19, 2021, 11:19pm UTC](https://forums.kodeco.com/t/skybox-and-water-not-lit-in-composition-pass/133171 "2021-02-19T23:19:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gellert5225](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/gellert5225/32/100741_2.png) [@gellert5225](https://forums.kodeco.com/u/gellert5225)\
**Post date:** [February 19, 2021, 11:19pm UTC](https://forums.kodeco.com/t/skybox-and-water-not-lit-in-composition-pass/133171/1 "2021-02-19T23:19:34Z")

</div>

Hi, I am trying to combine deferred lighting with skybox and water reflection. However the final scene is not lit:

 ![Screen Shot 2021-02-19 at 3.01.32 PM](https://files.chunter.kodeco.com/original/3X/9/7/975c178072d7b6fa1528fdcefdf8567a5285031a.jpeg)

And here are my G-Buffer textures:

 ![Screen Shot 2021-02-19 at 3.02.52 PM](https://files.chunter.kodeco.com/original/3X/9/7/97ba271bcd9bb90b1ad93602688377c9fb7662b2.jpeg)

As you can see, after the albedo texture was passed into Composition Pass’s fragment shader, it gets darker. I think the problem has something to do with normal. Because in my fragment shader, the code I used to calculate Sunlight diffuse is:

> ```
> float3 lightDirection = normalize(light.position);
> float diffuseIntensity = saturate(dot(lightDirection, normalDirection));
> diffuseColor += light.color * light.intensity * baseColor * diffuseIntensity;
> 
> ```

the `diffuseIntensity` variable depends on the normal direction, and my skybox does not really have a normal.

My render flow is as following:

```
// shadow pass
renderShadowPass(renderEncoder: shadowEncoder)

// reflection pass.
renderGbufferPass(renderEncoder: reflectEncoder)
scene.skybox?.render(renderEncoder: reflectEncoder)

// g-buffer pass
renderGbufferPass(renderEncoder: gBufferEncoder)
scene.skybox?.render(renderEncoder: gBufferEncoder)
scene.water.render(renderEncoder: gBufferEncoder)

// composition pass
...

```

So is this the correct render flow? What am I doing wrong here?

Thanks

---

<div class="post-metadata">

**Author:** ![caroline](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/caroline/32/111867_2.png) [@caroline](https://forums.kodeco.com/u/caroline)\
**Post date:** [February 20, 2021, 1:05am UTC](https://forums.kodeco.com/t/skybox-and-water-not-lit-in-composition-pass/133171/2 "2021-02-20T01:05:15Z")

</div>

It’s impossible for me to say without seeing the code.

Render flow looks fine. I would suggest taking a look at Apple’s sample code that does rendering with the skybox: [Apple Developer Documentation](https://developer.apple.com/documentation/metal/rendering_a_scene_with_deferred_lighting_in_swift)

Is that a scene manager? Looks great 👌 !

---

<div class="post-metadata">

**Author:** ![gellert5225](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/gellert5225/32/100741_2.png) [@gellert5225](https://forums.kodeco.com/u/gellert5225)\
**Post date:** [February 20, 2021, 4:46am UTC](https://forums.kodeco.com/t/skybox-and-water-not-lit-in-composition-pass/133171/3 "2021-02-20T04:46:55Z")

</div>

Hi Caroline, thank you for your reply.

I will have a look at Apple’s example. But I also tried the example code from Chapter 14, when I remove the 300 point lights, the scene has a really dark background(RGB(11, 14, 16)), where it should have a background of MTLClearColor(0.73, 0.92, 1, 1) as the sun light is still in the scene. Why does this happen and how do we fix it?

![Screen Shot 2021-02-19 at 8.44.47 PM](https://files.chunter.kodeco.com/original/3X/0/0/00dda0b9cfc81be550f65742d300ffdd644515c3.png)

And yes, I made a custom scene editor :)))

Thanks

---

<div class="post-metadata">

**Author:** ![caroline](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/caroline/32/111867_2.png) [@caroline](https://forums.kodeco.com/u/caroline)\
**Post date:** [February 20, 2021, 7:48am UTC](https://forums.kodeco.com/t/skybox-and-water-not-lit-in-composition-pass/133171/4 "2021-02-20T07:48:24Z")

</div>

I would love to answer your question, as I have a feeling that there needs some kind of stencil on the background, to stop the composition pass using incorrect color pixels from the normal and position color attachment textures. But I’m not completely familiar with this code, and am swamped with other stuff for a few days, which is why I haven’t answered your other question either 🙁.
