PDA

View Full Version : turn off Gouraud shading?



hcrisp
02-08-2012, 12:52 PM
The documentation says you can turn off Gouraud shading for SHADE_SURF calls, but I can't get it to work. Here is the documentation excerpt:



SET_SHADING Procedure: Modifies the light source shading parameters affecting the output of SHADE_SURF and POLYSHADE.

Keywords
Gouraud -- Controls the method of shading the surface polygons of the POLYSHADE procedure:
- If set to nonzero (the default), the Gouraud shading method is used.
- Otherwise, each polygon is shaded with a constant intensity.
Gouraud shading interpolates intensities from each vertex along each edge. Then, when scan converting the polygons, the shading is interpolated along each scan line from the edge intensities. Gouraud shading is slower than constant shading, but usually results in a more realistic appearance.


The documentation example for POLYSHADE works, but the following example with SHADE_SURF doesn't work. Can someone show me the correct syntax? Or is it a bug?



SET_SHADING, Gouraud=0
SHADE_SURF, DIST(10)

allan
02-15-2012, 04:35 PM
The SET_SHADING Gouraud keyword does not affect SHADE_SURF,
and the documentation does not claim that it does. It claims only to
effect POLYSHADE; this will be made more explicit in a future release.

Below is a workaround:

a = dist(10)
poly_surf, a, v, p, n
surface, a, /nodata, /save
set_shading, gouraud=0
tv, polyshade(v,p,/t3d)
axis, xaxis=0, /t3d, /noerase, charsize=1.5
axis, yaxis=0, /t3d, /noerase, charsize=1.5
axis, zaxis=2, /t3d, /noerase, charsize=1.5

hcrisp
02-16-2012, 12:10 PM
Thank you, that is very helpful.

Any suggestion for how to code a work-around for this implementation of SHADE_SURF?



z = dist(10,10)
x = replv(findgen(10), [10,10], 0)
y = replv(findgen(10), [10,10], 1)
shades = bindgen(10,10) * 2
shade_surf, z, x, y, shades=shades

allan
02-16-2012, 03:18 PM
you are welcome,
and please find below an example related to your latest question,
where the surface is shaded according to height;

a = dist(10)
poly_surf, a, v, p, n
i = (reform(p,5,n))(1:*,*) ; (4,n) index array into v(2,*)
z = avg( (v(2,*))(i), 0 ) ; average height of each polygon
s = interpol( [64,192], [min(z,m=m),m], z )
surface, a, /nodata, /save
set_shading, gouraud=0
tv, polyshade(v,p,/t3d,poly_shades=s)
axis, xaxis=0, /t3d, /noerase, charsize=1.5
axis, yaxis=0, /t3d, /noerase, charsize=1.5
axis, zaxis=2, /t3d, /noerase, charsize=1.5

hcrisp
02-16-2012, 04:43 PM
I am using your examples and getting closer. However, when it hits the POLYSHADE line, it gives this error:



POLYSHADE: Vertex 30: X,Y out of range.


Why is this happening? Earlier runs work, but later ones do not. Is there some system or common variable being modified that I need to pay attention to?

allan
02-16-2012, 06:26 PM
weird, what is your platform and version of wave?
i just put my last example in a file a.pro and then did
@a
thirty or forty times with incident . . .

allan
02-16-2012, 09:37 PM
then i copied a.pro to b.pro, changed the size of the dist(),
and repeatedly did
@a
@b
@a
@b
.
.
.
again without incident;

what i have not tried is using x and y vectors
in the surface call used to set-up the coordinate system;
are you doing this?

if so, the vertices returned from poly_surf will need to be
scaled and/or translated from the canonical index coordinates defined by z
into coordinates that match those defined by x and y;

allan
02-17-2012, 08:25 PM
ok, below is an example for a general case, where x and y vectors are used,
and where these vectors have different lengths and have random spacing;

a different 'warped dist' will appear each time the code is run, but in each case,
the surface is light-source-shaded in an intensity which varies with height;

m = 17
n = 19
x = 2*randomu(s,m) - 1
y = 2*randomu(s,n) - 1
x = x(sort(x))
y = y(sort(y))
z = dist(m,n)
poly_surf, z, v, p, q
v(0,*) = interpol( x, findgen(m), v(0,*) )
v(1,*) = interpol( y, findgen(n), v(1,*) )
i = (reform(p,5,q))(1:*,*)
h = avg( (v(2,*))(i), 0 )
c = interpol( [64,192], [min(h,m=m),m], h )
surface, z, x, y, /nodata, /save
set_shading, gouraud=0
tv, polyshade(v,p,/t3d,poly_shades=c)
axis, xaxis=0, /t3d, /noerase, charsize=1.5
axis, yaxis=0, /t3d, /noerase, charsize=1.5
axis, zaxis=2, /t3d, /noerase, charsize=1.5

hcrisp
02-29-2012, 11:27 AM
Allan,

I am using PV-WAVE 9.50c with 32-bit Win XP. I don't have a problem running your code from a fresh PV-WAVE prompt. But the same code run inside my application (which sizes the new window, modifies !P, draws the axes, load color table, etc.) gives the error mentioned earlier:



POLYSHADE: Vertex 30: X,Y out of range.


I checked to see if maybe it was in how the !P.T or !P.T3D were set up, but !P.T is the indentity matrix and !P.T3D is set to 0. Can you give any insight into why this might be happening? I don't even understand the error message. The data is fine, I would imagine, because I can save the x,y,z variables using SAVE and RESTORE them in a fresh session, and it does not error. Could it be due to clipping, or some other device-level processing?

hcrisp
02-29-2012, 11:56 AM
I think I found the source. If you alter the !Z.RANGE array, it will reproduce this error. Here is the before and after:



; this works:
pm, !z.range
; 0.00000000
; 0.00000000

; this errors:
pm, !z.range
; 0.00000000
; 0.20000000


Is this expected behavior? Is there any work-around?