/***************************************************************************
 *                         Zanoza Modeler v3.3.x                           *
 *     This is unpublished proprietary source code of Zanoza Software.     *
 *      The copyright notice does not evidence any actual or intended      *
 *                    publication of such source code.                     *
 *                                                                         *
 *                 Copyright (c) 2002-2024 Zanoza Software.                *
 *                                                                         *
 *                        All rights reserved.                             *
 ***************************************************************************
 *--------------------------------------------------------------------------
 * @author:   Oleg M.
 *--------------------------------------------------------------------------
 * @purpose:  ZModeler 3.3.x Pure (no parameters) screen-space shader
 *--------------------------------------------------------------------------
 * @history: 17.02.2023. Created
 * @Description:
   Shader for default rendering (with no materials). Used to draw 
   general-purpose geometry in viewports like wireframe, primitives,
   on-screen grid and other elements with flexible vertices format.
   This version of shader does not involve any light-specific 
   computations (attenuation on normals, back-facing fade etc.)
   and input vertices format does not need normals/tangents.
<[[
UserName = "On-screen Wireframe/solid"
Version  = 2.0
Options  = PURE
Engine = 11
]]>
*/

#pragma pack_matrix( row_major ) 

struct VS_INPUT
{
    float4 vPosition        : SV_POSITION;
    float4 vColorDif        : COLOR0;
};

struct VS_OUTPUT
{
    float4  vPosition : SV_POSITION;
    float4  vDiffuse  : COLOR;
};

#include "zmCommonBuffers.inl"

#ifdef VERTEX_SHADER

VS_OUTPUT mainVS(in VS_INPUT v)
{
    VS_OUTPUT output;

    //transform to screen:
    output.vPosition = float4(mul(v.vPosition, (float4x3)g_mWorld), 1);
    output.vPosition = float4(mul(output.vPosition, (float4x3)g_mView),1);
    output.vPosition = mul(output.vPosition, g_mProj);

    //
    // diffuse:
    float4 vertColor = (any(v.vColorDif.rgb) ? v.vColorDif : 1);
    float4 color = lerp(1, g_colors[1], g_colorBlend.y) * 
                   lerp(1, vertColor, g_colorBlend.x);

    // add emissive:
    color.rgb += //vertColor.rgb*g_colorBlend.z +
                 g_colors[3].rgb*g_colors[3].w;
    output.vDiffuse = color;
    output.vDiffuse.a = g_colors[1].a*lerp(1, vertColor.a, g_colorBlend.a);

    return output;
}
#endif //VERTEX_SHADER

float4 mainPS(in VS_OUTPUT v) : SV_TARGET
{
  return v.vDiffuse;
}
