Bleys

Hi there,

First of all thanks for this awesome soft :)

I'm trying to get a shader wich can use Normal Map and Spine entities. I've seen a lot of topics on the net but none of them fit really well. So I decided to
modify the Unity 5 Standard Shader, I kept only the Forward and Forward Add pass (lighting is set to Forward in the project).
(The spine export is done with premultiplied alpha checked.)

I came to two results pretty cool but with some troubles with non-directional lights.

In the image attached you can see (left to right)
- Directional Light only : everything is OK
- Directional + Point Light : ForwardAdd pass Alpha blend set to : Blend SrcAlpha One, some transparency issues
- Directional + Point Light : ForwardAdd pass Alpha blend set to : Blend One OneMinusAlphaSrc. You can see a cut : the right part is not affected by the point light and is Ok, but the left is very dark.

I'm not very familiar with shader so if someone can help me with that I would be grateful.

Here is the shader code (the properties are the same as Standard Shader)

SubShader
{
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
LOD 300

// ------------------------------------------------------------------
// Base forward pass (directional light, emission, lightmaps, ...)
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardBase" }
Cull Back

Blend [_SrcBlend] [_DstBlend]
ZWrite [_ZWrite]

CGPROGRAM
#pragma target 3.0
// TEMPORARY: GLES2.0 temporarily disabled to prevent errors spam on devices without textureCubeLodEXT
#pragma exclude_renderers gles

// -------------------------------------

#pragma shader_feature _NORMALMAP
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
#pragma shader_feature _EMISSION
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature ___ _DETAIL_MULX2
#pragma shader_feature _PARALLAXMAP

#pragma multi_compile_fwdbase
#pragma multi_compile_fog

#pragma vertex vertForwardBase
#pragma fragment fragForwardBase

#include "UnityStandardCore.cginc"

ENDCG
}
// ------------------------------------------------------------------
// Additive forward pass (one light per pass)
Pass
{
Name "FORWARD_DELTA"
Tags { "LightMode" = "ForwardAdd" "Queue" = "Transparent" "RenderType" = "Transparent" "IgnoreProjector"="True"}
//Blend SrcAlpha One
Blend One OneMinusSrcAlpha

Fog { Color (0,0,0,0) } // in additive pass fog should be black
Cull Off
ZWrite Off
ZTest LEqual

CGPROGRAM
#pragma target 3.0
// GLES2.0 temporarily disabled to prevent errors spam on devices without textureCubeLodEXT
#pragma exclude_renderers gles

// -------------------------------------
#pragma shader_feature _NORMALMAP
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature ___ _DETAIL_MULX2
#pragma shader_feature _PARALLAXMAP

#pragma multi_compile_fwdadd_fullshadows
#pragma multi_compile_fog

#pragma vertex vertForwardAdd
#pragma fragment fragForwardAdd

#include "UnityStandardCore.cginc"

ENDCG
}
}

FallBack "VertexLit"
CustomEditor "StandardShaderGUI"



Thanks for reading :)
Bu mesaja eklenen dosyaları görüntülemek için gerekli yetkilere sahip değilsiniz.
Bleys
  • Mesajlar: 1

tianna55555

I have same problem. Any idea why?
tianna55555
  • Mesajlar: 2

mugathur

I'm having this same issue and here's my assessment of what's happening. As a warning, I'm pretty new to shaders so I could be completely wrong.

Looking at Unity's documentation of Forward Rendering (http://docs.unity3d.com/Manual/RenderTech-ForwardRendering.html), the first pass is 1 directional light, vertex lighting, and spherical harmonics.

Any spot lights or point lights will be done in further passes.

So, for the base pass, it renders all the layers and is happy. Then, it does another pass and renders everything for a lighting pass. The unfortunate thing, though, is because this is a transparent render, there is no writing to the depth buffer. Therefore, the lighting for all the layers are drawn on top of the base pass, thus causing "back" layers to get drawn on top.

I'm not sure what the solution is for me because my characters have soft edges, but for the images you've supplied, they look like very hard edged characters so you could write to the depth buffer with an alpha cutoff.

Basically just set ZWrite to On and in your fragment shader, add a clip(alpha) so that it doesn't write to the depth buffer for alpha 0. Oh yeah. Make sure that your zSpacing is not 0 or else you'll get the z-fight of a lifetime.
mugathur
  • Mesajlar: 30


Dön Unity