Skip to content
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

Apply fog before tonemapping and encoding #26208

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/jsm/effects/OutlineEffect.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ class OutlineEffect {

' gl_FragColor = vec4( outlineColor, outlineAlpha );',

' #include <fog_fragment>',
' #include <tonemapping_fragment>',
' #include <colorspace_fragment>',
' #include <fog_fragment>',
' #include <premultiplied_alpha_fragment>',

'}'
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/lines/LineMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,9 @@ ShaderLib[ 'line' ] = {

gl_FragColor = vec4( diffuseColor.rgb, alpha );

#include <fog_fragment>
#include <tonemapping_fragment>
#include <colorspace_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>

}
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/loaders/LDrawLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ class LDrawConditionalLineMaterial extends ShaderMaterial {
#include <color_fragment>
outgoingLight = diffuseColor.rgb; // simple shader
gl_FragColor = vec4( outgoingLight, diffuseColor.a );
#include <fog_fragment>
#include <tonemapping_fragment>
#include <colorspace_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
}
`,
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/materials/MeshGouraudMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ const GouraudShader = {
#include <envmap_fragment>

#include <opaque_fragment>
#include <fog_fragment>
#include <tonemapping_fragment>
#include <colorspace_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
#include <dithering_fragment>

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/objects/Water.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ class Water extends Mesh {
vec3 outgoingLight = albedo;
gl_FragColor = vec4( outgoingLight, alpha );

#include <fog_fragment>
#include <tonemapping_fragment>
#include <colorspace_fragment>
#include <fog_fragment>
}`

};
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/objects/Water2.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ Water.WaterShader = {
// multiply water color with the mix of both textures
gl_FragColor = vec4( color, 1.0 ) * mix( refractColor, reflectColor, reflectance );

#include <fog_fragment>
#include <tonemapping_fragment>
#include <colorspace_fragment>
#include <fog_fragment>

}`

Expand Down
Binary file modified examples/screenshots/games_fps.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/misc_controls_map.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webaudio_orientation.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_animation_skinning_ik.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_buffergeometry.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_buffergeometry_points.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_buffergeometry_uint.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_custom_attributes_points2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_custom_attributes_points3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_geometry_dynamic.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_geometry_terrain.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_geometry_text.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_gpgpu_birds_gltf.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_gpgpu_protoplanet.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_helpers.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_interactive_buffergeometry.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_interactive_points.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_amf.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_gcode.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_md2_control.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_pcd.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_texture_ktx.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_ttf.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_lod.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_materials_texture_filters.jpg
Binary file modified examples/screenshots/webgl_materials_texture_manualmipmap.jpg
Binary file modified examples/screenshots/webgl_points_billboards.jpg
Binary file modified examples/screenshots/webgl_postprocessing_glitch.jpg
Binary file modified examples/screenshots/webgl_postprocessing_pixel.jpg
Binary file modified examples/screenshots/webgl_postprocessing_procedural.jpg
Binary file modified examples/screenshots/webgl_sprites.jpg
Binary file modified examples/screenshots/webxr_vr_teleport.jpg
Binary file modified examples/screenshots/webxr_xr_cubes.jpg
Binary file modified examples/screenshots/webxr_xr_dragging.jpg
2 changes: 1 addition & 1 deletion src/renderers/shaders/ShaderLib/linedashed.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ void main() {
outgoingLight = diffuseColor.rgb; // simple shader

#include <opaque_fragment>
#include <fog_fragment>
#include <tonemapping_fragment>
#include <colorspace_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>

}
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/shaders/ShaderLib/meshbasic.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ void main() {
#include <envmap_fragment>

#include <opaque_fragment>
#include <fog_fragment>
#include <tonemapping_fragment>
#include <colorspace_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
#include <dithering_fragment>

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/shaders/ShaderLib/meshlambert.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ void main() {

#include <envmap_fragment>
#include <opaque_fragment>
#include <fog_fragment>
#include <tonemapping_fragment>
#include <colorspace_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
#include <dithering_fragment>

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/shaders/ShaderLib/meshmatcap.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ void main() {
vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;

#include <opaque_fragment>
#include <fog_fragment>
#include <tonemapping_fragment>
#include <colorspace_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
#include <dithering_fragment>

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/shaders/ShaderLib/meshphong.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ void main() {

#include <envmap_fragment>
#include <opaque_fragment>
#include <fog_fragment>
#include <tonemapping_fragment>
#include <colorspace_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
#include <dithering_fragment>

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/shaders/ShaderLib/meshphysical.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ void main() {
#endif

#include <opaque_fragment>
#include <fog_fragment>
#include <tonemapping_fragment>
#include <colorspace_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
#include <dithering_fragment>

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/shaders/ShaderLib/meshtoon.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ void main() {
vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;

#include <opaque_fragment>
#include <fog_fragment>
#include <tonemapping_fragment>
#include <colorspace_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>
#include <dithering_fragment>

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/shaders/ShaderLib/points.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ void main() {
outgoingLight = diffuseColor.rgb;

#include <opaque_fragment>
#include <fog_fragment>
#include <tonemapping_fragment>
#include <colorspace_fragment>
#include <fog_fragment>
#include <premultiplied_alpha_fragment>

}
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/shaders/ShaderLib/shadow.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ void main() {

gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );

#include <fog_fragment>
#include <tonemapping_fragment>
#include <colorspace_fragment>
#include <fog_fragment>

}
`;
2 changes: 1 addition & 1 deletion src/renderers/shaders/ShaderLib/sprite.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ void main() {
outgoingLight = diffuseColor.rgb;

#include <opaque_fragment>
#include <fog_fragment>
#include <tonemapping_fragment>
#include <colorspace_fragment>
#include <fog_fragment>

}
`;
25 changes: 22 additions & 3 deletions src/renderers/webgl/WebGLMaterials.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BackSide } from '../../constants.js';
import { getUnlitUniformColorSpace } from '../shaders/UniformsUtils.js';
import { BackSide, LinearSRGBColorSpace, SRGBColorSpace } from '../../constants.js';
import { ColorManagement } from '../../math/ColorManagement.js';

function WebGLMaterials( renderer, properties ) {

Expand All @@ -17,7 +17,26 @@

function refreshFogUniforms( uniforms, fog ) {

fog.color.getRGB( uniforms.fogColor.value, getUnlitUniformColorSpace( renderer ) );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The default value (THREE.ColorManagement.workingColorSpace) would be the best choice. There's a mistake in the Color#getRGB documentation, to be fixed by #26210.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Oletus has this been resolved?

if ( ColorManagement.enabled ) {

fog.color.getRGB( uniforms.fogColor.value, LinearSRGBColorSpace );

} else {

if ( getUnlitUniformColorSpace( renderer ) === SRGBColorSpace ) {

Check warning on line 26 in src/renderers/webgl/WebGLMaterials.js

View workflow job for this annotation

GitHub Actions / Lint testing

'getUnlitUniformColorSpace' is not defined

// We do this to match previous behaviour, though it's a bit unintuitive to apply color management operations in case color management is disabled.

_color.copySRGBToLinear( fog.color );

Check warning on line 30 in src/renderers/webgl/WebGLMaterials.js

View workflow job for this annotation

GitHub Actions / Lint testing

'_color' is not defined
_color.getRGB( uniforms.fogColor.value );

Check warning on line 31 in src/renderers/webgl/WebGLMaterials.js

View workflow job for this annotation

GitHub Actions / Lint testing

'_color' is not defined

} else {

fog.color.getRGB( uniforms.fogColor.value );

}

}

if ( fog.isFog ) {

Expand Down
Loading