My favorites | Sign in
Project Logo
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#extension GL_EXT_gpu_shader4 : enable

uniform int key;
uniform sampler2D _input; //_input texture
uniform sampler2D stateTex;
uniform float dt; //time
uniform vec3 camPos;
uvec4 whiteNoise(in uvec4 _input, in unsigned int key);

vec4 convertToR0_R1(in uvec4 _input);
const float twopi = 6.283185;
const float EXCITERANGE = 20.0;
const float EPSILON = 2.4414e-4;
//This program updates the director texture of GPUEntities.
//we randomly pick a direction.
//Precondition:
//We assume that _input.xy contains the directional vector that we want to update.
//Where x is the e1 axis and y e2 axis.
void main()
{
//gl_TexCoord[0].t = 1.0 - gl_TexCoord[0].t;
vec4 state = texture2D(_input,gl_TexCoord[0].st);
if(state.z > state.w)
{
state.z = 0.0-dt;
//next throw dice to determine whether we want to change
uvec4 coord;
unsigned int uintkey = unsigned int(key);
coord.x = uint(gl_TexCoord[0].x*20000.0);
coord.y = uint(gl_TexCoord[0].y*20000.0);
coord.z = uintkey;
coord.w = uintkey;

uvec4 noise = whiteNoise(coord,uintkey);
vec4 rand = convertToR0_R1(noise);

state.w = rand.w*30.00+1.0; //change sometime in 1 to 5 sec

if(rand.x < rand.y) //do our probability thing
{

rand.z = rand.z*twopi; //theta
state.x = sin(rand.z);
state.y = cos(rand.z);
}

vec3 pos = texture2D(stateTex,gl_TexCoord[0].st).xyz;
vec3 camPosG = camPos;
camPosG.y = 0.0;
vec3 vecToPlayer = camPosG - pos;
float dis = length(vecToPlayer); //distance to player.
camPosG.y = 0.0;
vecToPlayer = camPosG - pos;
vecToPlayer = normalize(vecToPlayer);

if(dis > EPSILON)
dis = min(EXCITERANGE/dis,1.0);
else
dis = 1.0;


state.xy = (1.0-dis)*state.xy+dis*vecToPlayer.xz;

}



state.z += dt;
gl_FragColor = state;
}
Show details Hide details

Change log

r57 by llwijk on Aug 01, 2009   Diff
added preliminar networking.
Go to: 
Project members, sign in to write a code review

Older revisions

r56 by llwijk on Apr 11, 2009   Diff
Fixed a crash because OGL 3
input/ouput are reserved keywords, so
I had to change them in GLSL, but
forgot to reflect this when setting
input material in Ping-Pong shader.
...
r51 by llwijk on Oct 14, 2008   Diff
More work. Imposter renderer is more
complete than last time... :P. Started
working on some shader effects
(lighting etc) for imposters. Right
now the shader code is sort of messy,
...
r50 by llwijk on Oct 10, 2008   Diff
More updates to GPU zombie controller.
All revisions of this file

File info

Size: 1776 bytes, 70 lines
Hosted by Google Code