!!ARBvp1.0 # (fairly) generic file for 4D texture coordinates # x,y and z come from position # w comes from vertex.color.r (1/2 key controls in noise test app) # all four undergo a global scale based on vertex.color.g (3/4 keys) # z is scaled by 61 to put it in the same scale as x/y -- might more # logically go in the noise shader; minor optimization to do it here # w is scaled by 61/4 -- 61 for the same reasons as z; 1/4 to allow # change over a few octaves. # # overall external key controls (each in a decrement/increment pair): # 1/2: vertex.color.r: 4D noise w # 3/4: vertex.color.g: noise scale # 5/6: vertex.color.b: free # 7/8: vertex.color.b: free # all are passed to shader in the attribute 'frame' = result.texcoord[1] PARAM nscale = {.2,.2,12.2,100}; # .2*(1,1,61) static scale factor 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 noiseInput = result.texcoord[1]; # input to noise function # 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; # noise input: xyz from position, w from color.r, scale from color.g TEMP ni; MAD ni.x,vertex.color.y,-2,-1; # scale 2^-1 to 2^-3 (1/2 to 1/8) EX2 ni.x,ni.x; MUL ni,ni.x,nscale; # combine with static scaling MUL noiseInput.xyz, ni, vertex.position; # xyz from position MUL noiseInput.w, ni, vertex.color.x; # w from red END