0027943: Visualization - fix broken shading by positional light for object with local...
authorkgv <kgv@opencascade.com>
Sun, 9 Oct 2016 17:48:16 +0000 (20:48 +0300)
committerapn <apn@opencascade.com>
Thu, 13 Oct 2016 10:56:39 +0000 (13:56 +0300)
OpenGl_ShaderManager, per-vertex shading and per-fragment shading
- do not apply model-world matrix on the light sources
which are expected to be defined in world-space.

src/OpenGl/OpenGl_ShaderManager.cxx
src/Shaders/PhongShading.fs
tests/v3d/glsl/gouraud_pos1 [new file with mode: 0644]
tests/v3d/glsl/gouraud_spot1 [new file with mode: 0644]
tests/v3d/glsl/phong_pos1 [new file with mode: 0644]
tests/v3d/glsl/phong_spot1 [new file with mode: 0644]

index 2af3565..d94768d 100644 (file)
@@ -83,7 +83,7 @@ const char THE_FUNC_pointLight[] =
   EOL"  vec3 aLight = occLight_Position (theId).xyz;"
   EOL"  if (occLight_IsHeadlight (theId) == 0)"
   EOL"  {"
-  EOL"    aLight = vec3 (occWorldViewMatrix * occModelWorldMatrix * vec4 (aLight, 1.0));"
+  EOL"    aLight = vec3 (occWorldViewMatrix * vec4 (aLight, 1.0));"
   EOL"  }"
   EOL"  aLight -= thePoint;"
   EOL
@@ -121,8 +121,8 @@ const char THE_FUNC_spotLight[] =
   EOL"  vec3 aSpotDir = occLight_SpotDirection (theId).xyz;"
   EOL"  if (occLight_IsHeadlight (theId) == 0)"
   EOL"  {"
-  EOL"    aLight   = vec3 (occWorldViewMatrix * occModelWorldMatrix * vec4 (aLight,   1.0));"
-  EOL"    aSpotDir = vec3 (occWorldViewMatrix * occModelWorldMatrix * vec4 (aSpotDir, 0.0));"
+  EOL"    aLight   = vec3 (occWorldViewMatrix * vec4 (aLight,   1.0));"
+  EOL"    aSpotDir = vec3 (occWorldViewMatrix * vec4 (aSpotDir, 0.0));"
   EOL"  }"
   EOL"  aLight -= thePoint;"
   EOL
@@ -171,7 +171,7 @@ const char THE_FUNC_directionalLight[] =
   EOL"  vec3 aLight = normalize (occLight_Position (theId).xyz);"
   EOL"  if (occLight_IsHeadlight (theId) == 0)"
   EOL"  {"
-  EOL"    aLight = vec3 (occWorldViewMatrix * occModelWorldMatrix * vec4 (aLight, 0.0));"
+  EOL"    aLight = vec3 (occWorldViewMatrix * vec4 (aLight, 0.0));"
   EOL"  }"
   EOL
   EOL"  vec3 aHalf = normalize (aLight + theView);"
@@ -200,7 +200,7 @@ const char THE_FUNC_directionalLightFirst[] =
   EOL"  vec3 aLight = normalize (occLightSources[1].xyz);"
   EOL"  if (occLight_IsHeadlight (0) == 0)"
   EOL"  {"
-  EOL"    aLight = vec3 (occWorldViewMatrix * occModelWorldMatrix * vec4 (aLight, 0.0));"
+  EOL"    aLight = vec3 (occWorldViewMatrix * vec4 (aLight, 0.0));"
   EOL"  }"
   EOL
   EOL"  vec3 aHalf = normalize (aLight + theView);"
