浏览代码

Add More Blend Modes.

Added Divide, HardMix, LinearDodge, Linear Light, Linear Burn, Vivid Light. Fix Soft light.
/main
RinaldoTjan 8 年前
当前提交
efc8e110
共有 2 个文件被更改,包括 76 次插入32 次删除
  1. 94
      MaterialGraphProject/Assets/Rinaldo/BlendModeNode.cs
  2. 14
      MaterialGraphProject/Assets/Rinaldo/BlendModesEnum.cs

94
MaterialGraphProject/Assets/Rinaldo/BlendModeNode.cs


{
return "unity_blendmode_" + precision;
}
protected override string GetInputSlot1Name()
{
return "A|Blend/Src";
}
protected override string GetInputSlot2Name()
{
return "B|Base/Dest";
}
[SerializeField]
private BlendModesEnum m_BlendMode;

}
}
}
/*This is to overide input to be vector 3, not really necessary anymore*/
/*
*/
// var vector3one = precision+ "3(1.0, 1.0, 1.0);
switch (m_BlendMode)
{
case BlendModesEnum.Burn:

// outputString.AddShaderChunk("return "+precision+ "3(1.0,1.0,1.0) - (" + precision + "3(1.0,1.0,1.0) - arg2)/arg1;", false);
outputString.AddShaderChunk("return 1.0 - (1.0 - arg2)/arg1;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);

outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return arg2 / (" + precision + "3(1.0,1.0,1.0) - arg1);", false);
outputString.AddShaderChunk("return arg2 / (1.0 - arg1);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
break;
case BlendModesEnum.Divide:
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return arg2 / (arg1 + 0.000000000001);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
break;

outputString.Indent();
outputString.AddShaderChunk("return arg2 + arg1 - (" + precision + "3(2.0,2.0,2.0)*arg2*arg1);", false);
// outputString.AddShaderChunk("return arg2 + arg1 - (" + precision + "3(2.0,2.0,2.0)*arg2*arg1);", false);
outputString.AddShaderChunk("return arg2 + arg1 - (2.0 *arg2*arg1);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
break;

outputString.Deindent();
outputString.AddShaderChunk("}", false);
break;
case BlendModesEnum.HardMix:
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return step(1-arg1, arg2);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
break;
case BlendModesEnum.Lighten:
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);

outputString.AddShaderChunk("}", false);
break;
case BlendModesEnum.LinearBurn:
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return arg1 + arg2 - 1.0;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
break;
case BlendModesEnum.LinearDodge:
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return arg1 + arg2;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
break;
case BlendModesEnum.LinearLight:
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return arg2 + 2.0 * arg1 - 1.0;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
break;
case BlendModesEnum.Multiply:
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);

outputString.Deindent();
outputString.AddShaderChunk("}", false);
break;
/* case BlendModesEnum.Overlay:
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk(precision + outputDimension + " result1 = 2.0 * arg1 * arg2;", false);
outputString.AddShaderChunk(precision + outputDimension + " result2 = 1.0 - 2.0 * (1.0 - arg1) * (1.0 - arg2);", false);
outputString.AddShaderChunk(precision + outputDimension + " zeroOrOne = step(arg2, 0.5);", false);
outputString.AddShaderChunk("return result2 * zeroOrOne + (1 - zeroOrOne) * result1;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
break;
*/
// outputString.AddShaderChunk("return " + precision + "3(1.0, 1.0, 1.0) - ((" + precision + "3(1.0, 1.0, 1.0)-arg2) * (" + precision + "3(1.0, 1.0, 1.0) - arg1));", false);
outputString.AddShaderChunk("return 1.0 - (1.0-arg2) * (1.0 - arg1);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);

outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk(precision + outputDimension + " result2= 2.0 * arg2 * arg1 + arg2*arg2 - 2.0 * arg2*arg2*arg1;", false);
outputString.AddShaderChunk(precision + outputDimension + " result1= 2.0* sqrt(arg2) * arg1 - sqrt(arg2) + 2.0 * arg2 - 2.0 * arg2*arg1;", false);
outputString.AddShaderChunk(precision + outputDimension + " zeroOrOne = step(arg2, 0.5);", false);
outputString.AddShaderChunk(precision + outputDimension + " result1= 2.0 * arg2 * arg1 + arg2*arg2 - 2.0 * arg2*arg2*arg1;", false);
outputString.AddShaderChunk(precision + outputDimension + " result2= 2.0* sqrt(arg2) * arg1 - sqrt(arg2) + 2.0 * arg2 - 2.0 * arg2*arg1;", false);
outputString.AddShaderChunk(precision + outputDimension + " zeroOrOne = step(0.5, arg1);", false);
outputString.AddShaderChunk("return result2 * zeroOrOne + (1 - zeroOrOne) * result1;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);

outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return arg1 - arg2;", false);
outputString.AddShaderChunk("return arg2 - arg1;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
break;
case BlendModesEnum.VividLight:
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk(precision + outputDimension + " result1= 1.0-(1.0-arg2)/(2.0*arg1);", false);
outputString.AddShaderChunk(precision + outputDimension + " result2= arg2/(2.0*(1.0-arg1));", false);
outputString.AddShaderChunk(precision + outputDimension + " zeroOrOne = step(0.5, arg1);", false);
outputString.AddShaderChunk("return result2 * zeroOrOne + (1 - zeroOrOne) * result1;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
break;

14
MaterialGraphProject/Assets/Rinaldo/BlendModesEnum.cs


public enum BlendModesEnum
{
Burn,
Dodge,
// Divide,
Dodge,
Divide,
// HardMix,
HardMix,
// LinearDodge,
// LinearLight,
// LinearBurn,
LinearBurn,
LinearDodge,
LinearLight,
Multiply,
Negation,
Overlay,

Substract,
// VividLight
VividLight
/* Old Order

正在加载...
取消
保存