Skip to content

Commit 8ad2cd9

Browse files
authored
Merge pull request #2135 from Kitware/webgl_texture_specular_mix
fix(WebGL): fix textures with specular lighting
2 parents 54b5823 + 182bccc commit 8ad2cd9

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

Sources/Rendering/OpenGL/PolyDataMapper/index.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -782,9 +782,9 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
782782
FSSource,
783783
'//VTK::TCoord::Impl',
784784
[
785-
'vec4 tcolor = texture2D(texture1, tcoordVCVSOutput);',
786-
'gl_FragData[0] = clamp(gl_FragData[0],0.0,1.0)*',
787-
' vec4(tcolor.r,tcolor.r,tcolor.r,1.0);',
785+
' vec4 tcolor = texture2D(texture1, tcoordVCVSOutput);',
786+
' ambientColor = ambientColor*tcolor.r;',
787+
' diffuseColor = diffuseColor*tcolor.r;',
788788
]
789789
).result;
790790
break;
@@ -793,17 +793,23 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
793793
FSSource,
794794
'//VTK::TCoord::Impl',
795795
[
796-
'vec4 tcolor = texture2D(texture1, tcoordVCVSOutput);',
797-
'gl_FragData[0] = clamp(gl_FragData[0],0.0,1.0)*',
798-
' vec4(tcolor.r,tcolor.r,tcolor.r,tcolor.g);',
796+
' vec4 tcolor = texture2D(texture1, tcoordVCVSOutput);',
797+
' ambientColor = ambientColor*tcolor.r;',
798+
' diffuseColor = diffuseColor*tcolor.r;',
799+
' opacity = opacity * tcolor.g;',
799800
]
800801
).result;
801802
break;
802803
default:
803804
FSSource = vtkShaderProgram.substitute(
804805
FSSource,
805806
'//VTK::TCoord::Impl',
806-
'gl_FragData[0] = clamp(gl_FragData[0],0.0,1.0)*texture2D(texture1, tcoordVCVSOutput.st);'
807+
[
808+
' vec4 tcolor = texture2D(texture1, tcoordVCVSOutput);',
809+
' ambientColor = ambientColor*tcolor.rgb;',
810+
' diffuseColor = diffuseColor*tcolor.rgb;',
811+
' opacity = opacity * tcolor.a;',
812+
]
807813
).result;
808814
}
809815
}
@@ -832,9 +838,9 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
832838
FSSource,
833839
'//VTK::TCoord::Impl',
834840
[
835-
'vec4 tcolor = textureCube(texture1, tcoordVCVSOutput);',
836-
'gl_FragData[0] = clamp(gl_FragData[0],0.0,1.0)*',
837-
' vec4(tcolor.r,tcolor.r,tcolor.r,1.0);',
841+
' vec4 tcolor = textureCube(texture1, tcoordVCVSOutput);',
842+
' ambientColor = ambientColor*tcolor.r;',
843+
' diffuseColor = diffuseColor*tcolor.r;',
838844
]
839845
).result;
840846
break;
@@ -843,17 +849,23 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
843849
FSSource,
844850
'//VTK::TCoord::Impl',
845851
[
846-
'vec4 tcolor = textureCube(texture1, tcoordVCVSOutput);',
847-
'gl_FragData[0] = clamp(gl_FragData[0],0.0,1.0)*',
848-
' vec4(tcolor.r,tcolor.r,tcolor.r,tcolor.g);',
852+
' vec4 tcolor = textureCube(texture1, tcoordVCVSOutput);',
853+
' ambientColor = ambientColor*tcolor.r;',
854+
' diffuseColor = diffuseColor*tcolor.r;',
855+
' opacity = opacity * tcolor.g;',
849856
]
850857
).result;
851858
break;
852859
default:
853860
FSSource = vtkShaderProgram.substitute(
854861
FSSource,
855862
'//VTK::TCoord::Impl',
856-
'gl_FragData[0] = clamp(gl_FragData[0],0.0,1.0)*textureCube(texture1, tcoordVCVSOutput);'
863+
[
864+
' vec4 tcolor = textureCube(texture1, tcoordVCVSOutput);',
865+
' ambientColor = ambientColor*tcolor.rgb;',
866+
' diffuseColor = diffuseColor*tcolor.rgb;',
867+
' opacity = opacity * tcolor.a;',
868+
]
857869
).result;
858870
}
859871
}

Sources/Rendering/OpenGL/glsl/vtkPolyDataFS.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ void main()
7777
// Generate the normal if we are not passed in one
7878
//VTK::Normal::Impl
7979

80-
//VTK::Light::Impl
81-
8280
//VTK::TCoord::Impl
8381

82+
//VTK::Light::Impl
83+
8484
if (gl_FragData[0].a <= 0.0)
8585
{
8686
discard;

0 commit comments

Comments
 (0)