index 088384d..925e5d2 100755 (executable)
@@ -31,7 +31,7 @@ void pointLight (in int  theId,
   vec3 aLight = occLight_Position (theId).xyz;
   if (occLight_IsHeadlight (theId) == 0)
   {
-    aLight = vec3 (occWorldViewMatrix * occModelWorldMatrix * vec4 (aLight, 1.0));
+    aLight = vec3 (occWorldViewMatrix * vec4 (aLight, 1.0));
   }
   aLight -= thePoint;
 
@@ -67,8 +67,8 @@ void spotLight (in int  theId,
   vec3 aSpotDir = occLight_SpotDirection (theId).xyz;
   if (occLight_IsHeadlight (theId) == 0)
   {
-    aLight   = vec3 (occWorldViewMatrix * occModelWorldMatrix * vec4 (aLight,   1.0));
-    aSpotDir = vec3 (occWorldViewMatrix * occModelWorldMatrix * vec4 (aSpotDir, 0.0));
+    aLight   = vec3 (occWorldViewMatrix * vec4 (aLight,   1.0));
+    aSpotDir = vec3 (occWorldViewMatrix * vec4 (aSpotDir, 0.0));
   }
   aLight -= thePoint;
 
@@ -116,7 +116,7 @@ void directionalLight (in int  theId,
   vec3 aLight = normalize (occLight_Position (theId).xyz);
   if (occLight_IsHeadlight (theId) == 0)
   {
-    aLight = vec3 (occWorldViewMatrix * occModelWorldMatrix * vec4 (aLight, 0.0));
+    aLight = vec3 (occWorldViewMatrix * vec4 (aLight, 0.0));
   }
 
   vec3 aHalf = normalize (aLight + theView);
diff --git a/tests/v3d/glsl/gouraud_pos1 b/tests/v3d/glsl/gouraud_pos1
new file mode 100644 (file)
index 0000000..6fdb429
--- /dev/null
@@ -0,0 +1,45 @@
+puts "========"
+puts "Per-vertex lighting using built-in GLSL program, one positional light source."
+puts "Visual comparison with the reference snapshot should be performed for this test case."
+puts "========"
+
+# create objects
+set anX 0.001
+circle c 0 0 0 0.001
+mkedge e c
+wire   w e
+plane  s
+mkface f1 s w
+mkface f2 s w
+ttranslate f1 $anX -0.001 0
+
+# display objects
+vtop
+vdisplay -dispMode 1 f1 f2
+vsetlocation f2 $anX 0.001 0
+vpoint vl $anX 0 0.001
+vfit
+
+# setup light
+vcaps -ffp 0
+vrenderparams -shadingModel vert
+vlight clear
+vlight add positional pos $anX 0 0.001 color RED1 headLight 0
+
+set aColor1 [vreadpixel 205 180 rgb name]
+set aColor2 [vreadpixel 205 210 rgb name]
+if { "$aColor1" != "RED" || "$aColor2" != "RED" } {
+  puts "Error: expected color near the light spot is RED"
+}
+
+set aColor3 [vreadpixel 205 132 rgb name]
+set aColor4 [vreadpixel 205 280 rgb name]
+if { "$aColor3" != "RED3" || "$aColor4" != "RED4" } {
+  puts "Error: expected color mid from the light spot is RED4"
+}
+
+set aColor5 [vreadpixel 205 100 rgb name]
+set aColor6 [vreadpixel 205 306 rgb name]
+if { "$aColor5" != "RED4" || "$aColor6" != "RED4" } {
+  puts "Error: expected color far from the light spot is RED4"
+}
diff --git a/tests/v3d/glsl/gouraud_spot1 b/tests/v3d/glsl/gouraud_spot1
new file mode 100644 (file)
index 0000000..7adcf8d
--- /dev/null
@@ -0,0 +1,45 @@
+puts "========"
+puts "Per-vertex lighting using built-in GLSL program, one spot light source."
+puts "Visual comparison with the reference snapshot should be performed for this test case."
+puts "========"
+
+# create objects
+set anX 0.001
+circle c 0 0 0 0.001
+mkedge e c
+wire   w e
+plane  s
+mkface f1 s w
+mkface f2 s w
+ttranslate f1 $anX -0.001 0
+
+# display objects
+vtop
+vdisplay -dispMode 1 f1 f2
+vsetlocation f2 $anX 0.001 0
+vpoint vl $anX 0 0.001
+vfit
+
+# setup light
+vcaps -ffp 0
+vrenderparams -shadingModel vert
+vlight clear
+vlight add spotLight pos $anX 0 0.001 dir 0 0 -1 angle 60 constAtten 0.1 exponent 0.1 color RED1 headLight 0
+
+set aColor1 [vreadpixel 205 180 rgb name]
+set aColor2 [vreadpixel 205 220 rgb name]
+if { "$aColor1" != "RED" || "$aColor2" != "RED" } {
+  puts "Error: expected color near the light spot is RED"
+}
+
+set aColor3 [vreadpixel 205 132 rgb name]
+set aColor4 [vreadpixel 205 280 rgb name]
+if { "$aColor3" != "RED" || "$aColor4" != "RED4" } {
+  puts "Error: expected color mid from the light spot is RED4"
+}
+
+set aColor5 [vreadpixel 205 100 rgb name]
+set aColor6 [vreadpixel 205 306 rgb name]
+if { "$aColor5" != "GRAY9" || "$aColor6" != "GRAY9" } {
+  puts "Error: expected color far from the light spot is GRAY9"
+}
diff --git a/tests/v3d/glsl/phong_pos1 b/tests/v3d/glsl/phong_pos1
new file mode 100644 (file)
index 0000000..687ef5a
--- /dev/null
@@ -0,0 +1,45 @@
+puts "========"
+puts "Per-fragment lighting using built-in GLSL program, one positional light source."
+puts "Visual comparison with the reference snapshot should be performed for this test case."
+puts "========"
+
+# create objects
+set anX 0.001
+circle c 0 0 0 0.001
+mkedge e c
+wire   w e
+plane  s
+mkface f1 s w
+mkface f2 s w
+ttranslate f1 $anX -0.001 0
+
+# display objects
+vtop
+vdisplay -dispMode 1 f1 f2
+vsetlocation f2 $anX 0.001 0
+vpoint vl $anX 0 0.001
+vfit
+
+# setup light
+vcaps -ffp 0
+vrenderparams -shadingModel phong
+vlight clear
+vlight add positional pos $anX 0 0.001 color RED1 headLight 0
+
+set aColor1 [vreadpixel 205 180 rgb name]
+set aColor2 [vreadpixel 205 220 rgb name]
+if { "$aColor1" != "RED" || "$aColor2" != "RED" } {
+  puts "Error: expected color near the light spot is RED"
+}
+
+set aColor3 [vreadpixel 205 132 rgb name]
+set aColor4 [vreadpixel 205 280 rgb name]
+if { "$aColor3" != "RED4" || "$aColor4" != "RED4" } {
+  puts "Error: expected color mid from the light spot is RED4"
+}
+
+set aColor5 [vreadpixel 205 100 rgb name]
+set aColor6 [vreadpixel 205 306 rgb name]
+if { "$aColor5" != "RED4" || "$aColor6" != "RED4" } {
+  puts "Error: expected color far from the light spot is RED4"
+}
diff --git a/tests/v3d/glsl/phong_spot1 b/tests/v3d/glsl/phong_spot1
new file mode 100644 (file)
index 0000000..d6c45f2
--- /dev/null
@@ -0,0 +1,45 @@
+puts "========"
+puts "Per-fragment lighting using built-in GLSL program, one spot light source."
+puts "Visual comparison with the reference snapshot should be performed for this test case."
+puts "========"
+
+# create objects
+set anX 0.001
+circle c 0 0 0 0.001
+mkedge e c
+wire   w e
+plane  s
+mkface f1 s w
+mkface f2 s w
+ttranslate f1 $anX -0.001 0
+
+# display objects
+vtop
+vdisplay -dispMode 1 f1 f2
+vsetlocation f2 $anX 0.001 0
+vpoint vl $anX 0 0.001
+vfit
+
+# setup light
+vcaps -ffp 0
+vrenderparams -shadingModel phong
+vlight clear
+vlight add spotLight pos $anX 0 0.001 dir 0 0 -1 angle 60 constAtten 0.1 exponent 0.1 color RED1 headLight 0
+
+set aColor1 [vreadpixel 205 180 rgb name]
+set aColor2 [vreadpixel 205 220 rgb name]
+if { "$aColor1" != "RED" || "$aColor2" != "RED" } {
+  puts "Error: expected color near the light spot is RED"
+}
+
+set aColor3 [vreadpixel 205 132 rgb name]
+set aColor4 [vreadpixel 205 280 rgb name]
+if { "$aColor3" != "RED4" || "$aColor4" != "RED4" } {
+  puts "Error: expected color mid from the light spot is RED4"
+}
+
+set aColor5 [vreadpixel 205 100 rgb name]
+set aColor6 [vreadpixel 205 306 rgb name]
+if { "$aColor5" != "GRAY2" || "$aColor6" != "GRAY2" } {
+  puts "Error: expected color far from the light spot is GRAY2"
+}