shader diffuse bumpmapping(Cg): Unterschied zwischen den Versionen

Aus DGL Wiki
Wechseln zu: Navigation, Suche
(Die Seite wurde neu angelegt: =Shadername= Zurück zur Shadersammlung {|{{Prettytable_B1}} width=100% !width=60%|Beschreibung !width=20%|Autor !width=20%|Version |- |Wendet diffuses Bumpmapping ...)
(kein Unterschied)

Version vom 31. Oktober 2008, 16:14 Uhr

Shadername

Zurück zur Shadersammlung

Beschreibung Autor Version
Wendet diffuses Bumpmapping auf eine beliebige Oberfläche an. Igel457 1.0

Bilder

Die Originaltextur...
...und die Normalmap...
ergeben zusammen mit einer Lichtposition ein plastisches Bild.

Beschreibung

kommt noch...

Besondere Vorraussetzungen

kommt noch...

Code

struct fs_res {
  float4 color : COLOR;
};

float3 expand(float3 v)
{
  return (v - 0.5) * 2; // Expand a range-compressed vector
}

fs_res fragment_shader(
  float2 colortexcoords: TEXCOORD0,
  float3 lightdirection: TEXCOORD1,
  float4 color: COLOR,
  uniform sampler2D colormap,
  uniform sampler2D normalmap,
  uniform float  lightintensity,
  uniform float4 ambientcolor  
)
{
  fs_res OUT;
  
  float3 light = expand(lightdirection);
  
  float3 normaltex = tex2D(normalmap, colortexcoords).xyz;
  float3 normal = expand(normaltex);      
  
  OUT.color = (dot(-normal, light) * lightintensity * color + ambientcolor) * tex2D(colormap, colortexcoords);  
  
  return OUT;
}

struct vs_res {
  float4 position : POSITION;
  float4 color    : COLOR;
  float2 colortexcoords: TEXCOORD0;
  float3 lightdirection: TEXCOORD1;
};

vs_res vertex_shader(
  float3 position : POSITION,
  float3 normal : NORMAL,
  float4 color : COLOR,
  float4 colortexcoords : TEXCOORD0,
  uniform float4x4 modelview,
  uniform float3 lightpos,
  uniform float4 lightcolor  
)
{
  vs_res OUT; 
  
  //Transform the vertex position to the world position
  OUT.position = mul(modelview, float4(position, 1));
  
  //Comment this line if you don't want the shader to transform the light position
  //to the world position
  float4 lp = mul(modelview, float4(lightpos, 1));  
 
  //Set the color texture coordinates
  OUT.colortexcoords = colortexcoords;
  //Set the color of the vertex
  OUT.color = color * lightcolor;
  //Stor the light direction in a second texture coordinate vector
  OUT.lightdirection = normalize(position.xyz - lightpos);
  
  return OUT;
}