Texturing Models

This article is about using USES configuration files to apply textures to

models using default vertex and fragment shaders

(./data/shaders/meshShader.vs and ./data/shaders/meshShader.fs).

The code bellow will add a diffuse texture, but the process for adding other types of textures is very similar.


define UV_DIFFUSE_TEXTURE
texture uv_diffuseTexture ./modules/[moduleFolder]/[textureFile.jpg]

{

}
parameter1i uv_diffuseTexOp 0

parameter1f uv_diffuseTexStrength 1.0


  • The define UV_DIFFUSE_TEXTURE macro tells the shaders that you are using a diffuse texture, and the diffuse texture will not work without it.
  • The line texture uv_diffuseTexture /./modules/[moduleFolder]/[textureFile.jpg] specifies the relevant file as the diffuse texture file, and the curly brackets on the following lines are necessary.
  • The line parameter1i uv_diffuseTexOp 0 lets you specify the interaction between the diffuse material color and the texel colors. A value of 0 means that the texel color and the diffuse material color (which is roughly .6 .6 .6 by default) are multiplied together, a value of 1 means they are added together, and a value of 2 means that the texel color is subtracted from the diffuse material color. This value is 0 if unspecified.
  • The line parameter1f uv_diffuseTexStrength 1.0 lets you specify a multiplicitive factor for the outcome of the result of the texture operation.

Ambient, specular and reflection textures can be added in a similar fashion, just with different keywords. That is:

  • UV_AMBIENT_TEXTURE, UV_SPECULAR_TEXTURE, or UV_REFLECTION_TEXTURE replaces UV_DIFFUSE_TEXTURE.
  • uv_ambientTexture, uv_specularTexture, or uv_reflectionTexture replaces uv_diffuseTexture.
  • uv_ambientTexOp, uv_specularTexOp or uv_reflectionTexOp replaces uv_diffuseTexOp.
  • uv_ambientTexStrength, uv_specularTexStrength, or uv_reflectionTexStrength replaces uv_diffuseTexStrength.

You can also add a normal texture to a model. The normal texture does not take a strength or operation, so the keywords are UV_NORMAL_TEXTURE and uv_normalTexture.

Beginner

¿Le resulta útil este artículo?