Передача параметров шейдера для объекта в Graphics.Blit?

В моем случае мне нужно было создать исключение, поэтому я сделал:

class UnableToStripEnd(Exception):
    """A Exception type to indicate that the suffix cannot be removed from the text."""

    @staticmethod
    def get_exception(text, suffix):
        return UnableToStripEnd("Could not find suffix ({0}) on text: {1}."
                                .format(suffix, text))


def strip_end(text, suffix):
    """Removes the end of a string. Otherwise fails."""
    if not text.endswith(suffix):
        raise UnableToStripEnd.get_exception(text, suffix)
    return text[:len(text)-len(suffix)]
0
задан Ari Lotter 13 July 2018 в 18:56
поделиться

1 ответ

Я сделал это некоторое время назад, поэтому извините за плохое кодирование и ответ. Как я это делал в прошлый раз, был использован командный буфер, в котором вы получаете объект, который содержит информацию о цвете, который вы хотите очертить, и ссылка на рендереры.

public class OutlineObj
{
    public Color outlineColor;
    private Color currentColor;
    public Color targetColor;
    public float speed;
    public Renderer[] renderers;
    public void Outline ()
    {
        currentColor = targetColor;
    }
}

Что касается основного шейдера, выполняющего контур, вам просто нужно получить вершину объекта (камеру) и установить цвет Outline как глобальную переменную.

v2f vert (appdata v)
{
    v2f o;
    o.vertex = UnityObjectToClipPos (v.vertex);
    return o;
}

fixed4 _OutlineColor;

fixed4 frag (v2f i) : SV_Target
{
    return _OutlineColor;
}

Тогда контроллер, в котором вы можете зарегистрировать объекты и создать командный буфер, я не могу запомнить все это, но в значительной степени вам нужно очистить буфер команд, получить рендеринг текстуры перед эффектами изображения, то вы устанавливаете цель рендеринга, очищаете цели и устанавливаете нужные цвета с помощью

public class OutlineController
{
    private CommandBuffer buffer;
    public List<OutlineObj> registerObjects;    

    private void Awake ()
    {
        //GetAll the shaders and their ID
        //Add buffer to camera as before image effects.
    }

    public void Register (OutlineObj obj)
    {
        //register the object
        registerObjects.Add(obj);
    }

private void BuildCommandBuffer ()
{
    //Clear command buffer
    //Get the RT and set the render target
    //Per every object that wants an outline add their color and renders
    foreach (OutlineObj obj in registerObjects)
    {
        buffer.SetGlobalColor (outlieColor, obj.currentColor);
        for (int i = 0; i < obj.renderers.Length; ++i)
        {
            buffer.DrawRenderer(obj.renderers[i], controllerMat);
        }
    }
    //Set the renderPassTexture on the buffers blit
}
    private void Update ()
    {
        BuildCommandBuffer ();
    }
}

. Надеемся, что это поможет, посмотрите, как выполнять составные контуры с помощью командных буферов.

0
ответ дан jour 17 August 2018 в 12:13
поделиться
Другие вопросы по тегам:

Похожие вопросы: