-
Notifications
You must be signed in to change notification settings - Fork 20
/
transparentEffect.lua
56 lines (50 loc) · 1.81 KB
/
transparentEffect.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
--[[
NPL.load("(gl)script/ide/Effect/transparentEffect.lua");
TransparentEffect = commonlib.gettable("MyCompany.Aries.TransparentEffect");
TransparentEffect.Apply();
--]]
local TransparentEffect = commonlib.gettable("MyCompany.Aries.TransparentEffect");
local shaderFile = "script/ide/Effect/Shaders/transparent.fxo";
local effectHandleId = 1102;
local defaultEffectHandle = 12;
--@return effectHandle: remember the previous effect so we can set it back later
function TransparentEffect.Apply(character)
if(character and character:IsValid())then
local prevEffectHandle = character:GetField("render_tech", 0);
if(prevEffectHandle < 100) then
character:SetDynamicField("previousEffect", prevEffectHandle)
end
TransparentEffect.CreateEffect();
character:SetField("render_tech",effectHandleId);
character:SetField("RenderImportance",3);
return prevEffectHandle;
end
end
--r,g,b values range in [0,1]
function TransparentEffect.SetDiffuseColor(r,g,b)
local effect = ParaAsset.GetEffectFile("transparent");
if(effect and effect:IsValid())then
local params = effect:GetParamBlock();
params:SetVector3("diffuseColor",r,g,b);
end
end
function TransparentEffect.ResetEffect(character,effectHandle)
effectHandle = effectHandle or defaultEffectHandle;
if(character and character:IsValid())then
character:SetField("render_tech",effectHandle);
end
end
function TransparentEffect.CreateEffect()
local effect = ParaAsset.GetEffectFile("transparent");
if(effect:IsValid() == false)then
LOG.std(nil, "debug", "transparent", "shader file %s is loaded", shaderFile);
effect = ParaAsset.LoadEffectFile("transparent",shaderFile);
effect = ParaAsset.GetEffectFile("transparent");
effect:SetHandle(effectHandleId);
else
local handle = effect:GetHandle();
if(handle == -1)then
effect:SetHandle(effectHandleId);
end
end
end