Skip to content

Commit

Permalink
[unity] Pass ceramic blending params onto unity shader as separate pa…
Browse files Browse the repository at this point in the history
…rameters 👍
  • Loading branch information
jeremyfa committed Nov 15, 2020
1 parent 2f3f79f commit ef1a915
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
6 changes: 5 additions & 1 deletion plugins/unity/assets/msdf.shader
Expand Up @@ -4,6 +4,10 @@ Shader "msdf"
{
[PerRendererData] _MainTex ("Main Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_SrcBlendRgb ("Src Rgb", Int) = 0
_DstBlendRgb ("Dst Rgb", Int) = 0
_SrcBlendAlpha ("Src Alpha", Int) = 0
_DstBlendAlpha ("Dst Alpha", Int) = 0
texSize ("texSize", Vector) = (0,0,0,0)
pxRange ("pxRange", Float) = 0.0
}
Expand All @@ -22,7 +26,7 @@ Shader "msdf"
Cull Off
Lighting Off
ZWrite Off
Blend One OneMinusSrcAlpha
Blend [_SrcBlendRgb] [_DstBlendRgb], [_SrcBlendAlpha] [_DstBlendAlpha]

Pass
{
Expand Down
6 changes: 5 additions & 1 deletion plugins/unity/assets/pixelArt.shader
Expand Up @@ -4,6 +4,10 @@ Shader "pixelArt"
{
[PerRendererData] _MainTex ("Main Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_SrcBlendRgb ("Src Rgb", Int) = 0
_DstBlendRgb ("Dst Rgb", Int) = 0
_SrcBlendAlpha ("Src Alpha", Int) = 0
_DstBlendAlpha ("Dst Alpha", Int) = 0
}

SubShader
Expand All @@ -20,7 +24,7 @@ Shader "pixelArt"
Cull Off
Lighting Off
ZWrite Off
Blend One OneMinusSrcAlpha
Blend [_SrcBlendRgb] [_DstBlendRgb], [_SrcBlendAlpha] [_DstBlendAlpha]

Pass
{
Expand Down
6 changes: 5 additions & 1 deletion plugins/unity/assets/textured.shader
Expand Up @@ -4,6 +4,10 @@ Shader "textured"
{
[PerRendererData] _MainTex ("Main Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_SrcBlendRgb ("Src Rgb", Int) = 0
_DstBlendRgb ("Dst Rgb", Int) = 0
_SrcBlendAlpha ("Src Alpha", Int) = 0
_DstBlendAlpha ("Dst Alpha", Int) = 0
}

SubShader
Expand All @@ -20,7 +24,7 @@ Shader "textured"
Cull Off
Lighting Off
ZWrite Off
Blend One OneMinusSrcAlpha
Blend [_SrcBlendRgb] [_DstBlendRgb], [_SrcBlendAlpha] [_DstBlendAlpha]

Pass
{
Expand Down
29 changes: 29 additions & 0 deletions plugins/unity/runtime/src/backend/MaterialData.hx
Expand Up @@ -104,4 +104,33 @@ class MaterialData {

}

public static function blendingToUnityBlending(blending:backend.BlendMode):unityengine.rendering.BlendMode {

return switch blending {
case ZERO:
unityengine.rendering.BlendMode.Zero;
case ONE:
unityengine.rendering.BlendMode.One;
case SRC_COLOR:
unityengine.rendering.BlendMode.SrcColor;
case ONE_MINUS_SRC_COLOR:
unityengine.rendering.BlendMode.OneMinusSrcColor;
case SRC_ALPHA:
unityengine.rendering.BlendMode.SrcAlpha;
case ONE_MINUS_SRC_ALPHA:
unityengine.rendering.BlendMode.OneMinusSrcAlpha;
case DST_ALPHA:
unityengine.rendering.BlendMode.DstAlpha;
case ONE_MINUS_DST_ALPHA:
unityengine.rendering.BlendMode.OneMinusDstAlpha;
case DST_COLOR:
unityengine.rendering.BlendMode.DstColor;
case ONE_MINUS_DST_COLOR:
unityengine.rendering.BlendMode.OneMinusDstColor;
case SRC_ALPHA_SATURATE:
unityengine.rendering.BlendMode.SrcAlphaSaturate;
}

}

}
9 changes: 7 additions & 2 deletions plugins/unity/runtime/src/backend/Materials.hx
Expand Up @@ -51,14 +51,19 @@ class Materials {
repository.push(materialData);

if (texture != null) {
untyped __cs__('material.mainTexture = {1}', material, texture.unityTexture);
untyped __cs__('material.mainTexture = {0}', texture.unityTexture);
}
else {
untyped __cs__('material.mainTexture = {1}', material, null);
untyped __cs__('material.mainTexture = {0}', null);
}

materialData.syncShaderParams();

untyped __cs__('material.SetInt("_SrcBlendRgb", (int){0})', MaterialData.blendingToUnityBlending(materialData.srcRgb));
untyped __cs__('material.SetInt("_DstBlendRgb", (int){0})', MaterialData.blendingToUnityBlending(materialData.dstRgb));
untyped __cs__('material.SetInt("_SrcBlendAlpha", (int){0})', MaterialData.blendingToUnityBlending(materialData.srcAlpha));
untyped __cs__('material.SetInt("_DstBlendAlpha", (int){0})', MaterialData.blendingToUnityBlending(materialData.dstAlpha));

return materialData;

}
Expand Down

0 comments on commit ef1a915

Please sign in to comment.