mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-10 18:51:21 +03:00
0024344: TKOpenGl - only front side is lighted within Phong GLSL program
This commit is contained in:
parent
4fe9ad57df
commit
c90e941f78
@ -46,13 +46,14 @@ void pointLight (in int theId,
|
|||||||
|
|
||||||
vec3 aHalf = normalize (aLight + theView);
|
vec3 aHalf = normalize (aLight + theView);
|
||||||
|
|
||||||
float aNdotL = max (0.0, dot (theNormal, aLight));
|
vec3 aFaceSideNormal = gl_FrontFacing ? theNormal : -theNormal;
|
||||||
float aNdotH = max (0.0, dot (theNormal, aHalf ));
|
float aNdotL = max (0.0, dot (aFaceSideNormal, aLight));
|
||||||
|
float aNdotH = max (0.0, dot (aFaceSideNormal, aHalf ));
|
||||||
|
|
||||||
float aSpecl = 0.0;
|
float aSpecl = 0.0;
|
||||||
if (aNdotL > 0.0)
|
if (aNdotL > 0.0)
|
||||||
{
|
{
|
||||||
aSpecl = pow (aNdotH, occFrontMaterial_Shininess());
|
aSpecl = pow (aNdotH, gl_FrontFacing ? occFrontMaterial_Shininess() : occBackMaterial_Shininess());
|
||||||
}
|
}
|
||||||
|
|
||||||
Diffuse += occLight_Diffuse (theId).rgb * aNdotL * anAtten;
|
Diffuse += occLight_Diffuse (theId).rgb * aNdotL * anAtten;
|
||||||
@ -71,13 +72,15 @@ void directionalLight (in int theId,
|
|||||||
}
|
}
|
||||||
|
|
||||||
vec3 aHalf = normalize (aLight + theView);
|
vec3 aHalf = normalize (aLight + theView);
|
||||||
float aNdotL = max (0.0, dot (theNormal, aLight));
|
|
||||||
float aNdotH = max (0.0, dot (theNormal, aHalf ));
|
vec3 aFaceSideNormal = gl_FrontFacing ? theNormal : -theNormal;
|
||||||
|
float aNdotL = max (0.0, dot (aFaceSideNormal, aLight));
|
||||||
|
float aNdotH = max (0.0, dot (aFaceSideNormal, aHalf ));
|
||||||
|
|
||||||
float aSpecl = 0.0;
|
float aSpecl = 0.0;
|
||||||
if (aNdotL > 0.0)
|
if (aNdotL > 0.0)
|
||||||
{
|
{
|
||||||
aSpecl = pow (aNdotH, occFrontMaterial_Shininess());
|
aSpecl = pow (aNdotH, gl_FrontFacing ? occFrontMaterial_Shininess() : occBackMaterial_Shininess());
|
||||||
}
|
}
|
||||||
|
|
||||||
Diffuse += occLight_Diffuse (theId).rgb * aNdotL;
|
Diffuse += occLight_Diffuse (theId).rgb * aNdotL;
|
||||||
@ -111,9 +114,12 @@ vec4 computeLighting (in vec3 theNormal,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return vec4 (Ambient, 1.0) * occFrontMaterial_Ambient()
|
vec4 aMaterialAmbient = gl_FrontFacing ? occFrontMaterial_Ambient() : occBackMaterial_Ambient();
|
||||||
+ vec4 (Diffuse, 1.0) * occFrontMaterial_Diffuse()
|
vec4 aMaterialDiffuse = gl_FrontFacing ? occFrontMaterial_Diffuse() : occBackMaterial_Diffuse();
|
||||||
+ vec4 (Specular, 1.0) * occFrontMaterial_Specular();
|
vec4 aMaterialSpecular = gl_FrontFacing ? occFrontMaterial_Specular() : occBackMaterial_Specular();
|
||||||
|
return vec4 (Ambient, 1.0) * aMaterialAmbient
|
||||||
|
+ vec4 (Diffuse, 1.0) * aMaterialDiffuse
|
||||||
|
+ vec4 (Specular, 1.0) * aMaterialSpecular;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Entry point to the Fragment Shader
|
//! Entry point to the Fragment Shader
|
||||||
|
37
tests/v3d/glsl/phong_sides
Normal file
37
tests/v3d/glsl/phong_sides
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
puts "========"
|
||||||
|
puts "Per-pixel lighting using GLSL program (Phong shading), check lighting of back faces"
|
||||||
|
puts "========"
|
||||||
|
|
||||||
|
# create box
|
||||||
|
box b 1 2 3
|
||||||
|
explode b F
|
||||||
|
|
||||||
|
# draw box
|
||||||
|
vinit View1
|
||||||
|
vclear
|
||||||
|
vsetdispmode 1
|
||||||
|
vaxo
|
||||||
|
vdisplay b_1 b_2
|
||||||
|
vfit
|
||||||
|
vrotate 0.2 0.0 0.0
|
||||||
|
|
||||||
|
# take snapshot with fixed pipeline
|
||||||
|
vdump $::imagedir/${::casename}_OFF.png
|
||||||
|
set aColorB [vreadpixel 150 150 rgb name]
|
||||||
|
set aColorF [vreadpixel 250 250 rgb name]
|
||||||
|
if { "$aColorB" != "$aColorF"} {
|
||||||
|
puts "Error: front/back colors are different!"
|
||||||
|
}
|
||||||
|
set aColorFixed $aColorF
|
||||||
|
|
||||||
|
# activate phong shader
|
||||||
|
vshaderprog phong
|
||||||
|
set aColorB [vreadpixel 150 150 rgb name]
|
||||||
|
set aColorF [vreadpixel 250 250 rgb name]
|
||||||
|
if { "$aColorB" != "$aColorF"} {
|
||||||
|
puts "Error: front/back colors are different!"
|
||||||
|
}
|
||||||
|
|
||||||
|
if { "$aColorF" != "$aColorFixed"} {
|
||||||
|
puts "Error: colors are different!"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user