ShaderVector shader,parameter$,x#[,y#][,z#][,w#]
Parameters
|
shader - shader handle parameter$ - name of a vector parameter declared by the shader asset x# - first component y#, z#, w# (optional) - remaining components; 0 (default) |
Description
|
Sets a named vector parameter of a shader. Vectors carry directions, positions and multi-value settings: the wind direction of builtin:foliage, the snow direction of builtin:snow, the screen-space light source of builtin:light-shafts. Components you leave out are set to 0, so a plain 3D direction only needs x, y and z. Names are matched without regard to case and the value affects only this instance. The asset must declare the name as a vector; a missing name or wrong-type setter raises a runtime error. For colours, prefer ShaderColor and its familiar 0-255 components. For the full story, see named parameters in the shader guide. Requires Extended mode. See also: ShaderFloat, ShaderInt, ShaderColor, ShaderTexture, LoadShader. |
Example
; ShaderVector Example ; -------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,0,-5 light=CreateLight() RotateEntity light,35,-30,0 cube=CreateCube() ; The shader displaces vertices by its Offset vector parameter shader=LoadShader("assets/help_surface.b3shader") EntityShader cube,shader amplitude#=0.75 While Not KeyDown(1) ; Press [ / ] to change the slide amplitude If KeyDown(26) And amplitude>0 Then amplitude=amplitude-0.01 If KeyDown(27) And amplitude<1.5 Then amplitude=amplitude+0.01 ; Slide the cube sideways purely inside the vertex shader offset_x#=Sin(MilliSecs()*0.1)*amplitude ShaderVector shader,"Offset",offset_x,0,0,0 TurnEntity cube,0.2,0.4,0 ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Color 255,255,255 Text 0,0,"[ / ] : amplitude Arrow keys: move camera Esc: exit" Text 0,20,"ShaderVector shader,"+Chr$(34)+"Offset"+Chr$(34)+","+offset_x+",0,0,0" Flip Wend FreeShader shader End
Index