| Helpdesk | Real 3D | Main area |
What I am going to discuss here are several uses of the same thing. All are based on a very simple RPL program, and can produce the following effects:
: SHA1GET R FETCH iSha1R STORE G FETCH iSha1G STORE B FETCH iSha1B STORE ; : SHA1SET iSha1R FETCH R FETCH * 255 / R STORE iSha1G FETCH G FETCH * 255 / G STORE iSha1B FETCH B FETCH * 255 / B STORE ;
Also we need to do some additions to the startup.rpl file. Open the file in a texteditor and scroll down (not far) until you find a line that says something like this: 'VARIABLE iTOG_PARPER 0 iTOG_PARPER STORE' and just above it, enter the following:
VARIABLE iSha1R VARIABLE iSha1G VARIABLE iSha1B
Now, start Real 3D and the new variables defined in the startup.rpl can now be used as a temporary holding place for a color. Open the material editor and make a material called getcolor with an appropriate texturemap defining the color. click on the find field to define the handler program and select shadowmap1.rpl file you just created. Switch the color handler to RPL and type in SHA1GET in the expression field. Set the effect to 1 and hit apply. Create a second material by renaming this one to setcol. Select an appropriate shadowmap (greyscale works best, but using colormaps can give some nice effects), i.e. the panels texture. Change the color expression field to SHA1SET, set the effect slider to max and hit apply. Create some objects and map them with the materials you just defined, and, voila.
Some explanations may be appropriate at this point. When we call the SHA1GET word in the first material, it copies the red, green, and blue components of the texturemap into some variables. Since the effect is set to 1 the effect of this colormap when mapped onto some objects is so small that it is not of any notice. A value of 0 would trigger Real 3D to skip the entire definition and nothing would have happened. Increasing the value would increase the blending, which we are trying to avoid. When we call the SHA1SET word in the second material, it fetches the values from the variables and from the components in the shadowmap texture and multiplies them. It then divides the answer by 255 resulting in a range from 0 to 255 which off course is what we want. The end result is that the colormap is 'filtered' through the shadowmap (meaning that if the shadowmap is red, only the red colors of the colormap is shown). So if the shadowmap is a grey image, the color would have its brightness controlled by it. As this method works with colorized shadowmaps, it is a bit more flexible than the usual diffusion map used around, as these are normally based on greyscale images. Below is a couple of images describing the effect of shadowmapping/diffusionmapping.
Examples of color and shadow mapping combined |
||
|---|---|---|
|
|
|
| Fig. 1. The very simple basic model | Fig. 2. Textured with a colormap | Fig. 3. Filtered though a shadowmap |
|
|
|
| Fig. 4. Shadowmap control the specularity | Fig. 5. Redefine reflected to white | Fig. 6. Shadowmap used as bumpmap also |
In case you didn't notice, this is an extremely powerful method of adding detail to a very simple object. This polyhedron anded together with a simple ellipsoid kinda looks like a spaceshit. Okay, it isn't that good, but you get the picture.


: SPB1GET br FFETCH fSpeBr1 FSTORE 0.0 br FSTORE ; : SPB1SET fSpeBr1 FFETCH sb FSTORE ;
This will of course require that you define the fSpeBr1 variable somewhere in the startup.r3d file by writing 'FVARIABLE fSpeBr1' close to the others you wrote before. Also, we use brilliance map to define the specular brightness, so set the brilliance toggle in the getcolor material. Set Scope handler to RPL, and enter 'SPB1GET' in the expression field. Switch to the setcolor material, set Scope handler to RPL and enter 'SPB1SET' in the expression field. What happens is that the blue component (if my memory serves me correct, it might be the green one?) of the colormap also defines the specular brightness.
Now it is time to change one of the lines, just to give you an idea of how to scale the effect. The following requires that the colorcomponent is represented in full (giving galues from 0 to 255). Locate the line that says 'br FFETCH fSpeBr1 FSTORE' in the program and replace it with one of the following:
100.0 br FFETCH F- fSpeBr1 FSTORE ( inverts the specular effect sb FFETCH br FFETCH F+ fSpeBr1 FSTORE ( add to normal spec. br. br FFETCH 0.5 F* fSpeBr1 FSTORE ( rescales, new is 0 to 128 br FFETCH 0.25 F* 50.0 F+ fSpeBr1 FSTORE ( rescales, new is 50 to 114 100.0 br FFETCH 0.25 F* 50.0 F+ F- fSpeBr1 FSTORE ( inverts, rescales, new is 114 to 50
And so on, and so on... As you can see, the possibilities are limited only by the imagination, and the rendertime available :-).
Remember that white gives no effect where as black give a total shadow, so the image should contain 'full white' where there are no shadows, and grey to black where there are supposed to be shadows. Below is a picture I made using this technique, but also notice how the colored spots in the shadowmap controls the output of the colormap. For a full sized (1024*768) version, check out the Real 3D ftp-site. There should be a file in the images dir called ShadowMapExample.jpg. I try to keep things small (320*240) here. Even though this way of making shadows takes longer time to render than no shadows at all, this is a lot faster than if I was to render with a rectangular (area) light that cast shadows with a lightsamples value of about 4.
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
| Helpdesk | Real 3D | Main area |