WorldAssetShader ( asset )
Parameters
| asset - a ready shader asset handle returned by FindWorldAsset |
Description
|
Returns an ordinary shader handle from a ready shader asset. The result behaves exactly like a LoadShader handle: attach it to entities or cameras and drive its parameters as usual. The shader's source and dependencies were prepared on the background worker, with only the final pipeline creation happening on the main thread - so a preload manifest can warm up your game's shaders without a mid-game compile hitch. The returned handle is yours: it stays valid after the source world is freed, and you must release it with FreeShader when you are done. The asset handle itself dies with its world. The asset must be a shader and must be ready, or the call is a runtime error - check WorldAssetReady first for streaming or manual assets. For the full story, see the Async World Loading guide. Requires Extended mode. See also: FindWorldAsset, WorldAssetReady, WorldAssetTexture, WorldAssetSound, LoadShader, FreeShader. |
Example
; WorldAssetShader Example ; ------------------------ ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,1,-5 light=CreateLight() RotateEntity light,45,45,0 ; The crate that will receive the shader crate=CreateCube() PositionEntity crate,0,1,0 EntityColor crate,80,170,255 ; Load the asset manifest world in the background manifest=LoadWorldAsync("../../../samples/worlds/asset-preload.world") While Not WorldReady(manifest) If WorldLoadState(manifest)=WORLD_LOAD_FAILED Then RuntimeError WorldLoadError(manifest) Cls Text 0,0,"Loading the asset manifest..." Flip Wend ; The shader asset uses manual loading policy: resolving the handle ; starts preparing its packaged bytecode in the background shader_asset=FindWorldAsset(manifest,"display-shader") shader=0 While Not KeyDown(1) error$=WorldAssetError(shader_asset) ; Once ready, WorldAssetShader returns an ordinary shader reference If shader=0 And WorldAssetReady(shader_asset) shader=WorldAssetShader(shader_asset) EntityShader crate,shader EndIf TurnEntity crate,0,1,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 Text 0,0,"Arrow keys: move camera Esc: exit" If shader Text 0,20,"WorldAssetShader applied the 'World Asset Tint' shader to the crate" ElseIf error<>"" ; The packaged release ships the shader bytecode beside the manifest Text 0,20,"The shader asset could not be prepared:" Text 0,40,Mid(error,1,70) Text 0,60,Mid(error,71,70) Else Text 0,20,"Preparing the shader asset..." EndIf Flip Wend FreeWorld manifest If shader Then FreeShader shader End
Index