https://wiki.delphigl.com/index.php?title=shader_game_of_life&feed=atom&action=history
shader game of life - Versionsgeschichte
2024-03-29T05:45:53Z
Versionsgeschichte dieser Seite in DGL Wiki
MediaWiki 1.27.4
https://wiki.delphigl.com/index.php?title=shader_game_of_life&diff=24285&oldid=prev
Dj3hut1 am 3. November 2009 um 20:28 Uhr
2009-11-03T20:28:27Z
<p></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr style='vertical-align: top;' lang='de'>
<td colspan='2' style="background-color: white; color:black; text-align: center;">← Nächstältere Version</td>
<td colspan='2' style="background-color: white; color:black; text-align: center;">Version vom 3. November 2009, 20:28 Uhr</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l92" >Zeile 92:</td>
<td colspan="2" class="diff-lineno">Zeile 92:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>== Demo ==</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>== Demo ==</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[http://algoria.de/opengl/demos/life.jnlp Demo] ''(mit Quellen)''</div></td><td class='diff-marker'>+</td><td style="color:black; 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>[http://algoria.de/opengl/demos/life.jnlp <ins class="diffchange diffchange-inline">Java </ins>Demo] ''(mit Quellen)''</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; 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> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; 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 class="diffchange diffchange-inline">[http://algoria.de/demos/life.html WebGL Demo]</ins></div></td></tr>
</table>
Dj3hut1
https://wiki.delphigl.com/index.php?title=shader_game_of_life&diff=23207&oldid=prev
Dj3hut1: /* Code */ Link auf Demo
2009-03-29T20:44:13Z
<p><span dir="auto"><span class="autocomment">Code: </span> Link auf Demo</span></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr style='vertical-align: top;' lang='de'>
<td colspan='2' style="background-color: white; color:black; text-align: center;">← Nächstältere Version</td>
<td colspan='2' style="background-color: white; color:black; text-align: center;">Version vom 29. März 2009, 20:44 Uhr</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l69" >Zeile 69:</td>
<td colspan="2" class="diff-lineno">Zeile 69:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>     //Nachbarn berechnen</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>     //Nachbarn berechnen</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>     if ( x > <del class="diffchange diffchange-inline">0 </del>&& y > <del class="diffchange diffchange-inline">0 </del>) neighbours += lookup( x - 1, y - 1 );</div></td><td class='diff-marker'>+</td><td style="color:black; 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>     if ( x > <ins class="diffchange diffchange-inline">1 </ins>&& y > <ins class="diffchange diffchange-inline">1 </ins>) neighbours += lookup( x - 1, y - 1 );</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>     if ( y > <del class="diffchange diffchange-inline">0 </del>) neighbours += lookup( x, y - 1 );</div></td><td class='diff-marker'>+</td><td style="color:black; 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>     if ( y > <ins class="diffchange diffchange-inline">1 </ins>) neighbours += lookup( x, y - 1 );</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>     if ( x < SIZE - 1 && y > <del class="diffchange diffchange-inline">0 </del>) neighbours += lookup( x + 1, y - 1 );</div></td><td class='diff-marker'>+</td><td style="color:black; 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>     if ( x < SIZE - 1 && y > <ins class="diffchange diffchange-inline">1 </ins>) neighbours += lookup( x + 1, y - 1 );</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>     if ( x > <del class="diffchange diffchange-inline">0 </del>) neighbours += lookup( x - 1, y );</div></td><td class='diff-marker'>+</td><td style="color:black; 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>     if ( x > <ins class="diffchange diffchange-inline">1 </ins>) neighbours += lookup( x - 1, y );</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>     if ( x < SIZE - 1 ) neighbours += lookup( x + 1, y );</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>     if ( x < SIZE - 1 ) neighbours += lookup( x + 1, y );</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>     if ( x > <del class="diffchange diffchange-inline">0 </del>&& y < SIZE - 1 ) neighbours += lookup( x - 1, y + 1 );</div></td><td class='diff-marker'>+</td><td style="color:black; 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>     if ( x > <ins class="diffchange diffchange-inline">1 </ins>&& y < SIZE - 1 ) neighbours += lookup( x - 1, y + 1 );</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>     if ( y < SIZE - 1 ) neighbours += lookup( x, y + 1 );</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>     if ( y < SIZE - 1 ) neighbours += lookup( x, y + 1 );</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>     if ( x < SIZE - 1 && y < SIZE - 1 ) neighbours += lookup( x + 1, y + 1 );</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>     if ( x < SIZE - 1 && y < SIZE - 1 ) neighbours += lookup( x + 1, y + 1 );</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l89" >Zeile 89:</td>
<td colspan="2" class="diff-lineno">Zeile 89:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>     }</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>     }</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>}</source></div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>}</source></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; 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"> </td><td class='diff-marker'>+</td><td style="color:black; 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;">== Demo ==</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; 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"> </td><td class='diff-marker'>+</td><td style="color:black; 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;">[http://algoria.de/opengl/demos/life.jnlp Demo] ''(mit Quellen)''</ins></div></td></tr>
</table>
Dj3hut1
https://wiki.delphigl.com/index.php?title=shader_game_of_life&diff=23201&oldid=prev
Dj3hut1: Erstellung
2009-03-27T21:43:37Z
<p>Erstellung</p>
<p><b>Neue Seite</b></p><div>=Game of Life=<br />
Zurück zur [[Shadersammlung]]<br />
{|{{Prettytable_B1}} width=100%<br />
!width=60%|Beschreibung<br />
!width=20%|Autor<br />
!width=20%|Version<br />
|-<br />
|Simuliert das altbekannte Game Of Life.<br />
|dj3hut1<br />
|1.0<br />
|}<br />
<br />
==Bilder==<br />
{|<br />
|[[Bild:Game_of_life.png|framed|Szene aus 'Game of Life'.]]<br />
|}<br />
<br />
==Beschreibung==<br />
Ein Fragmentshader wird dazu benutzt, um das 'Game of Life' zu simulieren.<br />
<br />
Dazu wird zuerst eine Textur erstellt, die zufällig 'lebende'( weiß ) oder 'tote' ( schwarz ) Zellen enthält.<br />
Diese Textur repräsentiert die Anfangspopulation.<br />
<br />
In jedem ( Render- )schritt wird die nachfolgende Population berechnet.<br />
Abhängig davon, wieviel tote oder lebendige Nachbarzellen eine Zelle hat, wird entschieden ob die Zelle 'stirbt', am Leben bleibt oder eine neue Zelle geboren wird.<br />
<br />
Hat eine lebende Zelle 2 oder 3 Nachbarn überlebt sie, hat sie weniger als 2 verhungert sie, hat sie mehr als 3 stirbt sie wegen Überbevölkerung.<br />
<br />
Wenn eine leere Zelle von 3 lebendigen Zellen umgeben ist, wird dort eine neue Zelle 'geboren'.<br />
<br />
In jedem Renderschritt wird nun also die Textur an den Fragmentshader übergeben ( gezeichnet auf einem Quad ) und dort wird dann die nächste Generation berechnet und auf den Bildschirm geschrieben ( mit [[glFinish]] ).<br />
Mittels [[glCopyTexImage2D]] können die Daten wieder in die Textur geschrieben werden.<br />
<br />
==Besondere Vorraussetzungen==<br />
OpenGL 2.0.<br />
<br />
==Code==<br />
Vertexshader<br />
<source lang="glsl">void main()<br />
{<br />
gl_TexCoord[0] = gl_MultiTexCoord0;<br />
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;<br />
}</source><br />
<br />
Fragmentshader<br />
<source lang="glsl">uniform sampler2D Texture0;<br />
<br />
float SIZE = 64.0;<br />
<br />
int lookup( in float x, in float y )<br />
{<br />
vec2 tc;<br />
tc.x = x/SIZE;<br />
tc.y = y/SIZE;<br />
<br />
vec4 col = texture2D(Texture0, tc);<br />
<br />
if ( col.r == 1.0 )<br />
return 1;<br />
<br />
return 0;<br />
}<br />
<br />
void main()<br />
{<br />
float x = gl_FragCoord.x;<br />
float y = gl_FragCoord.y;<br />
int neighbours = 0;<br />
<br />
//Nachbarn berechnen<br />
if ( x > 0 && y > 0 ) neighbours += lookup( x - 1, y - 1 );<br />
if ( y > 0 ) neighbours += lookup( x, y - 1 );<br />
if ( x < SIZE - 1 && y > 0 ) neighbours += lookup( x + 1, y - 1 );<br />
if ( x > 0 ) neighbours += lookup( x - 1, y );<br />
if ( x < SIZE - 1 ) neighbours += lookup( x + 1, y );<br />
if ( x > 0 && y < SIZE - 1 ) neighbours += lookup( x - 1, y + 1 );<br />
if ( y < SIZE - 1 ) neighbours += lookup( x, y + 1 );<br />
if ( x < SIZE - 1 && y < SIZE - 1 ) neighbours += lookup( x + 1, y + 1 );<br />
<br />
//eigener Zustand<br />
int self = lookup( x, y );<br />
<br />
gl_FragColor = vec4(0);<br />
<br />
//hier wird entschieden, ob die Zelle lebt<br />
if ( neighbours == 3 || ( neighbours == 2 && self == 1 ) )<br />
{<br />
gl_FragColor = vec4(1);<br />
}<br />
}</source></div>
Dj3hut1