https://public.kitware.com/Wiki/index.php?title=Anisotropic_Lighting_Material&feed=atom&action=historyAnisotropic Lighting Material - Revision history2024-03-28T16:06:29ZRevision history for this page on the wikiMediaWiki 1.38.6https://public.kitware.com/Wiki/index.php?title=Anisotropic_Lighting_Material&diff=8766&oldid=prevAndy at 18:15, 17 April 20072007-04-17T18:15:31Z<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 18:15, 17 April 2007</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Download this file from [[Media:Anisotropic.xml]].</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Download this file from [[Media:Anisotropic.xml]].</div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">{{VTK/Template/Footer}}</ins></div></td></tr>
</table>Andyhttps://public.kitware.com/Wiki/index.php?title=Anisotropic_Lighting_Material&diff=7959&oldid=prevKmorel at 23:56, 5 December 20062006-12-05T23:56:34Z<p></p>
<a href="https://public.kitware.com/Wiki/index.php?title=Anisotropic_Lighting_Material&diff=7959&oldid=7797">Show changes</a>Kmorelhttps://public.kitware.com/Wiki/index.php?title=Anisotropic_Lighting_Material&diff=7797&oldid=prevKmorel at 02:45, 29 November 20062006-11-29T02:45:52Z<p></p>
<p><b>New page</b></p><div>Back to [[VTKShaders]]<br />
<br />
<pre><br />
<?xml version="1.0" encoding="UTF-8"?><br />
<br />
<!--<br />
This is a simple anisotropic shader. The lighting model is taken from<br />
"Efficient Rendering of Anisotropic Surfaces Using Computer Graphics" by<br />
Heidrich and Seidel (who get their shading from "Illumination in Diverse<br />
Codimensions" by Banks who in derived his model from "Rendering Fur With<br />
Three Dimensional Textures" by Kajiya and Kay.<br />
<br />
Copyright 2006 Sandia Corporation.<br />
Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive<br />
license for use of this work by or on behalf of the<br />
U.S. Government. Redistribution and use in source and binary forms, with<br />
or without modification, are permitted provided that this Notice and any<br />
statement of authorship are reproduced on all copies.<br />
--><br />
<br />
<br />
<Material name="Anisotropic"<br />
number_of_properties="1"<br />
number_of_vertex_shaders="1"<br />
number_of_fragment_shaders="1"><br />
<Property name="AnisotropicHighlights"><br />
<Member name="SpecularColor" number_of_elements="3"<br />
type="float" value="1.0 1.0 1.0"/><br />
<Member name="Specular" number_of_elements="1"<br />
type="float" value="1.0"/><br />
<Member name="SpecularPower" number_of_elements="1"<br />
type="float" value="50.0"/><br />
</Property><br />
<br />
<Shader scope="Vertex"<br />
name="AnisotropicVert"<br />
location="Inline"<br />
language="GLSL"<br />
entry="main"><br />
<Uniform name="ScratchAxis" type="float"<br />
number_of_elements="3" value="0.0 0.0 1.0"/><br />
/* This is the vertex program for a simple anisotropic shader. The lighting<br />
* model is taken from "Efficient Rendering of Anisotropic Surfaces Using<br />
* Computer Graphics" by Heidrich and Seidel (who get their shading from<br />
* "Illumination in Diverse Codimensions" by Banks who in derived his model from<br />
* "Rendering Fur With Three Dimensional Textures" by Kajiya and Kay.<br />
*<br />
* This anisotropic lighting model simulates the effect of a material with<br />
* microscopic fibers, scratches, or grooves that are aligned in a particular<br />
* direction. That direction must be known in advanced. Since we usually don't<br />
* have a direction in mind, we just fabricate one here. We do this by taking<br />
* the cross product of the object coordinate with a given vector and projecting<br />
* that onto the tangent plane. This creates fibers that rotate about the<br />
* vector. It is a nice effect for most objects, but creates singularities<br />
* along the vector (where the rotation is of radius 0) and where the surface<br />
* normal happens to be perpendicular to both the object coordinate vector and<br />
* the given vector (which can happen everywhere on the plane containing both<br />
* the given vector and the origin).<br />
*/<br />
<br />
/*<br />
* Copyright 2006 Sandia Corporation.<br />
* Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive<br />
* license for use of this work by or on behalf of the<br />
* U.S. Government. Redistribution and use in source and binary forms, with<br />
* or without modification, are permitted provided that this Notice and any<br />
* statement of authorship are reproduced on all copies.<br />
*/<br />
<br />
varying vec3 Normal;<br />
varying vec3 Tangent;<br />
<br />
uniform vec3 ScratchAxis;<br />
<br />
/* This function projects the vector v onto the plane defined by normal n.<br />
* the magnitude of n should be 1. */<br />
vec3 projectOnPlane(in vec3 v, in vec3 n)<br />
{<br />
return v - dot(n,v)*n;<br />
}<br />
<br />
void main(void)<br />
{<br />
gl_Position = ftransform();<br />
<br />
/* Transform the normal. */<br />
Normal = normalize(gl_NormalMatrix*gl_Normal);<br />
<br />
/* Fabricate a scratch direction. */<br />
vec3 rotationalDirection = cross(gl_Vertex.xyz, ScratchAxis);<br />
rotationalDirection = gl_NormalMatrix*rotationalDirection;<br />
Tangent = normalize(projectOnPlane(rotationalDirection, Normal));<br />
<br />
/* Pass lighting and coloring parameters. */<br />
gl_FrontColor = gl_Color;<br />
gl_BackColor = gl_Color;<br />
gl_TexCoord[0] = gl_MultiTexCoord0;<br />
}<br />
<br />
</Shader><br />
<br />
<Shader scope="Fragment"<br />
name="AnisotropicFrag"<br />
location="Inline"<br />
language="GLSL"<br />
entry="main"><br />
<LightUniform name="NumLights" value="NumberOfLights"/><br />
/* This is the fragment program for a simple anisotropic shader. The lighting<br />
* model is taken from "Efficient Rendering of Anisotropic Surfaces Using<br />
* Computer Graphics" by Heidrich and Seidel (who get their shading from<br />
* "Illumination in Diverse Codimensions" by Banks who in derived his model from<br />
* "Rendering Fur With Three Dimensional Textures" by Kajiya and Kay.<br />
*<br />
* This anisotropic lighting model simulates the effect of a material with<br />
* microscopic fibers, scratches, or grooves that are aligned in a particular<br />
* direction. That direction must be known in advanced. Since we usually don't<br />
* have a direction in mind, we just fabricate one here. We do this by taking<br />
* the cross product of the object coordinate with a given vector and projecting<br />
* that onto the tangent plane. This creates fibers that rotate about the<br />
* vector. It is a nice effect for most objects, but creates singularities<br />
* along the vector (where the rotation is of radius 0) and where the surface<br />
* normal happens to be perpendicular to both the object coordinate vector and<br />
* the given vector (which can happen everywhere on the plane containing both<br />
* the given vector and the origin).<br />
*/<br />
<br />
/*<br />
* Copyright 2006 Sandia Corporation.<br />
* Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive<br />
* license for use of this work by or on behalf of the<br />
* U.S. Government. Redistribution and use in source and binary forms, with<br />
* or without modification, are permitted provided that this Notice and any<br />
* statement of authorship are reproduced on all copies.<br />
*/<br />
<br />
varying vec3 Normal;<br />
varying vec3 Tangent;<br />
<br />
uniform int NumLights;<br />
<br />
/* Compute the contribution from a particular light source. */<br />
void DirectionalLight(in int lightIndex,<br />
in vec3 normal,<br />
in vec3 tangent,<br />
inout vec4 ambient,<br />
inout vec4 diffuse,<br />
inout vec4 specular)<br />
{<br />
vec3 light = normalize(vec3(gl_LightSource[lightIndex].position));<br />
<br />
/**** Compute ambient term. ****/<br />
ambient += gl_LightSource[lightIndex].ambient;<br />
<br />
/**** Compute a "corrective" term for object shelf shadowing. ****/<br />
float cosNL = dot(normal, light);<br />
float shadow = max(0.0, cosNL);<br />
<br />
/**** Compute diffuse term. ****/<br />
float cosLT = dot(tangent, light);<br />
/* This is the cosine of the angle between the light vector and the plane<br />
perpendicular to the tangent vector. */<br />
float cosLNp = sqrt(1.0 - cosLT*cosLT);<br />
diffuse += gl_LightSource[lightIndex].diffuse * shadow*cosLNp;<br />
<br />
/**** Compute specular term. ****/<br />
float cosVT = dot(vec3(0.0, 0.0, -1.0), tangent);<br />
float cosVNp = sqrt(1.0 - cosVT*cosVT);<br />
float cosVR = cosLNp*cosVNp - cosLT*cosVT; /* cos view, reflection. */<br />
cosVR = max(cosVR, 0.0);<br />
specular += ( gl_LightSource[lightIndex].specular<br />
* shadow * pow(cosVR, gl_FrontMaterial.shininess) );<br />
}<br />
<br />
void AllLights(in vec3 normal,<br />
in vec3 tangent,<br />
inout vec4 ambient,<br />
inout vec4 diffuse,<br />
inout vec4 specular)<br />
{<br />
DirectionalLight(0, normal, tangent, ambient, diffuse, specular);<br />
if (NumLights &gt; 1)<br />
{<br />
DirectionalLight(1, normal, tangent, ambient, diffuse, specular);<br />
if (NumLights &gt; 2)<br />
{<br />
DirectionalLight(2, normal, tangent, ambient, diffuse, specular);<br />
if (NumLights &gt; 3)<br />
{<br />
DirectionalLight(3, normal, tangent, ambient, diffuse, specular);<br />
if (NumLights &gt; 4)<br />
{<br />
DirectionalLight(4, normal, tangent, ambient, diffuse, specular);<br />
}<br />
}<br />
}<br />
}<br />
}<br />
<br />
void main(void)<br />
{<br />
/* If lighting the back of a polygon, flip normal.*/<br />
vec3 normal = normalize(Normal);<br />
vec3 tangent = normalize(Tangent);<br />
<br />
/* Compute light contributions. */<br />
vec4 ambient = vec4(0.0);<br />
vec4 diffuse = vec4(0.0);<br />
vec4 specular = vec4(0.0);<br />
AllLights(normal, tangent, ambient, diffuse, specular);<br />
<br />
gl_FragColor = ( ambient*gl_FrontMaterial.ambient<br />
+ diffuse*gl_FrontMaterial.diffuse<br />
+ specular*gl_FrontMaterial.specular);<br />
}<br />
<br />
</Shader><br />
</Material><br />
</pre><br />
<br />
Back to [[VTKShaders]]</div>Kmorel