Skybox and water not lit in Composition pass

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

And here are my G-Buffer textures:

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

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

Is that a scene manager? Looks great :ok_hand: !

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

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

Thanks

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 :slightly_frowning_face:.