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

ShaderChunks: Ignore alpha in output_fragment when transparent = false #22414

Closed
wants to merge 2 commits into from
Closed
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: 2 additions & 0 deletions src/renderers/shaders/ShaderChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import normalmap_pars_fragment from './ShaderChunk/normalmap_pars_fragment.glsl.
import clearcoat_normal_fragment_begin from './ShaderChunk/clearcoat_normal_fragment_begin.glsl.js';
import clearcoat_normal_fragment_maps from './ShaderChunk/clearcoat_normal_fragment_maps.glsl.js';
import clearcoat_pars_fragment from './ShaderChunk/clearcoat_pars_fragment.glsl.js';
import output_fragment from './ShaderChunk/output_fragment.glsl.js';
import packing from './ShaderChunk/packing.glsl.js';
import premultiplied_alpha_fragment from './ShaderChunk/premultiplied_alpha_fragment.glsl.js';
import project_vertex from './ShaderChunk/project_vertex.glsl.js';
Expand Down Expand Up @@ -207,6 +208,7 @@ export const ShaderChunk = {
clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
clearcoat_pars_fragment: clearcoat_pars_fragment,
output_fragment: output_fragment,
packing: packing,
premultiplied_alpha_fragment: premultiplied_alpha_fragment,
project_vertex: project_vertex,
Expand Down
7 changes: 7 additions & 0 deletions src/renderers/shaders/ShaderChunk/output_fragment.glsl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default /* glsl */`
#ifdef OPAQUE
diffuseColor.a = 1.0;
#endif

gl_FragColor = vec4( outgoingLight, diffuseColor.a );
`;
3 changes: 1 addition & 2 deletions src/renderers/shaders/ShaderLib/linedashed_frag.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ void main() {

outgoingLight = diffuseColor.rgb; // simple shader

gl_FragColor = vec4( outgoingLight, diffuseColor.a );

#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
Expand Down
3 changes: 1 addition & 2 deletions src/renderers/shaders/ShaderLib/meshbasic_frag.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ void main() {

#include <envmap_fragment>

gl_FragColor = vec4( outgoingLight, diffuseColor.a );

#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
Expand Down
3 changes: 1 addition & 2 deletions src/renderers/shaders/ShaderLib/meshlambert_frag.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ void main() {

#include <envmap_fragment>

gl_FragColor = vec4( outgoingLight, diffuseColor.a );

#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
Expand Down
3 changes: 1 addition & 2 deletions src/renderers/shaders/ShaderLib/meshmatcap_frag.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ void main() {

vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;

gl_FragColor = vec4( outgoingLight, diffuseColor.a );

#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
Expand Down
4 changes: 1 addition & 3 deletions src/renderers/shaders/ShaderLib/meshphong_frag.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ void main() {
vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;

#include <envmap_fragment>

gl_FragColor = vec4( outgoingLight, diffuseColor.a );

#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
Expand Down
3 changes: 1 addition & 2 deletions src/renderers/shaders/ShaderLib/meshphysical_frag.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ void main() {

#endif

gl_FragColor = vec4( outgoingLight, diffuseColor.a );

#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
Expand Down
3 changes: 1 addition & 2 deletions src/renderers/shaders/ShaderLib/meshtoon_frag.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ void main() {

vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;

gl_FragColor = vec4( outgoingLight, diffuseColor.a );

#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
Expand Down
3 changes: 1 addition & 2 deletions src/renderers/shaders/ShaderLib/points_frag.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ void main() {

outgoingLight = diffuseColor.rgb;

gl_FragColor = vec4( outgoingLight, diffuseColor.a );

#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
Expand Down
3 changes: 1 addition & 2 deletions src/renderers/shaders/ShaderLib/sprite_frag.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ void main() {

outgoingLight = diffuseColor.rgb;

gl_FragColor = vec4( outgoingLight, diffuseColor.a );

#include <output_fragment>
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
Expand Down
1 change: 1 addition & 0 deletions src/renderers/webgl/WebGLProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',

parameters.dithering ? '#define DITHERING' : '',
parameters.transparent === false ? '#define OPAQUE' : '',

ShaderChunk[ 'encodings_pars_fragment' ], // this code is required here because it is used by the various encoding/decoding function defined below
parameters.map ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
Expand Down
4 changes: 3 additions & 1 deletion src/renderers/webgl/WebGLPrograms.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
'numDirLights', 'numPointLights', 'numSpotLights', 'numHemiLights', 'numRectAreaLights',
'numDirLightShadows', 'numPointLightShadows', 'numSpotLightShadows',
'shadowMapEnabled', 'shadowMapType', 'toneMapping', 'physicallyCorrectLights',
'doubleSided', 'flipSided', 'numClippingPlanes', 'numClipIntersection', 'depthPacking', 'dithering',
'doubleSided', 'flipSided', 'numClippingPlanes', 'numClipIntersection', 'depthPacking', 'dithering', 'transparent',
'sheenTint', 'transmission', 'transmissionMap', 'thicknessMap'
];

Expand Down Expand Up @@ -208,6 +208,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
specularIntensityMap: !! material.specularIntensityMap,
specularTintMap: !! material.specularTintMap,
specularTintMapEncoding: getTextureEncodingFromMap( material.specularTintMap ),

alphaMap: !! material.alphaMap,
alphaTest: useAlphaTest,

Expand Down Expand Up @@ -257,6 +258,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
numClipIntersection: clipping.numIntersection,

dithering: material.dithering,
transparent: material.transparent,

shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
shadowMapType: renderer.shadowMap.type,
Expand Down