Archive 17/01/2023.

[Solved] Help with tube lighting

dragonCASTjosh

As many of you know i have been working on tube lighting for the past week but i have hit a roadblock that i cant seam to solve so i have decided its time to ask for help of fixing this issue. For tube lights i am following epics PBR paper http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf. But currently all tube lights act the same as sphere lights with both the radius and length changing the size of the sphere.

All the source code for the area lighting can be found on my fork on urho https://github.com/dragonCASTjosh/Urho3D/blob/master/bin/CoreData/Shaders/HLSL/PBR.hlsl

cadaver

Do you need new uniforms for lights? In that case check where in the code e.g. the light color uniform is being set, and add there. (Search PSP_LIGHTCOLOR in Batch.cpp)

Note that it’d be preferable to not take the performance hit for setting extra uniforms when non-PBR lighting is used, but that isn’t an absolute requirement.

dragonCASTjosh

[quote=“cadaver”]Do you need new uniforms for lights? In that case check where in the code e.g. the light color uniform is being set, and add there. (Search PSP_LIGHTCOLOR in Batch.cpp)

Note that it’d be preferable to not take the performance hit for setting extra uniforms when non-PBR lighting is used, but that isn’t an absolute requirement.[/quote]

currently its not using uniforms the values are hard coded but they are not having the intended affect and im lost on where its gone wrong.

for reference the section in the paper starts end of page 16 for tube lighting, and the tube lighting method in the shader i linked is my implementation.

dragonCASTjosh

For better reference here is the affect in unreal and the the results of it in urho, it should show what the problem is.

Unreal:

Urho:

dragonCASTjosh

Multiplying Pos into https://github.com/dragonCASTjosh/Urho3D/blob/master/bin/CoreData/Shaders/HLSL/PBR.hlsl#L40 causes more of a tube effect, but this is still incorrect results as the tube always points at the player and changes shape.


dragonCASTjosh

I think i know where the errors lay although im not sure how to fix it. The following code should work out each end of the tube. L0 and L1 are points at eaither side of the tube, but i feel its calculating it wrong.

        float3 pos   = (cLightPosPS.xyz - worldPos);
        float3 L01 = lightVec * LightLengh;
        float3 L0 = pos - 0.5 * L01;
        float3 L1 = pos + 0.5 * L01;
dragonCASTjosh

Solved, turns out lightVec should be vector you want the tube to point and not the vector of the light from the tube.

Modanung

Chool