!!ARBvp1.0 # vertex shader for 4-octave 3D turbulence PARAM nscale = .05; # overall scale PARAM oscale = {61,122,244,488}; # 61 (noise size) * {1,2,4,8} (octave scales) PARAM L = {-.577,.577,.577,0}; # light position PARAM Kd = {.9,.7,.5,0}; # diffuse color PARAM Ka = {.1,.14,.18,1}; # ambient color # inputs and outputs ATTRIB Vm = vertex.position; # position in model space ATTRIB Nm = vertex.normal; # normal in model space OUTPUT Vp = result.position; # position in projection space OUTPUT frame = result.texcoord[0]; # user input OUTPUT noiseInput1 = result.texcoord[1]; # 1st octave coordinate (scale=1) OUTPUT noiseInput2 = result.texcoord[2]; # 2nd octave coordinate (scale=2) OUTPUT noiseInput4 = result.texcoord[3]; # 3rd octave coordinate (scale=4) OUTPUT noiseInput8 = result.texcoord[4]; # 4th octave coordinate (scale=8) OUTPUT noiseInputZ = result.texcoord[5]; # z for octaves 1-4 # arbitrary user control MOV frame, vertex.color; # Transform the model-space vertex by the model to projection matrix DP4 Vp.x, state.matrix.mvp.row[0], Vm; DP4 Vp.y, state.matrix.mvp.row[1], Vm; DP4 Vp.z, state.matrix.mvp.row[2], Vm; DP4 Vp.w, state.matrix.mvp.row[3], Vm; # Transform the normal to view space TEMP N; DP3 N.x,state.matrix.modelview.invtrans.row[0],Nm; DP3 N.y,state.matrix.modelview.invtrans.row[1],Nm; DP3 N.z,state.matrix.modelview.invtrans.row[2],Nm; # compute per-vertex diffuse shading TEMP Nn,diff; DP3 Nn.w,N,N; RSQ Nn.w,Nn.w; MUL Nn,N,Nn.w; DP3 diff.x,Nn,L; MAX diff.x,diff.x,0; MAD result.color, diff.x, Kd, Ka; # pass through the noise inputs TEMP ni; MUL ni, vertex.position, nscale; MUL noiseInputZ, ni.z, oscale; MUL noiseInput1, ni, 1; MUL noiseInput2, ni, 2; MUL noiseInput4, ni, 4; MUL noiseInput8, ni, 8; END