;-
;vividgl lite free shader skins.
;
;Havn't had an whole lot of time to
;spend writing shaders, but now vivid is out of the
;door so to speak, i will be doing quite a few.
;free ones for vivid license owners.

Global shaderfolder$="shaders\"

Global va#=1
;[ predator skin. wrote by antony wells.]
Function skinrgbscale(fxskin,r#,g#,b#,alpha#=1)
	in.fxskin=Object.fxskin(fxskin)
	Shader_SetPar(in\vp[8],r,g,b,alpha)
End Function

Function skin_initshader(pixshader)
vertshader=pixshader
	Shader_InitPar(vertshader,"modelviewprojection",spmodelviewproj,spwhenon)
	Shader_InitPar(vertshader,"modelviewinverse",spmodelviewit,spwhenon)
	Shader_InitPar(vertshader,"modelview",spmodelview,spwhenon)
	Shader_InitPar(vertshader,"cameraposition",spcameraposition,spwhenon)
	Shader_InitPar(vertshader,"cameravector",spcameravector,spwhenon) 
	For v=0 To 16
		par=Shader_InitPar(vertshader,"light"+Str(v),splightvector,spwhenon)
		If par<>0
			Fx_ShaderPar(par,v,0,0,0,0)
		EndIf
	par=Shader_InitPar(vertshader,"lightposition"+Str(v),splightposition,spwhenon)
		If par<>0
			Fx_ShaderPar(par,v,0,0,0,0)
		EndIf
		par=Shader_InitPar(vertshader,"lightcolor"+Str(v),splightcolor,spwhenon)
		If par<>0
			Fx_ShaderPar(par,v,0,0,0,0)
		EndIf
		par=Shader_InitPar(vertshader,"lightspecular"+Str(v),splightspecular,spwhenon)
		If par<>0
			Fx_ShaderPar(par,v,0,0,0,0)
		EndIf
	Next
End Function

Function skin_zcolor()
;skinzcolor
;
;this fxskin renders the scene color coded
;to the depth of each pixel.
;uses vertex and pixel shaders.
	outskin=FxSkin_Create()
	verts=FxSkin_LoadVertexShader(outskin,shaderfolder+"z_tocolorvert.cg",False)
	pixs=FxSkin_LoadPixelShader(outskin,shaderfolder+"z_tocolorpix.cg",False)
skin_initshader(verts)
zpar=Shader_SetPar(pixs,"zscale",spfloat4,spwhenon)
skin_initshader(pixs)
	fx.fxskin=Object.fxskin(outskin)
	fx\pp[0]=zpar
	fx\vshad=Object.shader(verts)
	fx\pshad=Object.shader(pixs)
	Return outskin
End Function
Function skin_Masking()
	outskin=FxSkin_Create()
	pixs=FxSkin_LoadPixelShader(outskin,shaderfolder+"terrain_1pix.cg",False)
	skin_initshader(pixs)
	fx.fxskin=Object.fxskin(outskin)
	fx\pshad=Object.shader(pixs)
	Return outskin
End Function

Function skin_blurtexture()
	outskin=FxSkin_Create()
	pixs=FxSkin_LoadPixelShader(outskin,shaderfolder+"texture_blur1.cg",False)
	skin_initshader(pixs)
	blurpar=Shader_SetPar(pixs,"blur",spfloat4,spwhenon)
	fx.fxskin=Object.fxskin(outskin)
	fx\pp[0]=blurpar
	fx\pshad=Object.shader(pixs)
	Return outskin
End Function

Function skin_focusmap()
;blurtexture
;
;this fxskin blurs textures per pixel.
;for 2d ops, using activate_texture(...) to bind textures 0,1.
;texture 0=focus map.
;texture 1=color map.
;color map=graphics to display, each pixel will by
;blurred, based on how bright the focus map pixel
;as at the same location. use zcolor skin to produce
;3d depth maps compatible with this for 3d integeration.
;use skin_blurfactor(skin,blurfactor#)
;to increase/decrease blur. 0=no blur. 0.1=alot of blur.
;uses pixel shaders.
	outskin=FxSkin_Create()
	pixs=FxSkin_LoadPixelShader(outskin,shaderfolder+"texture_blur1.cg",False)
	skin_initshader(pixs)
	blurpar=Shader_SetPar(pixs,"blur",spfloat4,spwhenon)
	hazepar=Shader_SetPar(pixs,"ang",spfloat4,spwhenon)
	fx.fxskin=Object.fxskin(outskin)
	fx\pp[0]=blurpar
	fx\pp[1]=hazepar
	fx\pshad=Object.shader(pixs)
	Return outskin
End Function
Function skin_blurfactor(inskin,blurfactor#=0.1)
	fx.fxskin=Object.fxskin(inskin)
	Shader_SetPar(fx\pp[0],blurfactor)
End Function

;increase from 0 to 360, to shimmer pixels in the distance.
;leave at 0 for no haze.
Function skin_blurhaze(inskin,hazeangle#=0)
	fx.fxskin=Object.fxskin(inskin)
	Shader_SetPar(fx\pp[1],hazeangle)
End Function


Function skin_zcolorscale(inskin,zscale#=0.1)
	fx.fxskin=Object.fxskin(inskin)
	Shader_SetPar(fx\pp[0],zscale)
End Function

Function skin_perpixellight()
	outskin =FxSkin_Create()
	verts=FxSkin_LoadVertexShader(outskin,shaderfolder+"light_perpixelvert1.cg",False)
	pixs=FxSkin_LoadPixelShader(outskin,shaderfolder+"light_perpixelpix1.cg",False)
	skin_initshader(verts)
	skin_initshader(pixs)
	fx.fxskin=Object.fxskin(outskin)
	fx\vshad=Object.shader(verts)
	fx\pshad=Object.shader(pixs)
	Return outskin
End Function

Function glskintexture(skin,texture,index=-1)
	in.fxskin=Object.fxskin(skin)
	Fx_ShaderTexture(Handle(in\sp[1]),texture,index)
End Function

Function glskinlight(skin,light,index=-1)
	in.fxskin=Object.fxskin(skin)
	If index=-1 index=in\lc
	in\light[index]=Object.ent(light)
	in\lc=in\lc+1
End Function