Looooong / Unity-SRP-VXGI

Voxel-based Global Illumination using Unity Scriptable Render Pipeline
MIT License
774 stars 63 forks source link

How to set enviroment lighting #17

Closed Wenzy-- closed 5 years ago

Wenzy-- commented 5 years ago

Hi,Looooong.Your VXGI addon is great.But I don't know where to set the environmental lighting.In SEGI, I can go to the LightingSetting - envirment lighting - ambient color to set.But in VXGI this doesn't work.So the shadows are alway very dark.I can't make a bright environment~

Looooong commented 5 years ago

I didn't implement ambient lighting, so you will have to modify the shader to add ambient lighting. This is where the final color is outputted to the screen:

https://github.com/Looooong/Unity-SRP-VXGI/blob/663af605463b92c77f69f34b67e891535857a0ca/Shaders/VXGI.shader#L120

You can add a variable for ambient color, for example:

// Remember to define Ambient variable
o.color = float4(Ambient + emission + PixelRadiance(data, indirectDiffuseRadiance), 1.0);

And use Shader.SetGlobalColor or CommandBuffer.SetGlobalColor to assign ambient color to Ambient variable. The former method can be easily implemented in a MonoBehaviour script, while the later requires your knowledge in Scriptable Render Pipeline.

Wenzy-- commented 5 years ago

Thanks for your reply. That code you mentioned is very useful. I think you can consider intergrating it in the next version. It's convenient for the design tweaking.

But I remain some problems.This is the origin version by VXGI.There are some procedural mesh.Lighting is nice. vxgi

This is what I did as you said, add the ambient value.

vxgi plus ambient

But I think the result is easy to turn "gray" and "white",i mean the saturation is decrese.Is there other way I can add this ambient value?Maybe not use the simple addition.

I have try to add a scaleVal in it,like

o.color = float4(emission + PixelRadiance(data, indirectDiffuseRadiance * scaleVal), 1.0);

I think it just control the intensity of the second bounce.

goal

This color and result is close to what I want in ambient light.To light the object. Do you have any suggestion where can I apply the ambient value?

Wenzy-- commented 5 years ago

I try this one below. It seems better

  o.color = float4(emission + PixelRadiance(data, AmbientColor + indirectDiffuseRadiance * IndirectDiffuseRatio), 1.0);

Looooong commented 5 years ago

According to the document, Unity does have interval shader variable for ambient lighting. You can check out the Fog and Ambient section. I didn't test that out, so you might have to give it a try.

Looooong commented 5 years ago

But I think the result is easy to turn "gray" and "white"

First, check if you have set the project setting to use Linear Color Space. Secondly, the display can only display color in Low Dynamic Range. Therefore, to display HDR color correctly, we will have to implement tonemapping effect to map HDR color to LDR color.

Looooong commented 5 years ago

As you can see, ambient color is just a constant. Back then, it was used to compensate for indirect lighting which was very expensive to compute. As a result, when you add ambient color to the image, it just feel un-natural. This is why I didn't implement ambient color in the first place.

Looooong commented 5 years ago

I have added #23 which allows injection of environment lighting into the scene. The setting can be turned on or off in the render pipeline asset inspector.

Looooong commented 5 years ago

23 is replaced by #24.

Wenzy-- commented 5 years ago

I have tested.Very convenient and works well~

Looooong commented 5 years ago

I have merged this into master branch.