@willmotil wrote:
So some guy posted not to long ago he was doing the game of life.
I thought about how to doing this with a shader and gave it a go.
Basically i just drew from a rendertarget to rendertarget with preservecontents on, so from 1 to 2. Then 2 to 1 and so on each frame. Drawing the results to the screen to see it depending on which rendertarget was in rotations that frame.
.
I started playing around with the rules and came up with something really neat that i wanted to share because it looks so cool.I give you i dunno Circuitry ?. the shader is below if you would like to play around with it.
![]()
#if OPENGL #define SV_POSITION POSITION #define VS_SHADERMODEL vs_3_0 #define PS_SHADERMODEL ps_3_0 #else //#define VS_SHADERMODEL vs_3_0_level_9_1 //#define PS_SHADERMODEL ps_3_0_level_9_1 //#define VS_SHADERMODEL vs_3_0_level_10_0 //#define PS_SHADERMODEL ps_3_0_level_10_0 #define VS_SHADERMODEL vs_4_0 #define PS_SHADERMODEL ps_4_0 //#define VS_SHADERMODEL vs_4_0_level_9_1 //#define PS_SHADERMODEL ps_4_0_level_9_1 #endif //_______________________________________________________________ // common //_______________________________________________________________ float4x4 gworld; //float4x4 gworldviewprojection; Texture2D TextureA; sampler2D TextureSamplerA = sampler_state { Texture = <TextureA>; //AddressU = Wrap; //AddressV = Wrap; //MinFilter = Anisotropic; //MagFilter = Anisotropic; //MipFilter = Point; }; struct VertexShaderInputScreenQuadRtGameOfLife { float4 Position : POSITION0; float3 Normal : NORMAL0; float4 Color : COLOR0; float2 TexureCoordinateA : TEXCOORD0; }; struct VertexShaderOutputScreenQuadRtGameOfLife { float4 Position : SV_Position; //float3 Normal : TEXCOORD1;// removed cause it didn't work NORMAL0; float4 Color : COLOR0; float2 TexureCoordinateA : TEXCOORD0; }; struct PixelShaderOutputScreenQuadRtGameOfLife { float4 Color : COLOR0; }; VertexShaderOutputScreenQuadRtGameOfLife VertexShaderScreenQuadDrawRtGameOfLife(VertexShaderInputScreenQuadRtGameOfLife input) { VertexShaderOutputScreenQuadRtGameOfLife output; output.Position = mul(input.Position, gworld); // basically matrix identity output.TexureCoordinateA = input.TexureCoordinateA; output.Color = input.Color; return output; } // aiming for a crystal latice, we remove the rule it cant grow and make it grow. PixelShaderOutputScreenQuadRtGameOfLife PixelShaderScreenQuadDrawRtGameOfLife(VertexShaderOutputScreenQuadRtGameOfLife input) { PixelShaderOutputScreenQuadRtGameOfLife output; float texeldist = .002; float4 col = tex2D(TextureSamplerA, input.TexureCoordinateA); float4 col_right = tex2D(TextureSamplerA, input.TexureCoordinateA + float2(texeldist, .0f)); float4 col_left = tex2D(TextureSamplerA, input.TexureCoordinateA + float2(-texeldist, .0f)); float4 col_up = tex2D(TextureSamplerA, input.TexureCoordinateA + float2(.0f, -texeldist)); float4 col_down = tex2D(TextureSamplerA, input.TexureCoordinateA + float2(.0f, texeldist)); float ncount = 0; if (col_right.x > .1) { ncount += 1.0; } if (col_left.x > .1) { ncount += 1.0; } if (col_up.x > .1) { ncount += 1.0; } if (col_down.x > .1) { ncount += 1.0; } if (ncount > 0) { col.x += ncount * .01; } //if (col.x > .1) // the whole to the -1th //if (col.x > .09) // 10 to the -second 10 *.01 // if (col.x > .13416) // a value derived from the golden mean and the absolute ramajan value { if (ncount == 2 || ncount == 3) { // Only if its neighbour is equal to two or three days. it will survive into the next generation; //col.x += .07; // lets use primes *.01 7 is the closest to the 1.61 value we desire col.x += .03; // use prime 3 *.01 } else { // if it is less than two, then it would die of loneliness if more than three, it will be dead because of crowding. //col.x -= .07; // lets use primes *.01 7 is the closest to the 1.61 value we desire col.x -= .07; // use primes *.01 } } else { // if you had not a cell, but it has three neighbors, will breed a new cell. if (ncount == 3) { //col.x += .1449; // .09 * 1.61 // based on the golden ratio col.x += .12; // 12 * .01 } } output.Color = saturate(col); output.Color.w = 1.0; return output; } technique ScreenQuadDrawRtGameOfLife { pass { VertexShader = compile VS_SHADERMODEL VertexShaderScreenQuadDrawRtGameOfLife(); PixelShader = compile PS_SHADERMODEL PixelShaderScreenQuadDrawRtGameOfLife(); } }
Posts: 1
Participants: 1