-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic PBR implementation #261
Conversation
The text below was written up by @aclysma :
|
Yes absolutely! We should consider a combined light soultion in my opinion, although the branching might make things slower than what we want. For now I was mostly focusing on point lights since that's what the engine currently works with.
Scale is an important concept I don't know if we want bevy to be responsible for determining scale as that might differ from game to game. Typically though I'm on board with 1.0f32 = 1 meter.
Not with the way bind groups get generated currently. I think we can have a
We have to keep descriptor sets below 4 to be inline with the WGPU web spec. Natively we can request for more, although I'm not sure we need to. As for uniforms it depends on the type of uniform. Here is a complete list: dictionary GPULimits {
GPUSize32 maxBindGroups = 4;
GPUSize32 maxDynamicUniformBuffersPerPipelineLayout = 8;
GPUSize32 maxDynamicStorageBuffersPerPipelineLayout = 4;
GPUSize32 maxSampledTexturesPerShaderStage = 16;
GPUSize32 maxSamplersPerShaderStage = 16;
GPUSize32 maxStorageBuffersPerShaderStage = 4;
GPUSize32 maxStorageTexturesPerShaderStage = 4;
GPUSize32 maxUniformBuffersPerShaderStage = 12;
GPUSize32 maxUniformBufferBindingSize = 16384;
}; https://gpuweb.github.io/gpuweb/#gpulimits
Thanks I'll take a look! 👍
Yeah that's a really good idea!
I'm opening to switching to that, ultimately we need buy in from @cart on that, but if they spent more time figuring out stuff than perhaps its a better fit than filament. My only concern is that filament seems a bit more open with how they figured out stuff and the entire code base is open source which makes it a bit easier to digest.
Interesting. Seems like an easy enough thing to add in.
Yes I agree, however this is how the current system works, perhaps we can create a |
One thing I noticed is in filament is that they have a cool idea for a pixel struct here which I kinda like: struct PixelParams {
vec3 diffuseColor;
float perceptualRoughness;
float perceptualRoughnessUnclamped;
vec3 f0;
float roughness;
vec3 dfg;
vec3 energyCompensation;
#if defined(MATERIAL_HAS_CLEAR_COAT)
float clearCoat;
float clearCoatPerceptualRoughness;
float clearCoatRoughness;
#endif
#if defined(MATERIAL_HAS_ANISOTROPY)
vec3 anisotropicT;
vec3 anisotropicB;
float anisotropy;
#endif
#if defined(SHADING_MODEL_SUBSURFACE) || defined(HAS_REFRACTION)
float thickness;
#endif
#if defined(SHADING_MODEL_SUBSURFACE)
vec3 subsurfaceColor;
float subsurfacePower;
#endif
#if defined(SHADING_MODEL_CLOTH) && defined(MATERIAL_HAS_SUBSURFACE_COLOR)
vec3 subsurfaceColor;
#endif
#if defined(HAS_REFRACTION)
float etaRI;
float etaIR;
float transmission;
float uThickness;
vec3 absorption;
#endif
}; |
I'm not sure if it's the same everywhere but it might be - in vulkan I was seeing all uniforms being 4k aligned. (see minUniformBufferOffsetAlignment) My guess is that for uniform data, the size of the struct won't matter if we're just talking about a few fields. So I'm not sure that compiling things out of the PixelParams struct will actually benefit performance in practice. (I could be wrong though!) For multiple light types, what I did in my code was have separate arrays of each type of light. Anything being looped is technically a branch so I don't know that it's any better than branching to three different light impls. It makes for simple code though. Again as far as I know, branching isn't really expensive on current hardware if the branch is happening based on uniform data and all the work being done within a unit of compute are taking the same paths. |
PixelParams is just a convenience struct that is passed around to various methods internally in the shader I don't think it's actually a uniform. I liked it because it packages up the current fragment in way that is relatable to PBR which is cool imo.
Yeah a separate buffer for each light type is fine I think, but we have to be careful because we get a max of 4 storage buffers and 8 uniform buffers in a shader.. :( |
What I meant by separate arrays was one buffer like this:
I think I misunderstood about the PixelParams struct - I thought that was something (like properties for a material) being passed to the shader as a buffer :) |
output_color.xyz = light_accum; | ||
|
||
// Gamma correction. | ||
output_color.xyz = output_color.xyz / (output_color.xyz + vec3(1.0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically this is not gamma correction (i.e. correcting for the output color space transfer function) but is actually an artistic tone mapping operator (Reinhard)
I've just rebased this PR on main. Now cherry-picking the commits from #1160 |
Closing in favor of #1554. |
This is a rebase of StarArawns PBR work from #261 with IngmarBitters work from #1160 cherry-picked on top. I had to make a few minor changes to make some intermediate commits compile and the end result is not yet 100% what I expected, so there's a bit more work to do. Co-authored-by: John Mitchell <[email protected]> Co-authored-by: Ingmar Bitter <[email protected]>
This is a WIP draft PR for adding basic PBR support to bevy. I used this as a resource for this implementation:
https://google.github.io/filament/Filament.md.html