<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de">
		<id>https://wiki.delphigl.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sharkman</id>
		<title>DGL Wiki - Benutzerbeiträge [de]</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.delphigl.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sharkman"/>
		<link rel="alternate" type="text/html" href="https://wiki.delphigl.com/index.php/Spezial:Beitr%C3%A4ge/Sharkman"/>
		<updated>2026-04-20T22:40:37Z</updated>
		<subtitle>Benutzerbeiträge</subtitle>
		<generator>MediaWiki 1.27.4</generator>

	<entry>
		<id>https://wiki.delphigl.com/index.php?title=shader_PerPixel_Lighting2&amp;diff=25680</id>
		<title>shader PerPixel Lighting2</title>
		<link rel="alternate" type="text/html" href="https://wiki.delphigl.com/index.php?title=shader_PerPixel_Lighting2&amp;diff=25680"/>
				<updated>2012-06-07T12:20:51Z</updated>
		
		<summary type="html">&lt;p&gt;Sharkman: /* Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Per-Pixel-Lighting Shader=&lt;br /&gt;
Zurück zur [[Shadersammlung]]&lt;br /&gt;
{|{{Prettytable_B1}} width=100%&lt;br /&gt;
!width=60%|Beschreibung&lt;br /&gt;
!width=20%|Autor&lt;br /&gt;
!width=20%|Version&lt;br /&gt;
|-&lt;br /&gt;
|Per-Pixel-Lighting Shader&lt;br /&gt;
|Olee&lt;br /&gt;
|1.0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Bilder==&lt;br /&gt;
{|&lt;br /&gt;
|[[Bild:PPLShader.jpg|framed|400px|400px|Beispiel (Es handelt sich hierbei um EIN EINZIGES großes Quad)]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Beschreibung==&lt;br /&gt;
Eine Erweiterung des bestehenden PPL-Shaders aus der [[Shadersammlung]].&lt;br /&gt;
Dabei beachtet dieser im Gegensatz zum bestehenden den Abstand zur Lichtquelle,&lt;br /&gt;
unendlich weit entfernte Lichtquellen (Positionsvektor.W = 0) und&lt;br /&gt;
er behandelt im Anschluss an das Licht noch den Fog.&lt;br /&gt;
&lt;br /&gt;
==Besondere Vorraussetzungen==&lt;br /&gt;
Es muss eine  Textur gebunden sein, sonst ist das ergebnis immer Schwarz aufgrund des Folgenden Codes:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
  vec4 texColor	= gl_Color * texture2D(Texture0, gl_TexCoord[0].xy);	&lt;br /&gt;
  gl_FragColor	= texColor * (gl_FrontLightModelProduct.sceneColor + lightAmbientDiffuse) + lightSpecular;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Entweder man entfernt den eintrag '''*texture2D(Texture0, gl_TexCoord[0].xy)''' oder bindet vorher eine &lt;br /&gt;
weiße-1D-Textur.&lt;br /&gt;
&lt;br /&gt;
Über die uniform-Variable '''ActiveLights''' kann die Anzahl der Lichtquellen angegeben werden, die für die berechnung des Lichtes verwendet werden sollen. Dabei wird von von der Lichtquelle 0 aus hochgezählt.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
Vertexshader:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;glsl&amp;quot;&amp;gt;&lt;br /&gt;
varying vec3 position;&lt;br /&gt;
varying vec3 normal; &lt;br /&gt;
&lt;br /&gt;
void main(void) &lt;br /&gt;
{&lt;br /&gt;
  gl_Position		= gl_ModelViewProjectionMatrix * gl_Vertex;&lt;br /&gt;
  gl_FrontColor		= gl_Color;&lt;br /&gt;
  gl_TexCoord[0]	= gl_MultiTexCoord0; &lt;br /&gt;
  normal		= normalize(gl_NormalMatrix * gl_Normal);&lt;br /&gt;
  position		= vec3(gl_ModelViewMatrix * gl_Vertex);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fragmentshader:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;glsl&amp;quot;&amp;gt;&lt;br /&gt;
uniform sampler2D Texture0;&lt;br /&gt;
uniform int ActiveLights;&lt;br /&gt;
&lt;br /&gt;
varying vec3 position;&lt;br /&gt;
varying vec3 normal; &lt;br /&gt;
&lt;br /&gt;
void main(void) &lt;br /&gt;
{&lt;br /&gt;
  vec3 lightDir;&lt;br /&gt;
  float  attenFactor;&lt;br /&gt;
  vec3 eyeDir 			= normalize(-position); // camera is at (0,0,0) in ModelView space&lt;br /&gt;
  vec4 lightAmbientDiffuse 	= vec4(0.0,0.0,0.0,0.0);&lt;br /&gt;
  vec4 lightSpecular 		= vec4(0.0,0.0,0.0,0.0); 	&lt;br /&gt;
&lt;br /&gt;
  // iterate all lights&lt;br /&gt;
  for (int i=0; i&amp;lt;ActiveLights; ++i)&lt;br /&gt;
  {&lt;br /&gt;
	// attenuation and light direction&lt;br /&gt;
	if (gl_LightSource[i].position.w != 0.0)&lt;br /&gt;
	{&lt;br /&gt;
		// positional light source&lt;br /&gt;
		float dist	= distance(gl_LightSource[i].position.xyz, position);&lt;br /&gt;
		attenFactor	= 1.0/(	gl_LightSource[i].constantAttenuation + &lt;br /&gt;
					gl_LightSource[i].linearAttenuation * dist +&lt;br /&gt;
					gl_LightSource[i].quadraticAttenuation * dist * dist );&lt;br /&gt;
		lightDir	= normalize(gl_LightSource[i].position.xyz - position);&lt;br /&gt;
	}		&lt;br /&gt;
	else &lt;br /&gt;
	{			&lt;br /&gt;
		// directional light source			&lt;br /&gt;
		attenFactor	= 1.0;			&lt;br /&gt;
		lightDir	= gl_LightSource[i].position.xyz;		&lt;br /&gt;
	} 		&lt;br /&gt;
	// ambient + diffuse		&lt;br /&gt;
	lightAmbientDiffuse 	+= gl_FrontLightProduct[i].ambient*attenFactor;		&lt;br /&gt;
	lightAmbientDiffuse 	+= gl_FrontLightProduct[i].diffuse * max(dot(normalize(normal), lightDir), 0.0) * attenFactor; &lt;br /&gt;
	// specular		&lt;br /&gt;
	vec3 r 		= normalize(reflect(-lightDir, normal));&lt;br /&gt;
	lightSpecular 	+= gl_FrontLightProduct[i].specular * &lt;br /&gt;
			      pow(max(dot(r, eyeDir), 0.0), gl_FrontMaterial.shininess) *&lt;br /&gt;
			      attenFactor;	&lt;br /&gt;
  } 	&lt;br /&gt;
  // compute final color	&lt;br /&gt;
  vec4 texColor = gl_Color * texture2D(Texture0, gl_TexCoord[0].xy);	&lt;br /&gt;
  gl_FragColor 	= texColor * (gl_FrontLightModelProduct.sceneColor + lightAmbientDiffuse) + lightSpecular;&lt;br /&gt;
&lt;br /&gt;
  float fog	= (gl_Fog.end - gl_FogFragCoord) * gl_Fog.scale;	// Intensität berechnen &lt;br /&gt;
  fog		= clamp(fog, 0.0, 1.0);  				// Beschneiden &lt;br /&gt;
  gl_FragColor 	= mix(gl_Fog.color, gl_FragColor, fog);  		// Nebelfarbe einmischen &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sharkman</name></author>	</entry>

	</feed>