Patch Structure Reference



 

OVERVIEW:

During rendering the texture's
Work( ) function is passed four arguments, one of which is a pointer to a data structure called patch. This section of the tutorial details the meaning of the variables in the patch structure. This information is also provided in the textures.doc file provided in the Imagine Texture Software Development Kit.

 

patch->ptc_pos.X
patch->ptc_pos.Y
patch->ptc_pos.Z
These are the X, Y, and Z world coordinates of the point where the ray being traced intersected with the object this texture was applied to. You can use this for textures that have variations based on where the object is located in the scene. If you need hit point coordinates that are relative to the texture's axis use the vector argument that is passed to the Work( ) function instead. These values are read only. Modifying these values directly has no effect on the texture, but it's a bad idea to do anyway.
patch->ptc_nor.X
patch->ptc_nor.Y
patch->ptc_nor.Z
This is the surface normal vector at the point that the ray intersected with the object. If this surface has Phong shading, then this normal has already been modified by the Phong algorithm. This tells you which direction the surface is facing at the hit point. You can modify this direction vector to create bump maps. If you do modify this, remember to re-normalize it, make sure (X * X) + (Y * Y) + (Z * Z) = 1.0
patch->ptc_col.r
patch->ptc_col.g
patch->ptc_col.b
These are the Red, Green, and Blue values for the color of the pixel at the point that the ray intersected the object. They are floating point values and must be in the range of 0.0 to 1.0. Modifying these values will change the color of the object at this point.
patch->ptc_ref.r
patch->ptc_ref.g
patch->ptc_ref.b
These are the Red, Green, and Blue values for the reflectivity at this point on the object. They are floating point values and must be in the range of 0.0 to 1.0. Modifying these values will change the color and strength of reflections at this point. Anything reflected at this point will have it's color filtered by these settings.
patch->ptc_tra.r
patch->ptc_tra.g
patch->ptc_tra.b
These are the Red, Green, and Blue values for the transparency at this point on the object. They are floating point values and must be in the range of 0.0 to 1.0. Modifying these values will change the transparency of the object. The color of anything beyond this point on the object will be filtered through these color settings.
patch->ptc_spc.r
patch->ptc_spc.g
patch->ptc_spc.b
These are the Red, Green, and Blue values for the specular color of the pixel at this point if it happens to lay within an area of specular highlight. They are floating point values and must be in the range of 0.0 to 1.0. Modifying these values will change the specular color of the object at this point. This setting works together with the patch->hard value which controls the hardness, or tightness of specular highlights for the object at this point.
patch->sbj_shp You can extract shape information from this value by using this formula:
shape = patch->sbj_shp & 0x07;
Where the result will mean:
0 Object is a perfect sphere.
3 A face on a faceted object.
4 A face on a particle.
5 A ground object.

If the result of patch->sbj_shp & 0x0400 is not zero, then this means the ray has hit a perfect sphere and if it continued, it would hit the sphere again. On perfect sphere objects this tells you whether the ray is entering or exiting the sphere. The value is read only.
patch->sbj_shd This tells the render engine whether this object can cast shadows on itself. In other words, if it has protrusions or concave features. Imagine sets this to non-zero only on perfect spheres. This value is read only.
patch->ptc_c1
patch->ptc_c2
First and second barycentric coordinates. Basically, barycentric coordinates are a coordinate system that is relative to the space a surface (in this case, a triangle) occupies. No matter how large or small the triangle may be in world coordinates, these coordinates have been normalized into a 0.0 to 1.0 range. This coordinate system is useful in graphics for calculating Phong shading because it tells you how far from the edges of the triangle you are. You can use that information to adjust the surface normal and thereby smooth the surface between the edges of the triangle. However, since phong shading is already done for you by the render engine, these numbers are not of much use. You could use these coordinates to make a texture that varies depending on how close a point is to the edge of the object's triangle surfaces. Or you could turn off Phong shading on the object, and use these values to modify the surface normal, and thereby create your own smooth shading algorithm. These values are read only.
The third point of the barycentric coordinates can be calculated by this formula:
c3 = 1.0 - patch->ptc_c1 - patch->ptc_c2

patch->ptc_rayptr->base.X
patch->ptc_rayptr->base.Y
patch->ptc_rayptr->base.Z

patch->ptc_rayptr->unit.X
patch->ptc_rayptr->unit.Y
patch->ptc_rayptr->unit.Z

The base coordinates are the starting point of the ray that hit this object. The unit values are a directional vector that points in the direction that the ray is going in. These values are in world coordinates and are read only.

You can use the ray's directional vector patch->rayptr->unit in combination with the patch->ptc_nor surface normal to create effects like the Fakely texture provided with Imagine. These may also be useful in writing textures for lights.
patch->ptc_raydst This is the distance that the ray has traveled from it's base point to the hit point on the object. This value is in world coordinates and is read only.
patch->foglen This lets you alter the Fog Length for the object. Changing this will only work if the object originally had a Fog Length setting greater than zero.
patch->ptc_shiny This sets the shininess value for the object. See my shininess tutorial for more information on what shininess is in Imagine. This value is in a 0.0 to 1.0 range.
patch->ptc_hard This sets the hardness value for the object. Hardness controls how tight specular reflections will be on the object. This value is in a 0.0 to 1.0 range.
patch->ptc_index This sets the index of refraction for the object. This value should be in a 1.0 to 3.6 range. An index of refraction less than 1.0 will crash the render engine. A value greater than 3.6 may cause unpredictable results and possibly hang the render engine.
patch->ptc_bright This sets the brightness level of the object. This value is in a 0.0 to 1.0 range. The higher this value is the less effect shadows and shading will have on the object. This is not the same as making the object a light source. No light will be cast into the scene by setting this value.
patch->ptc_txdata This is a pointer to an array of 16 bytes. This array is passed from texture to texture during rendering of an object with multiple textures. You can use it to pass information or data to the next texture to be processed for this object. There are no standards established for using this data array. It is most useful if you are planning on creating multiple textures that need to communicate with each other. For example, you could create a bump texture and have it pass bump height information to the next texture to use in mapping different colors to different bump heights. The method of passing this information is decided by you. If the end user has a texture made by someone else that uses this data array it may interfere with how you are passing data. To be safe, instruct users of your textures to place them together in the texture list with no other textures in between.
patch->ptc_rough This sets the roughness value for the object. Roughness randomly alters the surface normal for you. Higher numbers cause more severe alterations. Since this alteration is random there will be no continuity from frame to frame in an animation. Under these conditions the object surface will appear to sparkle or crawl. This value is in a 0.0 to 1.0 range.
patch->ptc_brlite.r
patch->ptc_brlite.g
patch->ptc_brlite.b
These set the color and intensity of ambient light at this point on the object. This is the same concept as using a bitmap for an ambient lighting map in the attributes of an object. Traditionally ambient light maps are used to simulate radiosity (inter-reflection of light between objects). It can also be used to simulate translucent lighting effects like the glow of a candle stick near the flame. These values are in a 0.0 to 1.0 range.

 

Back to the Texture Tutorial Table of Contents



Back to the Tutorials 

 

 

 

 

© 2002 Kazimer Corp.
1010 University Ave. PMB #1862
San Diego, CA 92103-3395