CreateShader()

Syntax

Result = CreateShader(ShaderID, VertexProgram$, FragmentProgram$)
Description
Creates a new shader using the specified vertex and fragment programs.

Parameters

ShaderID A number between 0 and 65536 to identify the new shader. To select one of the predefined shader, use one of the following values as 'ShaderID' (VertexProgram$ and FragmentProgram$ values will be ignored):
  #PB_Material_ColorShader
  #PB_Material_PerpixelShader
  #PB_Material_BumpShader
  #PB_Material_SkyShader
  #PB_Material_WaterShader
  #PB_Material_WaterShaderRTT
  #PB_Material_OceanShader
  #PB_Material_PointSpriteSphereShader
VertexProgram$ The GLSL program to use for vertices.
FragmentProgram$ The GLSL program to use for fragments.

Return value

Nonzero if the shader was successfully created, zero otherwise.

Remarks

Shaders usually need to receive parameters to work and two functions allow to pass these parameters: MaterialShaderAutoParameter() (automatic parameter) and MaterialShaderParameter() (shader parameter).
PureBasic also allows to set these parameters directly in the shader programs by adding at the end of the 'uniform' declaration line: "//" followed by either:
- the auto parameter number preceded by a "+" (cf. 'ParameterType' constants of the MaterialShaderAutoParameter() function).
- one or more values (separated by a space) corresponding to the shader parameter (MaterialShaderParameter()).

Example:
uniform vec4 camera_pos;//+76 <- automatic parameter #PB_Shader_CameraPosition
uniform vec4 fog_params;//+31 <- automatic parameter #PB_Shader_FogParams
uniform vec3 speed;//0.5 1 0 <- shader parameter 'speed'
uniform sampler2D diffuseMap;//1 <- shader parameter texture number

See Also

CreateShaderMaterial(), MaterialShaderAutoParameter(), MaterialShaderParameter()

Supported OS

All

<- CreateMaterial() - Material Index - CreateShaderMaterial() ->