Giter Site home page Giter Site logo

james-jones / hlslcrosscompiler Goto Github PK

View Code? Open in Web Editor NEW
468.0 468.0 81.0 5.68 MB

License: Other

C++ 41.32% C 35.69% Shell 1.87% XSLT 0.03% FLUX 0.42% Assembly 2.38% Python 0.03% CMake 0.21% Makefile 2.47% M4 0.13% Groff 0.02% HTML 0.01% Logos 11.32% HLSL 1.21% GLSL 2.83% Objective-C 0.07%

hlslcrosscompiler's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hlslcrosscompiler's Issues

Declaring constant buffers out of order

There is a problem in reflection of constant buffers. If a buffer bound to b1 is declared before the buffer bound to b0 like this:
cbuffer cb1 : register(b1)
{
float4x4 world_view_proj;
};
cbuffer cb0 : register(b0)
{
float4 vars;
};
void main( in float4 in_pos : POSITION0, out float4 out_pos : POSITION )
{
float4 pos = in_pos + vars;
out_pos = mul(pos, world_view_proj);
}

the cross compiler will crash in TranslateVariableName because the buffers are swapped.

Implicit cast from float to uint in GLSL

When calling glCompileShader() with GLSL generated by HLSLCrossCompiler, GL says 'error C7011: implicit cast from "float" to "uint"'. I'm using an NVIDIA GPU. I tracked down the issue to this line of D3D microcode:

movc r0.x, cb0[391].y, r0.x, l(0)

This cross compiles into:

if(vec4(GlobalsVS.g_bFade).x != 0) {
    Temp_uint[0].x = Temp_uint[0].x;
} else {
    Temp_uint[0].x = 0.000000;    // <-- This line causes the error
}

The issue seems to be that the HLSL literal 'l(0)' is cross compiled into '0.000000' and not '0'.

I'm about to start digging through the HLSLCrossCompiler code, but I'm not sure where to start. I assume that since it knows the left-hand side is a uint that it will be able to work out that the right-hand side should be a uint?

Problems building on Linux: undefined reference to `max`

I'm building as follows:

$ git clone https://github.com/James-Jones/HLSLCrossCompiler.git
$ cd HLSLCrossCompiler
$ mkdir build && cd build
$ cmake ../mk
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
SETTING Little endian
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nand/dev/HLSLCrossCompiler/build
$ make
...
[ 97%] Linking CXX executable /home/nand/dev/HLSLCrossCompiler/bin/HLSLcc
/home/nand/dev/HLSLCrossCompiler/lib/liblibHLSLcc.a(toGLSLInstruction.c.o): In function `AddComparision':
toGLSLInstruction.c:(.text+0x1819): undefined reference to `max'
/home/nand/dev/HLSLCrossCompiler/lib/liblibHLSLcc.a(toGLSLOperand.c.o): In function `TranslateVariableNameWithMask':
toGLSLOperand.c:(.text+0x1ec2): undefined reference to `max'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/HLSLcc.dir/build.make:174: /home/nand/dev/HLSLCrossCompiler/bin/HLSLcc] Error 1
make[1]: *** [CMakeFiles/Makefile2:142: CMakeFiles/HLSLcc.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[100%] Linking CXX executable /home/nand/dev/HLSLCrossCompiler/bin/HLSLcc-i386
/home/nand/dev/HLSLCrossCompiler/lib/liblibHLSLcc-i386.a(toGLSLInstruction.c.o): In function `AddComparision':
toGLSLInstruction.c:(.text+0x188b): undefined reference to `max'
/home/nand/dev/HLSLCrossCompiler/lib/liblibHLSLcc-i386.a(toGLSLOperand.c.o): In function `TranslateVariableNameWithMask':
toGLSLOperand.c:(.text+0x1f04): undefined reference to `max'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/HLSLcc-i386.dir/build.make:174: /home/nand/dev/HLSLCrossCompiler/bin/HLSLcc-i386] Error 1
make[1]: *** [CMakeFiles/Makefile2:179: CMakeFiles/HLSLcc-i386.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

HLSL exp2(x) and log2(x) compiled incorrectly to GLSL exp(x) and log(x)

FXC compiles:

  • exp2(x) to 'exp' instructions in DXASM
  • log2(x) to 'log' instructions in DXASM

So DXASM exp and log instructions really are base-2 exp & log functions.

But HLSLcc is translating OPCODE_LOG to "log" and OPCODE_EXP to "exp".

Instead, I think it should be translating OPCODE_LOG to "log2" and OPCODE_EXP to "exp2", like this, in src / toGLSLInstruction.c:

case OPCODE_LOG:
    {
        CallHelper1(psContext, "log2", psInst, 0, 1);
        break;
    }
    case OPCODE_EXP:
    {
        CallHelper1(psContext, "exp2", psInst, 0, 1);
        break;
    }

Crash in FreeGLSLShader()

I'm crashing in FreeGLSLShader() when it frees the psShaderInfo->psConstantBuffers variable. Specifically, the Visual Studio C runtime says that "this may be due to a corruption of the heap". In my code, I've hooked the malloc/calloc/free/realloc callbacks, but they just call directly to the C runtime.

I then built and ran the standalone hlslcc.exe executable, and that has the same issue with the same shader. It does work fine with a very simple test shader though.

I printed out all the calls to the hooked memory functions, and I see it allocate the same memory that it's later trying to free, and there's no double-free. Are there any known issues with memory corruption in the library?

I'll keep digging into it on my end. Is there a way to get you the shader binary (or even the source HLSL code, if that's helpful) that's causing the crash?

constant buffer packed values addressed erroneously

It look like if several constant buffer values get packed in a single "constant buffer register" the hlslcc addresses only the first value in the register

for example in the following shader the buffer is all packed in a single register ("cb[0]")

EDIT: the problem only occurs when 2 or more "variables" are accessed at once (by the D3D HLSL optimizer) using a swizzle like "cb[0].xy" (when the optimizer doesn't pack them in a swizzle it works fine)


INPUT

cbuffer RenderTargetParams {
int Width;
int Height;
float AspectRatio;
}

struct VS_model0_ZNORMAL_Input {
float4 ObjectPosition : POSITION;
float3 Normal : NORMAL;

};

struct VS_model0_GATHER_Output {
float4 PixelPosition : SV_Position;
};

VS_model0_GATHER_Output main(VS_model0_ZNORMAL_Input input)
{
VS_model0_GATHER_Output output = (VS_model0_GATHER_Output)0;
float2 _screenuvnormalized;

_screenuvnormalized = float2(input.ObjectPosition.x / Width, input.ObjectPosition.y / Height);
output.PixelPosition.xy = _screenuvnormalized;
output.PixelPosition.zw = float2(Width * 2, Height * 2);
return output;

}


ASM

// Buffer Definitions:
//
// cbuffer RenderTargetParams
// {
//
// int Width; // Offset: 0 Size: 4
// int Height; // Offset: 4 Size: 4
// float AspectRatio; // Offset: 8 Size: 4 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name Type Format Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// RenderTargetParams cbuffer NA NA 0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// POSITION 0 xyzw 0 NONE float xy
// NORMAL 0 xyz 1 NONE float
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position 0 xyzw 0 POS float xyzw
//
vs_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[1], immediateIndexed
dcl_input v0.xy
dcl_output_siv o0.xyzw, position
dcl_temps 1
itof r0.xy, cb0[0].xyxx
div o0.xy, v0.xyxx, r0.xyxx
ishl r0.xy, cb0[0].xyxx, l(1, 1, 0, 0)
itof o0.zw, r0.xxxy
ret


OUTPUT

version 430

extension GL_ARB_shader_bit_encoding : require

struct vec1 {
float x;
};
struct uvec1 {
uint x;
};
struct ivec1 {
int x;
};
out gl_PerVertex {
vec4 gl_Position;
float gl_PointSize;
float gl_ClipDistance[];};
subroutine void SubroutineType();
layout(location = 0) uniform struct RenderTargetParamsVS_Type {
int Width;
int Height;
float AspectRatio;
} RenderTargetParamsVS;
layout(location = 0) in vec4 dcl_Input0;
vec4 Input0;

undef Output0

define Output0 phase0_Output0

vec4 phase0_Output0;
vec4 Temp[1];
ivec4 Temp_int[1];
uvec4 Temp_uint[1];
void main()
{
Input0 = dcl_Input0;
Temp_int[0].xy = floatBitsToInt(vec4(RenderTargetParamsVS.Width).xy);
Output0.xy = (vec4(Input0.xyxx / intBitsToFloat(Temp_int[0]).xyxx)).xy;
Temp_int[0].xy = (RenderTargetParamsVS.Width << ivec4(0x1, 0x1, 0x0, 0x0)).xy;
Output0.zw = (vec4(Temp_int[0].xxxy).zw);
gl_Position = vec4(phase0_Output0);
return;
}

the correct result should be more like

Temp_int[0].xy = (vec4(RenderTargetParamsVS.Width,RenderTargetParamsVS.Height,0,0) << ivec4(0x1, 0x1, 0x0, 0x0)).xy;

and

Temp_int[0].xy = floatBitsToInt(vec4(RenderTargetParamsVS.Width,RenderTargetParamsVS.Height,0,0).xy);

thank you for you time
Alberto

Another thing to fix

This fragment program:
sampler2D Texture0 : register(s0) : register(t0);
void main(out float4 Color : COLOR0)
{
Color = tex2D( Texture0, float2(0.5f, 0.5f) ).rrrr;
}

fails with error C7011: implicit cast from "vec4" to "vec2"

UDIV glsl output can be invalid

Hi,

under certain circumstances the glsl output for the UDIV operation is wrong:
if the first output register is the same as one of the operands, the divide will overwrite the operant and the following modulo uses wrong values as input.

Analyze of a cross compile

This one requires a bit more description. The cross compile don't fail, and I still have not tried running the shader for real. But the result worries me. So here goes:

The HLSL fragment program:
struct v2p
{
float3 Tex0 : TEXCOORD0;
float2 BlendWeights : TEXCOORD1;
float2 Tex1 : TEXCOORD2;
};
sampler2D Texture : register(s0) : register(t0);
void main( in v2p In, out float4 Out : COLOR0 )
{
float4 TopLeftTex = tex2D( Texture, In.Tex0.xz );
float4 TopRightTex = tex2D( Texture, In.Tex0.yz );
float4 BottomTex = tex2D( Texture, In.Tex1 );
float alphaBlendLeft = TopLeftTex.a * ( 1.h - In.BlendWeights.x );
float alphaBlendRight = TopRightTex.a * In.BlendWeights.x;
float bottom_alpha = BottomTex.a * In.BlendWeights.y;
const float blendThreshold = 0.250980392h;
Out = bottom_alpha > blendThreshold ? BottomTex : ( alphaBlendLeft > blendThreshold ) ? TopLeftTex : ( alphaBlendRight > blendThreshold ) ? TopRightTex : 0.h;
}

The D3D ASM:
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_sampler s0, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps linear v0.xyz
dcl_input_ps linear v1.xy
dcl_input_ps linear v1.zw
dcl_output o0.xyzw
dcl_temps 3
sample_indexable(texture2d)(float,float,float,float) r0.xyzw, v0.yzyy, t0.xyzw, s0
mul r1.x, r0.w, v1.x
lt r1.x, l(0.250980), r1.x
and r0.xyzw, r0.xyzw, r1.xxxx
add r1.x, -v1.x, l(1.000000)
sample_indexable(texture2d)(float,float,float,float) r2.xyzw, v0.xzxx, t0.xyzw, s0
mul r1.x, r1.x, r2.w
lt r1.x, l(0.250980), r1.x
movc r0.xyzw, r1.xxxx, r2.xyzw, r0.xyzw
sample_indexable(texture2d)(float,float,float,float) r1.xyzw, v1.zwzz, t0.xyzw, s0
mul r2.x, r1.w, v1.y
lt r2.x, l(0.250980), r2.x
movc o0.xyzw, r2.xxxx, r1.xyzw, r0.xyzw
ret

The converted GLSL program:

version 410

struct vec1 {
float x;
};
struct uvec1 {
uint x;
};
struct ivec1 {
int x;
};
subroutine void SubroutineType();
uniform sampler2D Texture;
layout(location = 0) in vec4 VtxGeoOutput0;
vec4 Input0;
layout(location = 1) in vec4 VtxGeoOutput1;
vec4 Input1;
layout(location = 0) out vec4 PixOutput0;

define Output0 PixOutput0

vec4 Temp0;
ivec4 Temp0_int;
uvec4 Temp0_uint;
vec4 Temp1;
ivec4 Temp1_int;
uvec4 Temp1_uint;
vec4 Temp2;
ivec4 Temp2_int;
uvec4 Temp2_uint;
void main()
{
Input0 = VtxGeoOutput0;
Input1 = VtxGeoOutput1;
Input1 = VtxGeoOutput1;
Temp0 = (texture(Texture, Input0.yz));
Temp1.x = Temp0.w * Input1.x;
Temp1_uint.x = ((0.250980)< (Temp1.x)) ? 1u : 0u;
Temp0_int = ivec4(ivec4(Temp0) & ivec4(Temp1_uint).xxxx);
Temp1.x = -Input1.x + 1.000000;
Temp2 = (texture(Texture, Input0.xz));
Temp1.x = Temp1.x * Temp2.w;
Temp1_uint.x = ((0.250980)< (Temp1.x)) ? 1u : 0u;
if(vec4(Temp1_uint.xxxx).x != 0) {
Temp0 = Temp2;
} else {
Temp0 = Temp0_int;
}
Temp1 = (texture(Texture, Input1.zw));
Temp2.x = Temp1.w * Input1.y;
Temp2_uint.x = ((0.250980)< (Temp2.x)) ? 1u : 0u;
if(vec4(Temp2_uint.xxxx).x != 0) {
Output0 = Temp1;
} else {
Output0 = Temp0;
}
return;
}

And the problem, the D3D ASM does:
lt r1.x, l(0.250980), r1.x
and r0.xyzw, r0.xyzw, r1.xxxx

I imagine that the result of "lt" is either 0xFFFFFFFFU or 0x0U. When doing "and" with a float, it will either set the float to 0.0f or keep it as it was.

While the GLSL does:
Temp1_uint.x = ((0.250980)< (Temp1.x)) ? 1u : 0u;
Temp0_int = ivec4(ivec4(Temp0) & ivec4(Temp1_uint).xxxx);

Here are a few problems:

  • First the result of the conditional assignment is either 0x1U or 0x0U. Additionally perhaps a "bvec4 b = lessThan(x, y)" would be better than a uvec4 b = a < b ? (uint) -1 : 0? Perhaps it doesn't matter, but the result should be max_uint, not 1.
  • At the second line, the floats in Temp0 is converted to ints. An "floatBitsToInt()" would reinterpret the floats correctly, and then an "intBitsToFloat()" back to store the result.
  • Another small issue (which is probably fine) is that the and in the cross compiler don't keep uints, it seems to require values to be casted to ints. This is fine if the resulting value is not supposed to be casted back to a float.

Hull shader input: VtxOutputGeo0 not array when it should be.

When working on getting triangle tessellation to work, I noticed a problem when doing a simple pass through for the control points that doesn't appear to be a problem with quads on my driver (though the code generation bug still exists).

Unless you are modifying the control points, VtxOutputGeo0 is not declared as an array (3 for tri, 4 for quad). This causes a link error for me. To work around this whilst testing things I modified the shader I was using to simply multiply the control points by a value to ensure their modification, VtxOutputGeo0 in this case was declared as an array of size 3. The code that works is as follows:

struct IA_OUTPUT
{
    float4 cpoint : CPOINT;
    float4 colour : COLOR;
};

struct VS_OUTPUT
{
    float4 cpoint : SV_Position;
    float4 colour : COLOR;
};

matrix World;
matrix View;
matrix Projection;

VS_OUTPUT VS(IA_OUTPUT input)
{
    VS_OUTPUT output;

    output.cpoint = mul( input.cpoint, World );
    output.cpoint = mul( output.cpoint, View );
    output.cpoint = mul( output.cpoint, Projection );

    output.colour = input.colour;
    return output;
}

struct HS_CONSTANT_OUTPUT
{
    float edges[3] : SV_TessFactor;
    float innerEdges: SV_InsideTessFactor;
};

struct HS_OUTPUT
{
    float4 cpoint : SV_Position;
    float4 colour : COLOR;
};

float InnerFactor = 1.0f;
float OuterFactor = 1.0f;

HS_CONSTANT_OUTPUT HSConst()
{
    HS_CONSTANT_OUTPUT output;

    output.innerEdges = InnerFactor;
    output.edges[0] = OuterFactor;
    output.edges[1] = OuterFactor;
    output.edges[2] = OuterFactor;

    return output;
}

[domain("tri")]
[partitioning("integer")]
[outputtopology("triangle_ccw")]
[outputcontrolpoints(3)]
[patchconstantfunc("HSConst")]
HS_OUTPUT HS(InputPatch<VS_OUTPUT, 3> ip, uint id : SV_OutputControlPointID)
{
    HS_OUTPUT output;
    output.cpoint = ip[id].cpoint * 1.01f;
    output.colour = ip[id].colour * 1.01f;
    return output;
}

struct DS_OUTPUT
{
    float4 position : SV_Position;
    float4 colour : COLOR;
};


float4 interpolate(float3 TessCoord, float4 v0, float4 v1, float4 v2 )
{
    float4 a = TessCoord.x * v0;
    float4 b = TessCoord.y * v1;
    float4 c = TessCoord.z * v2;
    return a + b + c;
}

[domain("tri")]
DS_OUTPUT DS(HS_CONSTANT_OUTPUT input, OutputPatch<HS_OUTPUT, 3> op, float3 uv : SV_DomainLocation)
{
    DS_OUTPUT output;

    output.position = interpolate(uv, op[0].cpoint, op[1].cpoint, op[2].cpoint);

    output.colour = interpolate(uv, op[0].colour, op[1].colour, op[2].colour);

    return output;
}


float4 PS(DS_OUTPUT input) : SV_Target0
{
    return input.colour;
}

The code that shows the bug is as follows:

struct IA_OUTPUT
{
    float4 cpoint : CPOINT;
    float4 colour : COLOR;
};

struct VS_OUTPUT
{
    float4 cpoint : SV_Position;
    float4 colour : COLOR;
};

matrix World;
matrix View;
matrix Projection;

VS_OUTPUT VS(IA_OUTPUT input)
{
    VS_OUTPUT output;

    output.cpoint = mul( input.cpoint, World );
    output.cpoint = mul( output.cpoint, View );
    output.cpoint = mul( output.cpoint, Projection );

    output.colour = input.colour;
    return output;
}

struct HS_CONSTANT_OUTPUT
{
    float edges[3] : SV_TessFactor;
    float innerEdges: SV_InsideTessFactor;
};

struct HS_OUTPUT
{
    float4 cpoint : SV_Position;
    float4 colour : COLOR;
};

float InnerFactor = 1.0f;
float OuterFactor = 1.0f;

HS_CONSTANT_OUTPUT HSConst()
{
    HS_CONSTANT_OUTPUT output;

    output.innerEdges = InnerFactor;
    output.edges[0] = OuterFactor;
    output.edges[1] = OuterFactor;
    output.edges[2] = OuterFactor;

    return output;
}

[domain("tri")]
[partitioning("integer")]
[outputtopology("triangle_ccw")]
[outputcontrolpoints(3)]
[patchconstantfunc("HSConst")]
HS_OUTPUT HS(InputPatch<VS_OUTPUT, 3> ip, uint id : SV_OutputControlPointID)
{
    HS_OUTPUT output;
    output.cpoint = ip[id].cpoint;
    output.colour = ip[id].colour;
    return output;
}

struct DS_OUTPUT
{
    float4 position : SV_Position;
    float4 colour : COLOR;
};


float4 interpolate(float3 TessCoord, float4 v0, float4 v1, float4 v2 )
{
    float4 a = TessCoord.x * v0;
    float4 b = TessCoord.y * v1;
    float4 c = TessCoord.z * v2;
    return a + b + c;
}

[domain("tri")]
DS_OUTPUT DS(HS_CONSTANT_OUTPUT input, OutputPatch<HS_OUTPUT, 3> op, float3 uv : SV_DomainLocation)
{
    DS_OUTPUT output;

    output.position = interpolate(uv, op[0].cpoint, op[1].cpoint, op[2].cpoint);

    output.colour = interpolate(uv, op[0].colour, op[1].colour, op[2].colour);

    return output;
}


float4 PS(DS_OUTPUT input) : SV_Target0
{
    return input.colour;
}

Assertion failing during convert

This probably more of a user error than an issue, but I can't seem to get anything to convert. I either get a failed assertion in GetConstantBufferFromBindingPoint() (psShaderInfo->ui32NumConstantBuffers is always 0) or a crash in AddUserOutput() (psSignature is null when the switch tries to access it), depending on exactly which shader I try to convert.

I'm not compiling the HLSL with the strip_reflect or strip_debug options. Is there anything stupid that I'm forgetting to do?

Missing Opcode - minor issue

In the Switch statement, there are:

case OPCODE_MIN: case OPCODE_IMAX: case OPCODE_MAX: case OPCODE_MUL:

which is missing OPCODE_IMIN:

Minor issue, but ran across the need for it, so seemed worth mentioning.

Another implicit cast issue

I'm seeing a separate issue that is causing implicit cast errors. Given this HLSL:

void TestVS(float4 vPos : POSITION, out float4 oPosition : POSITION)
{
    float4 value;
    if (vPos.x == 1 && vPos.y == 1)
        value = 0;
    else
        value = 1;
    oPosition = value;
}

The D3D bytecode is this:

vs_4_0
dcl_input v0.xy
dcl_output o0.xyzw
dcl_temps 1
eq r0.xy, v0.xyxx, l(1.000000, 1.000000, 0.000000, 0.000000)
and r0.x, r0.y, r0.x
movc o0.xyzw, r0.xxxx, l(0,0,0,0), l(1.000000,1.000000,1.000000,1.000000)
ret 

Which gets cross-compiled to:

void main()
{
    //--- Start Early Main ---
    Input0 = dcl_Input0;
    //--- End Early Main ---
    //Instruction 0
    //EQ
    Temp_uint[0].xy = uvec2(equal(vec4(Input0.xyxx).xy, vec4(vec4(1.000000, 1.000000, 0.000000, 0.000000)).xy)) * 0xFFFFFFFFu;
    //Instruction 1
    //AND
    Temp_uint[0].x = ivec4(Temp_uint[0]).y & ivec4(Temp_uint[0]).x;
    //Instruction 2
    //MOVC
    if(vec4(Temp_uint[0].xxxx).x != 0) {
        Output0 = vec4(0.000000, 0.000000, 0.000000, 0.000000);
    } else {
        Output0 = vec4(1.000000, 1.000000, 1.000000, 1.000000);
    }
    //Instruction 3
    //RET
    return;
}

But GLSL complains that on line 11 (after the // AND comment) there is an implicit cast from int to uint.

Packet in/out variables are handled incorrectly

Hi,

when the HLSL shader compiler decides to pack multiple in/out variables into one vec4, only the first decl is emitted correctly. Resulting in wrong in/out temp variable types, assignments and swizzle/index operations.

An example for a packet in/out would be:

struct VS_Out {
float2 var1 : TEXCOORD0;
float4 var2 : TEXCOORD1;
float var3 : TEXCOORD2;
};

The HLSL compiler will pack var3 and var1 into one float3 in/out register and this breaks HLSLcc.

ld_aoffimmi returns bad u,v,w indices

Please know that I'm not expert here, and could be wrong.

I did check the latest code in the repository, and think this is probably still a problem.

For an instruction like:
ld_aoffimmi(-1,0,0) r2.xyzw, r0.xzww, t1.xyzw
The decompiler is returning iUAddrOffset=15, instead of -1.

The return value is defined as int, but the parameter is actually a 4 bit, 2's complement number, so the range should be -8..7 instead of the returned 1..15

Here are the docs for this instruction, in case it's helpful.
http://msdn.microsoft.com/en-us/library/windows/desktop/hh447172(v=vs.85).aspx

cbuffer with array of structs

Hello there,
So it seems we can't have arrays in a cbuffer.
how do you work around that?

This is for a specific case. Pass an array of lights structs to a shader

Problems with SINCOS

I really like this project. I have tried to run HLSLcc on a large amount of shaders and want to give you feedback on a few issues I have come across:

  • In decode.c, DeocdeInstruction(), the "case OPCODE_SINCOS:" should set "psInst->ui32FirstSrc = 2;" since the D3D ASM op SINCOS has two outputs and one input.
  • A second issue with SINCOS is in toGLSLInstruction.c, TranslateInstruction(), the result of the operation is not swizzled. I had a case where the HLSL code had "float2 = sin(float2)" which after the cross compile resulted in an 'error C7011: implicit cast from "vec4" to "vec2" '
  • I'm not sure, but perhaps the "TranslateOperand" for "//Dest cos" should use TO_FLAG_DESTINATION? The code is in the same place as the issue above.

Another small thing I discovered was that OPCODE_DERIV_RTX is handled, but OPCODE_DERIV_RTX_COARSE and OPCODE_DERIV_RTX_FINE are not. I just added them to the switch cases where they were missing to be handled the same way as OPCODE_DERIV_RTX, and it all worked.

There are a few more problems which I still have not analyzed properly, and I have not yet run any of the produced GLSL shaders so I might have more feedback later.

texelFetch(ld opcodes) assumes swizzles are always in xyzw order

texelFetch(ld opcodes) is assuming that the "operand 2" swizzle is always in the xyzw order
I'm not sure if this problem only occurs in texelFetch it might occur in othe instructions

here's a shader that reproduces the problem(it fetches a texture with a yzw swizzle)


INPUT

uniform sampler2D ITex0;

struct VS_POSTFX_OUT
{
float4 pos : SV_Position;
float2 uv : TEXCOORD0;
};

// pixel shader

struct PS_POSTFX_OUT
{
float4 color : SV_Target;
};

PS_POSTFX_OUT
PS_POSTFX(VS_POSTFX_OUT input)
{
PS_POSTFX_OUT output = (PS_POSTFX_OUT)0;

int3 screenuv = int3(input.pos.x, input.pos.y, 0);
float4 outputcolor = ITex0.Load(screenuv).xyzw;
output.color = float4(outputcolor.yzw, 1.0f);

return output;

}


ASSEMBLY

//
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//
// Resource Bindings:
//
// Name Type Format Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// ITex0 texture float4 2d 0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position 0 xyzw 0 POS float xy
// TEXCOORD 0 xy 1 NONE float
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target 0 xyzw 0 TARGET float xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps_siv linear noperspective v0.xy, position
dcl_output o0.xyzw
dcl_temps 1
0: ftoi r0.xy, v0.xyxx
1: mov r0.zw, l(0,0,0,0)
2: ld_indexable(texture2d)(float,float,float,float) r0.xyz, r0.xyzw, t0.yzwx
3: mov o0.xyz, r0.xyzx
4: mov o0.w, l(1.000000)
5: ret
// Approximately 6 instruction slots used


OUTPUT

subroutine void SubroutineType();
struct vec1 {
float x;
};
struct uvec1 {
uint x;
};
struct ivec1 {
int x;
};
layout(std140) uniform;
uniform sampler2D ITex0;
vec4 Input0;
layout(location = 0) out vec4 SV_Target0;

define Output0 SV_Target0

vec4 Temp[1];
ivec4 Temp_int[1];
uvec4 Temp_uint[1];
void main()
{
//--- Start Early Main ---
Input0.xy = gl_FragCoord.xy;
//--- End Early Main ---
//Instruction 6
//FTOI
Temp_int[0].xy = ivec4(Input0.xyxx).xy;
//Instruction 7
//MOV
Temp_int[0].zw = ivec2(0x0, 0x0);
//Instruction 8
//LD
Temp_int[0].xyz = floatBitsToInt(texelFetch(ITex0, Temp_int[0].xy, 0).xyz); //this should be "texelFetch(ITex0, Temp_int[0].xy, 0).xzw"
//Instruction 9
//MOV
Output0.xyz = intBitsToFloat(Temp_int[0].xyz);
//Instruction 10
//MOV
Output0.w = 1.000000;
//Instruction 11
//RET
return;
}

thank you for your time
Alberto

Uninitialized memory on decode may be misinterpreted in later passes

Hi,

just debugged a wrong shader. Root cause was uninitialized memory of a instruction. I just happened that one operator of an instruction was an input register and its special name was by chance 7 (index id) which resulted in wrong output.

A memset(psInst, 0, sizeof(Instruction) * ui32ShaderLength); after the psInst = hlslcc_malloc(sizeof(Instruction) * ui32ShaderLength); in decode.c (1376) got rid of it.

ld instructions with srcResource swizzling getting compiled incorrectly

This DXASM instruction:
ld_indexable(texture2d)(float,float,float,float) r0.xyw, r3.xyzw, t1.xywz

is getting compiled incorrectly to this GLSL (ignoring the .xywz swizzling of "t1.xywz"):
" Temp[0].xyw = texelFetch(g_t1, ivec2((Temp_int[3]).xy), 0).xyw;\n"

… which I think should be:

" Temp[0].xyw = texelFetch(g_t1, ivec2((Temp_int[3]).xy), 0).xyz;\n"

See http://msdn.microsoft.com/en-us/library/windows/desktop/hh447172(v=vs.85).aspx
"The swizzle on srcResource determines how to swizzle the 4-component result coming back from the texture load, after which .mask on dest determines which components in dest get updated."

Add HLSLcc flag to let users disable bit-cast temp registers

This commit has introduced corruption in multiple GLSL 150 fragment shaders that I have been generating with HLSLcc:
"Bit-cast temp registers - issues #8, #20 and #21"
fa593f4

The previous HLSLcc versions worked fine for me, using SM5 pixel shaders as input and "HLSLcc.exe -lang=150 -flags=1 ...".

Would it be possible for you to add a new HLSLcc flag to let users disable bit-cast temp register strategy for specific shaders (reverting to the old strategy that uses separate arrays of registers for each type)?
This will have the advantage to remove a dependency with GL_ARB_shader_bit_encoding, and hopefully will fix the regression on my end.

StructuredBuffers/SSBO

@James-Jones
Testing a simple structured buffer with float4x4 will result in an invalid GLSL shader with this output:

layout(binding = 0) readonly buffer Block0 {
    mat4 StructuredRes0[];
};

    //LD_STRUCTURED
    Temp[0] = uintBitsToFloat(uvec4(floatBitsToUint(StructuredRes0[0x0].$Element), floatBitsToUint(StructuredRes0[0x0].$Element), floatBitsToUint(StructuredRes0[0x0].$Element), floatBitsToUint(StructuredRes0[0x0].$Element)));

Input HLSL code:

StructuredBuffer<float4x4> WorldTransformData;

VS_OUTPUT main( VS_INPUT IN )
{
    VS_OUTPUT OUT;

    float4 positionOS = float4( IN.PositionIn.xyz, 1.0f );

    float4x4 worldMatrix = WorldTransformData[0];

    float4 positionWS = mul( positionOS, worldMatrix );

    float4 positionCS = mul( positionWS, ViewProjection );

    OUT.Position = positionCS;

    return OUT;
}

InterlockedMin at fixed memory address not translating correctly

HLSL Source
[numthreads(1, 1, 1)]
void CSMain (uint id : SV_DispatchThreadID, RWStructuredBuffer distance)
{
InterlockedMin (distance[2], 6);
}

HLSL ASM
cs_5_0
dcl_globalFlags refactoringAllowed
dcl_uav_structured u0, 4
dcl_thread_group 1, 1, 1
atomic_imin u0, l(2, 0, 0, 0), l(6)
ret

GLSL output from HLSLCrossCompiler

atomicMin(distance[0], 0x6);

It should be distance[2]

Full Output

version 400

extension GL_ARB_compute_shader : enable

extension GL_ARB_shader_storage_buffer_object : enable

extension GL_ARB_shader_atomic_counters : enable

extension GL_ARB_shader_storage_buffer_object : enable

subroutine void SubroutineType();
struct vec1 {
float x;
};
struct uvec1 {
uint x;
};
struct ivec1 {
int x;
};
buffer Block0 {
int distance[];
};
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main()
{
//--- Start Early Main ---
//--- End Early Main ---
//Instruction 0
//ATOMIC_IMIN
atomicMin(distance[0], 0x6);
//Instruction 1
//RET
return;

Linux

Hi,
really great project you are working on!

More of a question than an issue:
Is this supposed to compile (and work) on Linux?
I tried and managed to fix quite some compile errors (mainly missing headers) but failed in the end.

Another (unrelated) thing:
In the tests folder there are some version controlled *.o files. I assume you committed them by accident...

INOT swizzle not matching

I have tried to compile NVIDIAs FXAA implementation pixel shader and I encountered a generation error.

an instruction like this

not r4.yw, r3.zzzw

produces this result

//INOT
Temp_int[0].yw = ~(Temp_int[0].zzzw);

and compilation fails because is assigning a vec4 to a vec2

the original shader is ~2000 lines so I made another shader(that makes no sense) to reproduce the problem(is a ps 5.0).

float4 ImmediatePS(VS_OUT_Immediate input) : SV_TARGET
{
bool4 bools = bool4(input.texUV.x > 0, input.texUV.y > 0, input.texUV.x > 0, input.texUV.y > 0);
bool2 twobools = !bools.xy;
if (twobools.x) {
if (twobools.y) {
input.texUV.x += 7;
}
}
else if (twobools.y == twobools.x)
{
input.texUV.x += 12;
}

return ITex0.Sample(smpLinClamp, input.texUV) * input.color;

}

Alberto

Simplistic shader failing

This shader does not compile with HLSLcc. It is intended for HLSL shader model 4 and I'm trying to convert it to GLSL 410:

Texture2D Tex;
float4 main(float4 pos : SV_Position) : SV_Target
{
int3 texCoord = int3(int2(pos.xy), 0);
return Tex.Load(texCoord);
}

Issues with vs 2015

Hey James; thx for this amazing project :) Problem is that I can't compile the project on my windows machine with visual studio 2015 (as C code); it says that static enums are invalid! Any ideas ?

TODO list?

Hi,
really an interesting project..
not an issue really, but would want to hack on your project in my free time and some guidance into what's missing or a TODO list would be good.. also for example what's missing in compute shader branch for integration into trunk?..

Crash translating hull shader outputs

I've encountered problem with translating hull shaders. GetOutputSignatureFromRegister in AddUserOutput returns a null reference. It appears that there is trouble when join phases have a lot of dcl_output instructions. After 8-10 instructions the register numbers get out of whack and the output signature cannot be retrieved.

Here is source to reproduce the issue, compiled with this command.
fxc.exe /Od /Gec /T hs_5_0 /Fo test.o /E HS_PNTriangles test.hlsl

#line 10 ""
#ifdef DUMMY_PREPROCESSOR_TO_WORK_AROUND_HLSL_COMPILER_LINE_HANDLING
#endif

#line 1 "HLSLSupport.cginc"
#ifndef HLSL_SUPPORT_INCLUDED
#define HLSL_SUPPORT_INCLUDED


#if defined(SHADER_API_D3D11) || defined(SHADER_API_XBOX360) || defined(SHADER_API_D3D11_9X) || defined(VAR_COMPILER_HLSLCC) || defined(SHADER_API_D3D9)
#define VAR_COMPILER_HLSL
#elif defined(SHADER_TARGET_GLSL)
#define VAR_COMPILER_HLSL2GLSL
#else
#define VAR_COMPILER_CG
#endif

#if !defined(SV_Target)
#   if defined(SHADER_API_PSSL)
#       define SV_Target S_TARGET_OUTPUT
#   elif !defined(SHADER_API_XBOXONE)
#       define SV_Target COLOR
#   endif
#endif


#if !defined(SV_Target0)
#   if defined(SHADER_API_PSSL)
#       define SV_Target0 S_TARGET_OUTPUT0
#   elif !defined(SHADER_API_XBOXONE)
#       define SV_Target0 COLOR0
#   endif
#endif


#if !defined(SV_Target1)
#   if defined(SHADER_API_PSSL)
#       define SV_Target1 S_TARGET_OUTPUT1
#   elif !defined(SHADER_API_XBOXONE)
#       define SV_Target1 COLOR1
#   endif
#endif

#if !defined(SV_Target2)
#   if defined(SHADER_API_PSSL)
#       define SV_Target2 S_TARGET_OUTPUT2
#   elif !defined(SHADER_API_XBOXONE)
#       define SV_Target2 COLOR2
#   endif
#endif

#if !defined(SV_Target3)
#   if defined(SHADER_API_PSSL)
#       define SV_Target3 S_TARGET_OUTPUT3
#   elif !defined(SHADER_API_XBOXONE)
#       define SV_Target3 COLOR3
#   endif
#endif



#if !defined(SV_Depth)
#   if defined(SHADER_API_PSSL)
#       define SV_Depth S_DEPTH_OUTPUT
#   elif !defined(SHADER_API_XBOXONE)
#       define SV_Depth DEPTH
#   endif
#endif

#if defined(SHADER_API_PSSL)
// compute shader defines
#define StructuredBuffer RegularBuffer
#define SV_VertexID S_VERTEX_ID

#endif 

#if defined(VAR_COMPILER_HLSL)
#pragma warning (disable : 3205) // conversion of larger type to smaller
#pragma warning (disable : 3568) // unknown pragma ignored
#endif

#if !defined(SHADER_TARGET_GLSL) && !defined(SHADER_API_PSSL)
#define fixed half
#define fixed2 half2
#define fixed3 half3
#define fixed4 half4
#define fixed4x4 half4x4
#define fixed3x3 half3x3
#define fixed2x2 half2x2
#define sampler2D_half sampler2D
#define sampler2D_float sampler2D
#define samplerCUBE_half samplerCUBE
#define samplerCUBE_float samplerCUBE
#endif

#if defined(SHADER_API_PSSL)
#define uniform
#define half float
#define half2 float2
#define half3 float3
#define half4 float4
#define half2x2 float2x2
#define half3x3 float3x3
#define half4x4 float4x4
#define fixed float
#define fixed2 float2
#define fixed3 float3
#define fixed4 float4
#define fixed4x4 half4x4
#define fixed3x3 half3x3
#define fixed2x2 half2x2
#define samplerCUBE_half samplerCUBE
#define samplerCUBE_float samplerCUBE

#define CBUFFER_START(name) ConstantBuffer name {
#define CBUFFER_END };
#elif !defined(VAR_COMPILER_HLSLCC) && (defined(SHADER_API_D3D11) || defined(SHADER_API_D3D11_9X))
#define CBUFFER_START(name) cbuffer name {
#define CBUFFER_END };
#else
#define CBUFFER_START(name)
#define CBUFFER_END
#endif

#if defined(SHADOWS_NATIVE) && defined(SHADER_API_PSSL)
    // PSSL
    #define VAR_DECLARE_SHADOWMAP(tex)      Texture2D tex; SamplerComparisonState sampler##tex
    #define VAR_SAMPLE_SHADOW(tex,coord)        tex.SampleCmpLOD0(sampler##tex,(coord).xy,(coord).z)
    #define VAR_SAMPLE_SHADOW_PROJ(tex,coord)   tex.SampleCmpLOD0(sampler##tex,(coord).xy/(coord).w,(coord).z/(coord).w)
#elif defined(SHADOWS_NATIVE) && (defined(SHADER_API_D3D11) || defined(SHADER_API_D3D11_9X) || defined(VAR_COMPILER_HLSLCC))
    // DX11 syntax for shadow maps
    #define VAR_DECLARE_SHADOWMAP(tex) Texture2D tex; SamplerComparisonState sampler##tex
    #define VAR_SAMPLE_SHADOW(tex,coord) tex.SampleCmpLevelZero (sampler##tex,(coord).xy,(coord).z)
    #define VAR_SAMPLE_SHADOW_PROJ(tex,coord) tex.SampleCmpLevelZero (sampler##tex,(coord).xy/(coord).w,(coord).z/(coord).w)
#elif defined(SHADOWS_NATIVE) && defined(SHADER_TARGET_GLSL)
    // hlsl2glsl syntax for shadow maps
    #define VAR_DECLARE_SHADOWMAP(tex) sampler2DShadow tex
    #define VAR_SAMPLE_SHADOW(tex,coord) shadow2D (tex,(coord).xyz)
    #define VAR_SAMPLE_SHADOW_PROJ(tex,coord) shadow2Dproj (tex,coord)
#elif defined(SHADOWS_NATIVE) && defined(SHADER_API_PSP2) && !defined(SHADER_API_PSM)
    #define VAR_DECLARE_SHADOWMAP(tex) sampler2D tex
    #define VAR_SAMPLE_SHADOW(tex,coord) f1tex2D<float>(tex, (coord).xyz)
    #define VAR_SAMPLE_SHADOW_PROJ(tex,coord) f1tex2Dproj<float>(tex, coord)
#elif defined(SHADOWS_NATIVE) && defined(SHADER_API_D3D9)
    // Native shadow maps hack on D3D9: look just like regular
    // texture sample. Have to always do a projected sample
    // so that HLSL compiler doesn't try to be too smart and mess up swizzles
    // (thinking that Z is unused).
    #define VAR_DECLARE_SHADOWMAP(tex) sampler2D tex
    #define VAR_SAMPLE_SHADOW(tex,coord) tex2Dproj (tex,float4((coord).xyz,1)).r
    #define VAR_SAMPLE_SHADOW_PROJ(tex,coord) tex2Dproj (tex,coord).r
#else
    // Fallback for other platforms: look just like a regular texture sample.
    #define VAR_DECLARE_SHADOWMAP(tex) sampler2D tex
    #define VAR_SAMPLE_SHADOW(tex,coord) tex2D (tex,(coord).xyz).r
    #define VAR_SAMPLE_SHADOW_PROJ(tex,coord) tex2Dproj (tex,coord).r
#endif



// Macros to declare textures and samplers, possibly separately. For platforms
// that have separate samplers & textures (like DX11), and we'd want to conserve
// the samplers.
//  - VAR_DECLARE_TEX2D_NOSAMPLER declares a texture, without a sampler.
//  - VAR_SAMPLE_TEX2D_SAMPLER samples a texture, using sampler from another texture.
//      That another texture must also be actually used in the current shader, otherwise
//      the correct sampler will not be set.
#if defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(VAR_COMPILER_HLSLCC)
#define VAR_DECLARE_TEX2D(tex) Texture2D tex; SamplerState sampler##tex
#define VAR_DECLARE_TEX2D_NOSAMPLER(tex) Texture2D tex
#define VAR_SAMPLE_TEX2D(tex,coord) tex.Sample (sampler##tex,coord)
#define VAR_SAMPLE_TEX2D_SAMPLER(tex,samplertex,coord) tex.Sample (sampler##samplertex,coord)
#else
#define VAR_DECLARE_TEX2D(tex) sampler2D tex
#define VAR_DECLARE_TEX2D_NOSAMPLER(tex) sampler2D tex
#define VAR_SAMPLE_TEX2D(tex,coord) tex2D (tex,coord)
#define VAR_SAMPLE_TEX2D_SAMPLER(tex,samplertex,coord) tex2D (tex,coord)
#endif



#define samplerRECT sampler2D
#define texRECT tex2D
#define texRECTlod tex2Dlod
#define texRECTbias tex2Dbias
#define texRECTproj tex2Dproj

#if defined(SHADER_API_PSSL)
#define VPOS            S_POSITION
#elif defined(VAR_COMPILER_CG)
// Cg seems to use WPOS instead of VPOS semantic?
#define VPOS WPOS
// Cg does not have tex2Dgrad and friends, but has tex2D overload that
// can take the derivatives
#define tex2Dgrad tex2D
#define texCUBEgrad texCUBE
#define tex3Dgrad tex3D
#endif


#if defined(SHADER_API_PSSL)

struct sampler1D {
    Texture1D       t;
    SamplerState    s;
};
struct sampler2D {
    Texture2D       t;
    SamplerState    s;
};
struct sampler2D_float {
    Texture2D       t;
    SamplerState    s;
};
struct sampler3D {
    Texture3D       t;
    SamplerState    s;
};
struct samplerCUBE {
    TextureCube     t;
    SamplerState    s;
};

float4 tex1D(sampler1D x, float v)              { return x.t.Sample(x.s, v); }
float4 tex2D(sampler2D x, float2 v)             { return x.t.Sample(x.s, v); }
float4 tex2D(sampler2D_float x, float2 v)       { return x.t.Sample(x.s, v); }
float4 tex3D(sampler3D x, float3 v)             { return x.t.Sample(x.s, v); }
float4 texCUBE(samplerCUBE x, float3 v)         { return x.t.Sample(x.s, v); }

float4 tex1Dbias(sampler1D x, in float4 t)      { return x.t.SampleBias(x.s, t.x, t.w); }
float4 tex2Dbias(sampler2D x, in float4 t)      { return x.t.SampleBias(x.s, t.xy, t.w); }
float4 tex2Dbias(sampler2D_float x, in float4 t)        { return x.t.SampleBias(x.s, t.xy, t.w); }
float4 tex3Dbias(sampler3D x, in float4 t)      { return x.t.SampleBias(x.s, t.xyz, t.w); }
float4 texCUBEbias(samplerCUBE x, in float4 t)  { return x.t.SampleBias(x.s, t.xyz, t.w); }

float4 tex1Dlod(sampler1D x, in float4 t)       { return x.t.SampleLOD(x.s, t.x, t.w); }
float4 tex2Dlod(sampler2D x, in float4 t)       { return x.t.SampleLOD(x.s, t.xy, t.w); }
float4 tex2Dlod(sampler2D_float x, in float4 t)     { return x.t.SampleLOD(x.s, t.xy, t.w); }
float4 tex3Dlod(sampler3D x, in float4 t)       { return x.t.SampleLOD(x.s, t.xyz, t.w); }
float4 texCUBElod(samplerCUBE x, in float4 t)   { return x.t.SampleLOD(x.s, t.xyz, t.w); }

float4 tex1Dgrad(sampler1D x, float t, float dx, float dy)          { return x.t.SampleGradient(x.s, t, dx, dy); }
float4 tex2Dgrad(sampler2D x, float2 t, float2 dx, float2 dy)       { return x.t.SampleGradient(x.s, t, dx, dy); }
float4 tex2Dgrad(sampler2D_float x, float2 t, float2 dx, float2 dy)     { return x.t.SampleGradient(x.s, t, dx, dy); }
float4 tex3Dgrad(sampler3D x, float3 t, float3 dx, float3 dy)       { return x.t.SampleGradient(x.s, t, dx, dy); }
float4 texCUBEgrad(samplerCUBE x, float3 t, float3 dx, float3 dy)   { return x.t.SampleGradient(x.s, t, dx, dy); }

float4 tex1Dproj(sampler1D s, in float2 t)      { return tex1D(s, t.x / t.y); }
float4 tex1Dproj(sampler1D s, in float4 t)      { return tex1D(s, t.x / t.w); }
float4 tex2Dproj(sampler2D s, in float3 t)      { return tex2D(s, t.xy / t.z); }
float4 tex2Dproj(sampler2D_float s, in float3 t)        { return tex2D(s, t.xy / t.z); }
float4 tex2Dproj(sampler2D s, in float4 t)      { return tex2D(s, t.xy / t.w); }
float4 tex3Dproj(sampler3D s, in float4 t)      { return tex3D(s, t.xyz / t.w); }
float4 texCUBEproj(samplerCUBE s, in float4 t)  { return texCUBE(s, t.xyz / t.w); }

#elif defined(SHADER_API_XBOX360)

float4 tex2Dproj(in sampler2D s, in float4 t) 
{ 
    float2 ti=t.xy / t.w;
    return tex2D( s, ti);
}

float4 tex2Dproj(in sampler2D s, in float3 t) 
{ 
    float2 ti=t.xy / t.z;
    return tex2D( s, ti);
}


#endif

#if defined(VAR_COMPILER_HLSL) || defined (SHADER_TARGET_GLSL)
#define FOGC FOG
#endif

// Use VFACE pixel shader input semantic in your shaders to get front-facing scalar value.
#if defined(VAR_COMPILER_CG)
#define VFACE FACE
#endif
#if defined(VAR_COMPILER_HLSL2GLSL)
#define FACE VFACE
#endif

#if defined(SHADER_API_PSSL)
#define SV_POSITION S_POSITION
#elif !defined(SHADER_API_D3D11) && !defined(SHADER_API_D3D11_9X)
#define SV_POSITION POSITION
#endif


#if (defined(SHADER_API_D3D9) || defined(SHADER_API_XBOX360) || defined(SHADER_API_PS3) || defined(SHADER_API_D3D11) || defined(SHADER_API_D3D11_9X) || defined(SHADER_API_PSP2) || defined(SHADER_API_PSSL)) && !defined(VAR_COMPILER_HLSLCC)
#define VAR_ATTEN_CHANNEL r
#else
#define VAR_ATTEN_CHANNEL a
#endif

#if defined(SHADER_API_D3D9) || defined(SHADER_API_XBOX360) || defined(SHADER_API_PSP2)
#define VAR_HALF_TEXEL_OFFSET
#endif

#if (defined(SHADER_API_D3D9) || defined(SHADER_API_XBOX360) || defined(SHADER_API_PS3) || defined(SHADER_API_D3D11) || defined(SHADER_API_D3D11_9X) || defined(SHADER_API_PSP2) || defined(SHADER_API_PSSL)) && !defined(VAR_COMPILER_HLSLCC)
#define VAR_UV_STARTS_AT_TOP 1
#endif

#if (defined(SHADER_API_D3D9) || defined(SHADER_API_XBOX360) || defined(SHADER_API_PS3) || defined(SHADER_API_D3D11) || defined(SHADER_API_D3D11_9X)) && !defined(VAR_COMPILER_HLSLCC)
#define VAR_NEAR_CLIP_VALUE (0.0)
#else
#define VAR_NEAR_CLIP_VALUE (-1.0)
#endif


#if defined(SHADER_API_D3D9)
#define VAR_MIGHT_NOT_HAVE_DEPTH_TEXTURE
#endif


#if (defined(SHADER_API_OPENGL) && !defined(SHADER_TARGET_GLSL)) || defined(SHADER_API_PSP2)
#define VAR_BUGGY_TEX2DPROJ4
#define VAR_PROJ_COORD(a) (a).xyw
#else
#define VAR_PROJ_COORD(a) a
#endif


// Platforms which do not use cascaded/screenspace shadow maps: more or less "mobile" platforms
#if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3) || defined(SHADER_API_GLES31) || defined(SHADER_API_METAL) || defined(SHADER_API_D3D11_9X)
#define VAR_NO_SCREENSPACE_SHADOWS
#endif

// Platforms which do not use RGBM lightmap compression, or DXT5nm normal map compression
#if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3) || defined(SHADER_API_GLES31) || defined(SHADER_API_METAL)
#define VAR_NO_RGBM
#define VAR_NO_DXT5nm
#endif

// Platforms which can support "framebuffer fetch" on some devices
#if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3) || defined(SHADER_API_GLES31)
#define VAR_FRAMEBUFFER_FETCH_AVAILABLE
#endif


// On most platforms, use floating point render targets to store depth of point
// light shadowmaps. However, on some others they either have issues, or aren't widely
// supported; in which case fallback to encoding depth into RGBA channels.
// Make sure this define matches GraphicsCaps.useRGBAForPointShadows.
#if defined(SHADER_API_GLES) || defined(SHADER_API_PSP2) || defined(SHADER_API_XBOX360) || defined(SHADER_API_PS3)
#define VAR_USE_RGBA_FOR_POINT_SHADOWS
#endif


#if defined(VAR_COMPILER_HLSL) || defined(VAR_COMPILER_HLSLCC)
#define VAR_INITIALIZE_OUTPUT(type,name) name = (type)0;
#else
#define VAR_INITIALIZE_OUTPUT(type,name)
#endif

#if defined(SHADER_API_D3D11) || defined(VAR_COMPILER_HLSLCC)
#define VAR_CAN_COMPILE_TESSELLATION 1
#   define VAR_domain                   domain
#   define VAR_partitioning         partitioning
#   define VAR_outputtopology           outputtopology
#   define VAR_patchconstantfunc        patchconstantfunc
#   define VAR_outputcontrolpoints  outputcontrolpoints
#elif defined(SHADER_API_PSSL)
#   define VAR_CAN_COMPILE_TESSELLATION 1

#   define SV_OutputControlPointID      S_OUTPUT_CONTROL_POINT_ID
#   define SV_TessFactor                S_EDGE_TESS_FACTOR
#   define SV_InsideTessFactor          S_INSIDE_TESS_FACTOR
#   define SV_DomainLocation            S_DOMAIN_LOCATION

#   define VAR_domain                   DOMAIN_PATCH_TYPE
#   define VAR_partitioning         PARTITIONING_TYPE
#   define VAR_outputtopology           OUTPUT_TOPOLOGY_TYPE
#   define VAR_patchconstantfunc        PATCH_CONSTANT_FUNC
#   define VAR_outputcontrolpoints  OUTPUT_CONTROL_POINTS

#   define  domain                      DOMAIN_PATCH_TYPE
#   define  partitioning                PARTITIONING_TYPE
#   define  outputtopology              OUTPUT_TOPOLOGY_TYPE
#   define  patchconstantfunc           PATCH_CONSTANT_FUNC
#   define  outputcontrolpoints         OUTPUT_CONTROL_POINTS

#   define  maxtessfactor               MAX_TESS_FACTOR
#   define  instance                    INSTANCE
#   define  numthreads                  NUM_THREADS
#   define  patchsize                   PATCH_SIZE
#   define  maxvertexcount              MAX_VERTEX_COUNT            
#   define  earlydepthstencil           FORCE_EARLY_DEPTH_STENCIL

#   define  GroupMemoryBarrierWithGroupSync ThreadGroupMemoryBarrierSync

// geometry shader
#   define TriangleStream               TriangleBuffer              
#   define PointStream                  PointBuffer                 
#   define LineStream                   LineBuffer                  
#   define triangle                 Triangle                    
#   define point                        Point                       
#   define line                     Line                        
#   define triangleadj                  AdjacentTriangle            
#   define lineadj                      AdjacentLine

// multimedia operations
#define msad4                       msad

#endif

// Not really needed anymore, but did ship in My 4.0; with D3D11_9X remapping them to .r channel.
// Now that's not used.
#define VAR_SAMPLE_1CHANNEL(x,y) tex2D(x,y).a
#define VAR_ALPHA_CHANNEL a


#endif

#line 13 ""

#line 1 "MyShaderVariables.cginc"
#ifndef VAR_SHADER_VARIABLES_INCLUDED
#define VAR_SHADER_VARIABLES_INCLUDED

#line 1 "HLSLSupport.cginc"
#ifndef HLSL_SUPPORT_INCLUDED
#define HLSL_SUPPORT_INCLUDED


#if defined(SHADER_API_D3D11) || defined(SHADER_API_XBOX360) || defined(SHADER_API_D3D11_9X) || defined(VAR_COMPILER_HLSLCC) || defined(SHADER_API_D3D9)
#define VAR_COMPILER_HLSL
#elif defined(SHADER_TARGET_GLSL)
#define VAR_COMPILER_HLSL2GLSL
#else
#define VAR_COMPILER_CG
#endif

#if !defined(SV_Target)
#   if defined(SHADER_API_PSSL)
#       define SV_Target S_TARGET_OUTPUT
#   elif !defined(SHADER_API_XBOXONE)
#       define SV_Target COLOR
#   endif
#endif


#if !defined(SV_Target0)
#   if defined(SHADER_API_PSSL)
#       define SV_Target0 S_TARGET_OUTPUT0
#   elif !defined(SHADER_API_XBOXONE)
#       define SV_Target0 COLOR0
#   endif
#endif


#if !defined(SV_Target1)
#   if defined(SHADER_API_PSSL)
#       define SV_Target1 S_TARGET_OUTPUT1
#   elif !defined(SHADER_API_XBOXONE)
#       define SV_Target1 COLOR1
#   endif
#endif

#if !defined(SV_Target2)
#   if defined(SHADER_API_PSSL)
#       define SV_Target2 S_TARGET_OUTPUT2
#   elif !defined(SHADER_API_XBOXONE)
#       define SV_Target2 COLOR2
#   endif
#endif

#if !defined(SV_Target3)
#   if defined(SHADER_API_PSSL)
#       define SV_Target3 S_TARGET_OUTPUT3
#   elif !defined(SHADER_API_XBOXONE)
#       define SV_Target3 COLOR3
#   endif
#endif



#if !defined(SV_Depth)
#   if defined(SHADER_API_PSSL)
#       define SV_Depth S_DEPTH_OUTPUT
#   elif !defined(SHADER_API_XBOXONE)
#       define SV_Depth DEPTH
#   endif
#endif

#if defined(SHADER_API_PSSL)
// compute shader defines
#define StructuredBuffer RegularBuffer
#define SV_VertexID S_VERTEX_ID

#endif 

#if defined(VAR_COMPILER_HLSL)
#pragma warning (disable : 3205) // conversion of larger type to smaller
#pragma warning (disable : 3568) // unknown pragma ignored
#endif

#if !defined(SHADER_TARGET_GLSL) && !defined(SHADER_API_PSSL)
#define fixed half
#define fixed2 half2
#define fixed3 half3
#define fixed4 half4
#define fixed4x4 half4x4
#define fixed3x3 half3x3
#define fixed2x2 half2x2
#define sampler2D_half sampler2D
#define sampler2D_float sampler2D
#define samplerCUBE_half samplerCUBE
#define samplerCUBE_float samplerCUBE
#endif

#if defined(SHADER_API_PSSL)
#define uniform
#define half float
#define half2 float2
#define half3 float3
#define half4 float4
#define half2x2 float2x2
#define half3x3 float3x3
#define half4x4 float4x4
#define fixed float
#define fixed2 float2
#define fixed3 float3
#define fixed4 float4
#define fixed4x4 half4x4
#define fixed3x3 half3x3
#define fixed2x2 half2x2
#define samplerCUBE_half samplerCUBE
#define samplerCUBE_float samplerCUBE

#define CBUFFER_START(name) ConstantBuffer name {
#define CBUFFER_END };
#elif !defined(VAR_COMPILER_HLSLCC) && (defined(SHADER_API_D3D11) || defined(SHADER_API_D3D11_9X))
#define CBUFFER_START(name) cbuffer name {
#define CBUFFER_END };
#else
#define CBUFFER_START(name)
#define CBUFFER_END
#endif

#if defined(SHADOWS_NATIVE) && defined(SHADER_API_PSSL)
    // PSSL
    #define VAR_DECLARE_SHADOWMAP(tex)      Texture2D tex; SamplerComparisonState sampler##tex
    #define VAR_SAMPLE_SHADOW(tex,coord)        tex.SampleCmpLOD0(sampler##tex,(coord).xy,(coord).z)
    #define VAR_SAMPLE_SHADOW_PROJ(tex,coord)   tex.SampleCmpLOD0(sampler##tex,(coord).xy/(coord).w,(coord).z/(coord).w)
#elif defined(SHADOWS_NATIVE) && (defined(SHADER_API_D3D11) || defined(SHADER_API_D3D11_9X) || defined(VAR_COMPILER_HLSLCC))
    // DX11 syntax for shadow maps
    #define VAR_DECLARE_SHADOWMAP(tex) Texture2D tex; SamplerComparisonState sampler##tex
    #define VAR_SAMPLE_SHADOW(tex,coord) tex.SampleCmpLevelZero (sampler##tex,(coord).xy,(coord).z)
    #define VAR_SAMPLE_SHADOW_PROJ(tex,coord) tex.SampleCmpLevelZero (sampler##tex,(coord).xy/(coord).w,(coord).z/(coord).w)
#elif defined(SHADOWS_NATIVE) && defined(SHADER_TARGET_GLSL)
    // hlsl2glsl syntax for shadow maps
    #define VAR_DECLARE_SHADOWMAP(tex) sampler2DShadow tex
    #define VAR_SAMPLE_SHADOW(tex,coord) shadow2D (tex,(coord).xyz)
    #define VAR_SAMPLE_SHADOW_PROJ(tex,coord) shadow2Dproj (tex,coord)
#elif defined(SHADOWS_NATIVE) && defined(SHADER_API_PSP2) && !defined(SHADER_API_PSM)
    #define VAR_DECLARE_SHADOWMAP(tex) sampler2D tex
    #define VAR_SAMPLE_SHADOW(tex,coord) f1tex2D<float>(tex, (coord).xyz)
    #define VAR_SAMPLE_SHADOW_PROJ(tex,coord) f1tex2Dproj<float>(tex, coord)
#elif defined(SHADOWS_NATIVE) && defined(SHADER_API_D3D9)
    // Native shadow maps hack on D3D9: look just like regular
    // texture sample. Have to always do a projected sample
    // so that HLSL compiler doesn't try to be too smart and mess up swizzles
    // (thinking that Z is unused).
    #define VAR_DECLARE_SHADOWMAP(tex) sampler2D tex
    #define VAR_SAMPLE_SHADOW(tex,coord) tex2Dproj (tex,float4((coord).xyz,1)).r
    #define VAR_SAMPLE_SHADOW_PROJ(tex,coord) tex2Dproj (tex,coord).r
#else
    // Fallback for other platforms: look just like a regular texture sample.
    #define VAR_DECLARE_SHADOWMAP(tex) sampler2D tex
    #define VAR_SAMPLE_SHADOW(tex,coord) tex2D (tex,(coord).xyz).r
    #define VAR_SAMPLE_SHADOW_PROJ(tex,coord) tex2Dproj (tex,coord).r
#endif



// Macros to declare textures and samplers, possibly separately. For platforms
// that have separate samplers & textures (like DX11), and we'd want to conserve
// the samplers.
//  - VAR_DECLARE_TEX2D_NOSAMPLER declares a texture, without a sampler.
//  - VAR_SAMPLE_TEX2D_SAMPLER samples a texture, using sampler from another texture.
//      That another texture must also be actually used in the current shader, otherwise
//      the correct sampler will not be set.
#if defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(VAR_COMPILER_HLSLCC)
#define VAR_DECLARE_TEX2D(tex) Texture2D tex; SamplerState sampler##tex
#define VAR_DECLARE_TEX2D_NOSAMPLER(tex) Texture2D tex
#define VAR_SAMPLE_TEX2D(tex,coord) tex.Sample (sampler##tex,coord)
#define VAR_SAMPLE_TEX2D_SAMPLER(tex,samplertex,coord) tex.Sample (sampler##samplertex,coord)
#else
#define VAR_DECLARE_TEX2D(tex) sampler2D tex
#define VAR_DECLARE_TEX2D_NOSAMPLER(tex) sampler2D tex
#define VAR_SAMPLE_TEX2D(tex,coord) tex2D (tex,coord)
#define VAR_SAMPLE_TEX2D_SAMPLER(tex,samplertex,coord) tex2D (tex,coord)
#endif



#define samplerRECT sampler2D
#define texRECT tex2D
#define texRECTlod tex2Dlod
#define texRECTbias tex2Dbias
#define texRECTproj tex2Dproj

#if defined(SHADER_API_PSSL)
#define VPOS            S_POSITION
#elif defined(VAR_COMPILER_CG)
// Cg seems to use WPOS instead of VPOS semantic?
#define VPOS WPOS
// Cg does not have tex2Dgrad and friends, but has tex2D overload that
// can take the derivatives
#define tex2Dgrad tex2D
#define texCUBEgrad texCUBE
#define tex3Dgrad tex3D
#endif


#if defined(SHADER_API_PSSL)

struct sampler1D {
    Texture1D       t;
    SamplerState    s;
};
struct sampler2D {
    Texture2D       t;
    SamplerState    s;
};
struct sampler2D_float {
    Texture2D       t;
    SamplerState    s;
};
struct sampler3D {
    Texture3D       t;
    SamplerState    s;
};
struct samplerCUBE {
    TextureCube     t;
    SamplerState    s;
};

float4 tex1D(sampler1D x, float v)              { return x.t.Sample(x.s, v); }
float4 tex2D(sampler2D x, float2 v)             { return x.t.Sample(x.s, v); }
float4 tex2D(sampler2D_float x, float2 v)       { return x.t.Sample(x.s, v); }
float4 tex3D(sampler3D x, float3 v)             { return x.t.Sample(x.s, v); }
float4 texCUBE(samplerCUBE x, float3 v)         { return x.t.Sample(x.s, v); }

float4 tex1Dbias(sampler1D x, in float4 t)      { return x.t.SampleBias(x.s, t.x, t.w); }
float4 tex2Dbias(sampler2D x, in float4 t)      { return x.t.SampleBias(x.s, t.xy, t.w); }
float4 tex2Dbias(sampler2D_float x, in float4 t)        { return x.t.SampleBias(x.s, t.xy, t.w); }
float4 tex3Dbias(sampler3D x, in float4 t)      { return x.t.SampleBias(x.s, t.xyz, t.w); }
float4 texCUBEbias(samplerCUBE x, in float4 t)  { return x.t.SampleBias(x.s, t.xyz, t.w); }

float4 tex1Dlod(sampler1D x, in float4 t)       { return x.t.SampleLOD(x.s, t.x, t.w); }
float4 tex2Dlod(sampler2D x, in float4 t)       { return x.t.SampleLOD(x.s, t.xy, t.w); }
float4 tex2Dlod(sampler2D_float x, in float4 t)     { return x.t.SampleLOD(x.s, t.xy, t.w); }
float4 tex3Dlod(sampler3D x, in float4 t)       { return x.t.SampleLOD(x.s, t.xyz, t.w); }
float4 texCUBElod(samplerCUBE x, in float4 t)   { return x.t.SampleLOD(x.s, t.xyz, t.w); }

float4 tex1Dgrad(sampler1D x, float t, float dx, float dy)          { return x.t.SampleGradient(x.s, t, dx, dy); }
float4 tex2Dgrad(sampler2D x, float2 t, float2 dx, float2 dy)       { return x.t.SampleGradient(x.s, t, dx, dy); }
float4 tex2Dgrad(sampler2D_float x, float2 t, float2 dx, float2 dy)     { return x.t.SampleGradient(x.s, t, dx, dy); }
float4 tex3Dgrad(sampler3D x, float3 t, float3 dx, float3 dy)       { return x.t.SampleGradient(x.s, t, dx, dy); }
float4 texCUBEgrad(samplerCUBE x, float3 t, float3 dx, float3 dy)   { return x.t.SampleGradient(x.s, t, dx, dy); }

float4 tex1Dproj(sampler1D s, in float2 t)      { return tex1D(s, t.x / t.y); }
float4 tex1Dproj(sampler1D s, in float4 t)      { return tex1D(s, t.x / t.w); }
float4 tex2Dproj(sampler2D s, in float3 t)      { return tex2D(s, t.xy / t.z); }
float4 tex2Dproj(sampler2D_float s, in float3 t)        { return tex2D(s, t.xy / t.z); }
float4 tex2Dproj(sampler2D s, in float4 t)      { return tex2D(s, t.xy / t.w); }
float4 tex3Dproj(sampler3D s, in float4 t)      { return tex3D(s, t.xyz / t.w); }
float4 texCUBEproj(samplerCUBE s, in float4 t)  { return texCUBE(s, t.xyz / t.w); }

#elif defined(SHADER_API_XBOX360)

float4 tex2Dproj(in sampler2D s, in float4 t) 
{ 
    float2 ti=t.xy / t.w;
    return tex2D( s, ti);
}

float4 tex2Dproj(in sampler2D s, in float3 t) 
{ 
    float2 ti=t.xy / t.z;
    return tex2D( s, ti);
}


#endif

#if defined(VAR_COMPILER_HLSL) || defined (SHADER_TARGET_GLSL)
#define FOGC FOG
#endif

// Use VFACE pixel shader input semantic in your shaders to get front-facing scalar value.
#if defined(VAR_COMPILER_CG)
#define VFACE FACE
#endif
#if defined(VAR_COMPILER_HLSL2GLSL)
#define FACE VFACE
#endif

#if defined(SHADER_API_PSSL)
#define SV_POSITION S_POSITION
#elif !defined(SHADER_API_D3D11) && !defined(SHADER_API_D3D11_9X)
#define SV_POSITION POSITION
#endif


#if (defined(SHADER_API_D3D9) || defined(SHADER_API_XBOX360) || defined(SHADER_API_PS3) || defined(SHADER_API_D3D11) || defined(SHADER_API_D3D11_9X) || defined(SHADER_API_PSP2) || defined(SHADER_API_PSSL)) && !defined(VAR_COMPILER_HLSLCC)
#define VAR_ATTEN_CHANNEL r
#else
#define VAR_ATTEN_CHANNEL a
#endif

#if defined(SHADER_API_D3D9) || defined(SHADER_API_XBOX360) || defined(SHADER_API_PSP2)
#define VAR_HALF_TEXEL_OFFSET
#endif

#if (defined(SHADER_API_D3D9) || defined(SHADER_API_XBOX360) || defined(SHADER_API_PS3) || defined(SHADER_API_D3D11) || defined(SHADER_API_D3D11_9X) || defined(SHADER_API_PSP2) || defined(SHADER_API_PSSL)) && !defined(VAR_COMPILER_HLSLCC)
#define VAR_UV_STARTS_AT_TOP 1
#endif

#if (defined(SHADER_API_D3D9) || defined(SHADER_API_XBOX360) || defined(SHADER_API_PS3) || defined(SHADER_API_D3D11) || defined(SHADER_API_D3D11_9X)) && !defined(VAR_COMPILER_HLSLCC)
#define VAR_NEAR_CLIP_VALUE (0.0)
#else
#define VAR_NEAR_CLIP_VALUE (-1.0)
#endif


#if defined(SHADER_API_D3D9)
#define VAR_MIGHT_NOT_HAVE_DEPTH_TEXTURE
#endif


#if (defined(SHADER_API_OPENGL) && !defined(SHADER_TARGET_GLSL)) || defined(SHADER_API_PSP2)
#define VAR_BUGGY_TEX2DPROJ4
#define VAR_PROJ_COORD(a) (a).xyw
#else
#define VAR_PROJ_COORD(a) a
#endif


// Platforms which do not use cascaded/screenspace shadow maps: more or less "mobile" platforms
#if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3) || defined(SHADER_API_GLES31) || defined(SHADER_API_METAL) || defined(SHADER_API_D3D11_9X)
#define VAR_NO_SCREENSPACE_SHADOWS
#endif

// Platforms which do not use RGBM lightmap compression, or DXT5nm normal map compression
#if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3) || defined(SHADER_API_GLES31) || defined(SHADER_API_METAL)
#define VAR_NO_RGBM
#define VAR_NO_DXT5nm
#endif

// Platforms which can support "framebuffer fetch" on some devices
#if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3) || defined(SHADER_API_GLES31)
#define VAR_FRAMEBUFFER_FETCH_AVAILABLE
#endif


// On most platforms, use floating point render targets to store depth of point
// light shadowmaps. However, on some others they either have issues, or aren't widely
// supported; in which case fallback to encoding depth into RGBA channels.
// Make sure this define matches GraphicsCaps.useRGBAForPointShadows.
#if defined(SHADER_API_GLES) || defined(SHADER_API_PSP2) || defined(SHADER_API_XBOX360) || defined(SHADER_API_PS3)
#define VAR_USE_RGBA_FOR_POINT_SHADOWS
#endif


#if defined(VAR_COMPILER_HLSL) || defined(VAR_COMPILER_HLSLCC)
#define VAR_INITIALIZE_OUTPUT(type,name) name = (type)0;
#else
#define VAR_INITIALIZE_OUTPUT(type,name)
#endif

#if defined(SHADER_API_D3D11) || defined(VAR_COMPILER_HLSLCC)
#define VAR_CAN_COMPILE_TESSELLATION 1
#   define VAR_domain                   domain
#   define VAR_partitioning         partitioning
#   define VAR_outputtopology           outputtopology
#   define VAR_patchconstantfunc        patchconstantfunc
#   define VAR_outputcontrolpoints  outputcontrolpoints
#elif defined(SHADER_API_PSSL)
#   define VAR_CAN_COMPILE_TESSELLATION 1

#   define SV_OutputControlPointID      S_OUTPUT_CONTROL_POINT_ID
#   define SV_TessFactor                S_EDGE_TESS_FACTOR
#   define SV_InsideTessFactor          S_INSIDE_TESS_FACTOR
#   define SV_DomainLocation            S_DOMAIN_LOCATION

#   define VAR_domain                   DOMAIN_PATCH_TYPE
#   define VAR_partitioning         PARTITIONING_TYPE
#   define VAR_outputtopology           OUTPUT_TOPOLOGY_TYPE
#   define VAR_patchconstantfunc        PATCH_CONSTANT_FUNC
#   define VAR_outputcontrolpoints  OUTPUT_CONTROL_POINTS

#   define  domain                      DOMAIN_PATCH_TYPE
#   define  partitioning                PARTITIONING_TYPE
#   define  outputtopology              OUTPUT_TOPOLOGY_TYPE
#   define  patchconstantfunc           PATCH_CONSTANT_FUNC
#   define  outputcontrolpoints         OUTPUT_CONTROL_POINTS

#   define  maxtessfactor               MAX_TESS_FACTOR
#   define  instance                    INSTANCE
#   define  numthreads                  NUM_THREADS
#   define  patchsize                   PATCH_SIZE
#   define  maxvertexcount              MAX_VERTEX_COUNT            
#   define  earlydepthstencil           FORCE_EARLY_DEPTH_STENCIL

#   define  GroupMemoryBarrierWithGroupSync ThreadGroupMemoryBarrierSync

// geometry shader
#   define TriangleStream               TriangleBuffer              
#   define PointStream                  PointBuffer                 
#   define LineStream                   LineBuffer                  
#   define triangle                 Triangle                    
#   define point                        Point                       
#   define line                     Line                        
#   define triangleadj                  AdjacentTriangle            
#   define lineadj                      AdjacentLine

// multimedia operations
#define msad4                       msad

#endif

// Not really needed anymore, but did ship in My 4.0; with D3D11_9X remapping them to .r channel.
// Now that's not used.
#define VAR_SAMPLE_1CHANNEL(x,y) tex2D(x,y).a
#define VAR_ALPHA_CHANNEL a


#endif

#line 4 "MyShaderVariables.cginc"


#if defined (DIRECTIONAL_COOKIE) || defined (DIRECTIONAL)
#define USING_DIRECTIONAL_LIGHT
#endif



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

CBUFFER_START(MyPerCamera)
    // Time values from My
    uniform float4 _Time;
    uniform float4 _SinTime;
    uniform float4 _CosTime;
    uniform float4 var_DeltaTime; // dt, 1/dt, smoothdt, 1/smoothdt

    uniform float3 _WorldSpaceCameraPos;

    // x = 1 or -1 (-1 if projection is flipped)
    // y = near plane
    // z = far plane
    // w = 1/far plane
    uniform float4 _ProjectionParams;

    // x = width
    // y = height
    // z = 1 + 1.0/width
    // w = 1 + 1.0/height
    uniform float4 _ScreenParams;

    uniform float4 _ZBufferParams;

    // x = orthographic camera's width
    // y = orthographic camera's height
    // z = unused
    // w = 1.0 if camera is ortho, 0.0 if perspective
    uniform float4 var_OrthoParams;
CBUFFER_END


CBUFFER_START(MyPerCameraRare)
    uniform float4 var_CameraWorldClipPlanes[6];

    // Projection matrices of the camera. Note that this might be different from projection matrix
    // that is set right now, e.g. while rendering shadows the matrices below are still the projection
    // of original camera.
    uniform float4x4 var_CameraProjection;
    uniform float4x4 var_CameraInvProjection;
CBUFFER_END



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

CBUFFER_START(MyLighting)

    #ifdef USING_DIRECTIONAL_LIGHT
    uniform half4 _WorldSpaceLightPos0;
    #else
    uniform float4 _WorldSpaceLightPos0;
    #endif

    uniform float4 _LightPositionRange; // xyz = pos, w = 1/range

    float4 var_4LightPosX0;
    float4 var_4LightPosY0;
    float4 var_4LightPosZ0;
    half4 var_4LightAtten0;

    half4 var_LightColor[8];
    float4 var_LightPosition[8];
    // x = -1
    // y = 1
    // z = quadratic attenuation
    // w = range^2
    half4 var_LightAtten[8];
    float4 var_SpotDirection[8];

    // SH lighting environment
    half4 var_SHAr;
    half4 var_SHAg;
    half4 var_SHAb;
    half4 var_SHBr;
    half4 var_SHBg;
    half4 var_SHBb;
    half4 var_SHC;
CBUFFER_END

CBUFFER_START(MyLightingOld)
    half3 var_LightColor0, var_LightColor1, var_LightColor2, var_LightColor3; // keeping those only for any existing shaders; remove in 4.0
CBUFFER_END


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

CBUFFER_START(MyShadows)
    float4 var_ShadowSplitSpheres[4];
    float4 var_ShadowSplitSqRadii;
    float4 var_LightShadowBias;
    float4 _LightSplitsNear;
    float4 _LightSplitsFar;
    float4x4 var_World2Shadow[4];
    half4 _LightShadowData;
    float4 var_ShadowFadeCenterAndType;
CBUFFER_END

#define _World2Shadow var_World2Shadow[0]
#define _World2Shadow1 var_World2Shadow[1]
#define _World2Shadow2 var_World2Shadow[2]
#define _World2Shadow3 var_World2Shadow[3]


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

CBUFFER_START(MyPerDraw)
    float4x4 glstate_matrix_mvp;
    float4x4 glstate_matrix_modelview0;
    float4x4 glstate_matrix_invtrans_modelview0;
    #define VAR_MATRIX_MVP glstate_matrix_mvp
    #define VAR_MATRIX_MV glstate_matrix_modelview0
    #define VAR_MATRIX_IT_MV glstate_matrix_invtrans_modelview0

    uniform float4x4 _Object2World;
    uniform float4x4 _World2Object;
    uniform float4 var_LODFade; // x is the fade value ranging within [0,1]. y is x quantized into 16 levels
CBUFFER_END




CBUFFER_START(MyPerDrawRare)
    float4x4 glstate_matrix_transpose_modelview0;
    #define VAR_MATRIX_T_MV glstate_matrix_transpose_modelview0
CBUFFER_END



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

CBUFFER_START(MyPerFrame)

    float4x4 glstate_matrix_projection;
    float4   glstate_lightmodel_ambient;
    #define VAR_MATRIX_P glstate_matrix_projection
    #define VAR_LIGHTMODEL_AMBIENT glstate_lightmodel_ambient

    float4x4 var_MatrixV;
    float4x4 var_MatrixVP;
    #define VAR_MATRIX_V var_MatrixV
    #define VAR_MATRIX_VP var_MatrixVP

    fixed4 var_AmbientSky;
    fixed4 var_AmbientGround;

CBUFFER_END


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

CBUFFER_START(MyFog)
    uniform fixed4 var_FogColor;
    // x = density / sqrt(ln(2)), useful for Exp2 mode
    // y = density / ln(2), useful for Exp mode
    // z = -1/(end-start), useful for Linear mode
    // w = end/(end-start), useful for Linear mode
    uniform float4 var_FogParams;
CBUFFER_END


// ----------------------------------------------------------------------------
//  Deprecated

// There used to be fixed function-like texture matrices, defined as VAR_MATRIX_TEXTUREn. These are gone now; and are just defined to identity.
#define VAR_MATRIX_TEXTURE0 float4x4(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1)
#define VAR_MATRIX_TEXTURE1 float4x4(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1)
#define VAR_MATRIX_TEXTURE2 float4x4(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1)
#define VAR_MATRIX_TEXTURE3 float4x4(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1)


#endif

#line 14 ""

#line 10 ""
#ifdef DUMMY_PREPROCESSOR_TO_WORK_AROUND_HLSL_COMPILER_LINE_HANDLING
#endif

// #pragma target 5.0

//// #pragma vertex VS_RenderScene
//// #pragma fragment PS_RenderSceneTextured

// #pragma vertex VS_RenderSceneWithTessellation
// #pragma fragment PS_RenderSceneTextured
// #pragma hull HS_PNTriangles
// #pragma domain DS_PNTriangles

#line 1 "MyCG.cginc"
#ifndef VAR_CG_INCLUDED
#define VAR_CG_INCLUDED

#line 1 "MyShaderVariables.cginc"
#ifndef VAR_SHADER_VARIABLES_INCLUDED
#define VAR_SHADER_VARIABLES_INCLUDED

#line 1 "HLSLSupport.cginc"
#ifndef HLSL_SUPPORT_INCLUDED
#define HLSL_SUPPORT_INCLUDED


#if defined(SHADER_API_D3D11) || defined(SHADER_API_XBOX360) || defined(SHADER_API_D3D11_9X) || defined(VAR_COMPILER_HLSLCC) || defined(SHADER_API_D3D9)
#define VAR_COMPILER_HLSL
#elif defined(SHADER_TARGET_GLSL)
#define VAR_COMPILER_HLSL2GLSL
#else
#define VAR_COMPILER_CG
#endif

#if !defined(SV_Target)
#   if defined(SHADER_API_PSSL)
#       define SV_Target S_TARGET_OUTPUT
#   elif !defined(SHADER_API_XBOXONE)
#       define SV_Target COLOR
#   endif
#endif


#if !defined(SV_Target0)
#   if defined(SHADER_API_PSSL)
#       define SV_Target0 S_TARGET_OUTPUT0
#   elif !defined(SHADER_API_XBOXONE)
#       define SV_Target0 COLOR0
#   endif
#endif


#if !defined(SV_Target1)
#   if defined(SHADER_API_PSSL)
#       define SV_Target1 S_TARGET_OUTPUT1
#   elif !defined(SHADER_API_XBOXONE)
#       define SV_Target1 COLOR1
#   endif
#endif

#if !defined(SV_Target2)
#   if defined(SHADER_API_PSSL)
#       define SV_Target2 S_TARGET_OUTPUT2
#   elif !defined(SHADER_API_XBOXONE)
#       define SV_Target2 COLOR2
#   endif
#endif

#if !defined(SV_Target3)
#   if defined(SHADER_API_PSSL)
#       define SV_Target3 S_TARGET_OUTPUT3
#   elif !defined(SHADER_API_XBOXONE)
#       define SV_Target3 COLOR3
#   endif
#endif



#if !defined(SV_Depth)
#   if defined(SHADER_API_PSSL)
#       define SV_Depth S_DEPTH_OUTPUT
#   elif !defined(SHADER_API_XBOXONE)
#       define SV_Depth DEPTH
#   endif
#endif

#if defined(SHADER_API_PSSL)
// compute shader defines
#define StructuredBuffer RegularBuffer
#define SV_VertexID S_VERTEX_ID

#endif 

#if defined(VAR_COMPILER_HLSL)
#pragma warning (disable : 3205) // conversion of larger type to smaller
#pragma warning (disable : 3568) // unknown pragma ignored
#endif

#if !defined(SHADER_TARGET_GLSL) && !defined(SHADER_API_PSSL)
#define fixed half
#define fixed2 half2
#define fixed3 half3
#define fixed4 half4
#define fixed4x4 half4x4
#define fixed3x3 half3x3
#define fixed2x2 half2x2
#define sampler2D_half sampler2D
#define sampler2D_float sampler2D
#define samplerCUBE_half samplerCUBE
#define samplerCUBE_float samplerCUBE
#endif

#if defined(SHADER_API_PSSL)
#define uniform
#define half float
#define half2 float2
#define half3 float3
#define half4 float4
#define half2x2 float2x2
#define half3x3 float3x3
#define half4x4 float4x4
#define fixed float
#define fixed2 float2
#define fixed3 float3
#define fixed4 float4
#define fixed4x4 half4x4
#define fixed3x3 half3x3
#define fixed2x2 half2x2
#define samplerCUBE_half samplerCUBE
#define samplerCUBE_float samplerCUBE

#define CBUFFER_START(name) ConstantBuffer name {
#define CBUFFER_END };
#elif !defined(VAR_COMPILER_HLSLCC) && (defined(SHADER_API_D3D11) || defined(SHADER_API_D3D11_9X))
#define CBUFFER_START(name) cbuffer name {
#define CBUFFER_END };
#else
#define CBUFFER_START(name)
#define CBUFFER_END
#endif

#if defined(SHADOWS_NATIVE) && defined(SHADER_API_PSSL)
    // PSSL
    #define VAR_DECLARE_SHADOWMAP(tex)      Texture2D tex; SamplerComparisonState sampler##tex
    #define VAR_SAMPLE_SHADOW(tex,coord)        tex.SampleCmpLOD0(sampler##tex,(coord).xy,(coord).z)
    #define VAR_SAMPLE_SHADOW_PROJ(tex,coord)   tex.SampleCmpLOD0(sampler##tex,(coord).xy/(coord).w,(coord).z/(coord).w)
#elif defined(SHADOWS_NATIVE) && (defined(SHADER_API_D3D11) || defined(SHADER_API_D3D11_9X) || defined(VAR_COMPILER_HLSLCC))
    // DX11 syntax for shadow maps
    #define VAR_DECLARE_SHADOWMAP(tex) Texture2D tex; SamplerComparisonState sampler##tex
    #define VAR_SAMPLE_SHADOW(tex,coord) tex.SampleCmpLevelZero (sampler##tex,(coord).xy,(coord).z)
    #define VAR_SAMPLE_SHADOW_PROJ(tex,coord) tex.SampleCmpLevelZero (sampler##tex,(coord).xy/(coord).w,(coord).z/(coord).w)
#elif defined(SHADOWS_NATIVE) && defined(SHADER_TARGET_GLSL)
    // hlsl2glsl syntax for shadow maps
    #define VAR_DECLARE_SHADOWMAP(tex) sampler2DShadow tex
    #define VAR_SAMPLE_SHADOW(tex,coord) shadow2D (tex,(coord).xyz)
    #define VAR_SAMPLE_SHADOW_PROJ(tex,coord) shadow2Dproj (tex,coord)
#elif defined(SHADOWS_NATIVE) && defined(SHADER_API_PSP2) && !defined(SHADER_API_PSM)
    #define VAR_DECLARE_SHADOWMAP(tex) sampler2D tex
    #define VAR_SAMPLE_SHADOW(tex,coord) f1tex2D<float>(tex, (coord).xyz)
    #define VAR_SAMPLE_SHADOW_PROJ(tex,coord) f1tex2Dproj<float>(tex, coord)
#elif defined(SHADOWS_NATIVE) && defined(SHADER_API_D3D9)
    // Native shadow maps hack on D3D9: look just like regular
    // texture sample. Have to always do a projected sample
    // so that HLSL compiler doesn't try to be too smart and mess up swizzles
    // (thinking that Z is unused).
    #define VAR_DECLARE_SHADOWMAP(tex) sampler2D tex
    #define VAR_SAMPLE_SHADOW(tex,coord) tex2Dproj (tex,float4((coord).xyz,1)).r
    #define VAR_SAMPLE_SHADOW_PROJ(tex,coord) tex2Dproj (tex,coord).r
#else
    // Fallback for other platforms: look just like a regular texture sample.
    #define VAR_DECLARE_SHADOWMAP(tex) sampler2D tex
    #define VAR_SAMPLE_SHADOW(tex,coord) tex2D (tex,(coord).xyz).r
    #define VAR_SAMPLE_SHADOW_PROJ(tex,coord) tex2Dproj (tex,coord).r
#endif



// Macros to declare textures and samplers, possibly separately. For platforms
// that have separate samplers & textures (like DX11), and we'd want to conserve
// the samplers.
//  - VAR_DECLARE_TEX2D_NOSAMPLER declares a texture, without a sampler.
//  - VAR_SAMPLE_TEX2D_SAMPLER samples a texture, using sampler from another texture.
//      That another texture must also be actually used in the current shader, otherwise
//      the correct sampler will not be set.
#if defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(VAR_COMPILER_HLSLCC)
#define VAR_DECLARE_TEX2D(tex) Texture2D tex; SamplerState sampler##tex
#define VAR_DECLARE_TEX2D_NOSAMPLER(tex) Texture2D tex
#define VAR_SAMPLE_TEX2D(tex,coord) tex.Sample (sampler##tex,coord)
#define VAR_SAMPLE_TEX2D_SAMPLER(tex,samplertex,coord) tex.Sample (sampler##samplertex,coord)
#else
#define VAR_DECLARE_TEX2D(tex) sampler2D tex
#define VAR_DECLARE_TEX2D_NOSAMPLER(tex) sampler2D tex
#define VAR_SAMPLE_TEX2D(tex,coord) tex2D (tex,coord)
#define VAR_SAMPLE_TEX2D_SAMPLER(tex,samplertex,coord) tex2D (tex,coord)
#endif



#define samplerRECT sampler2D
#define texRECT tex2D
#define texRECTlod tex2Dlod
#define texRECTbias tex2Dbias
#define texRECTproj tex2Dproj

#if defined(SHADER_API_PSSL)
#define VPOS            S_POSITION
#elif defined(VAR_COMPILER_CG)
// Cg seems to use WPOS instead of VPOS semantic?
#define VPOS WPOS
// Cg does not have tex2Dgrad and friends, but has tex2D overload that
// can take the derivatives
#define tex2Dgrad tex2D
#define texCUBEgrad texCUBE
#define tex3Dgrad tex3D
#endif


#if defined(SHADER_API_PSSL)

struct sampler1D {
    Texture1D       t;
    SamplerState    s;
};
struct sampler2D {
    Texture2D       t;
    SamplerState    s;
};
struct sampler2D_float {
    Texture2D       t;
    SamplerState    s;
};
struct sampler3D {
    Texture3D       t;
    SamplerState    s;
};
struct samplerCUBE {
    TextureCube     t;
    SamplerState    s;
};

float4 tex1D(sampler1D x, float v)              { return x.t.Sample(x.s, v); }
float4 tex2D(sampler2D x, float2 v)             { return x.t.Sample(x.s, v); }
float4 tex2D(sampler2D_float x, float2 v)       { return x.t.Sample(x.s, v); }
float4 tex3D(sampler3D x, float3 v)             { return x.t.Sample(x.s, v); }
float4 texCUBE(samplerCUBE x, float3 v)         { return x.t.Sample(x.s, v); }

float4 tex1Dbias(sampler1D x, in float4 t)      { return x.t.SampleBias(x.s, t.x, t.w); }
float4 tex2Dbias(sampler2D x, in float4 t)      { return x.t.SampleBias(x.s, t.xy, t.w); }
float4 tex2Dbias(sampler2D_float x, in float4 t)        { return x.t.SampleBias(x.s, t.xy, t.w); }
float4 tex3Dbias(sampler3D x, in float4 t)      { return x.t.SampleBias(x.s, t.xyz, t.w); }
float4 texCUBEbias(samplerCUBE x, in float4 t)  { return x.t.SampleBias(x.s, t.xyz, t.w); }

float4 tex1Dlod(sampler1D x, in float4 t)       { return x.t.SampleLOD(x.s, t.x, t.w); }
float4 tex2Dlod(sampler2D x, in float4 t)       { return x.t.SampleLOD(x.s, t.xy, t.w); }
float4 tex2Dlod(sampler2D_float x, in float4 t)     { return x.t.SampleLOD(x.s, t.xy, t.w); }
float4 tex3Dlod(sampler3D x, in float4 t)       { return x.t.SampleLOD(x.s, t.xyz, t.w); }
float4 texCUBElod(samplerCUBE x, in float4 t)   { return x.t.SampleLOD(x.s, t.xyz, t.w); }

float4 tex1Dgrad(sampler1D x, float t, float dx, float dy)          { return x.t.SampleGradient(x.s, t, dx, dy); }
float4 tex2Dgrad(sampler2D x, float2 t, float2 dx, float2 dy)       { return x.t.SampleGradient(x.s, t, dx, dy); }
float4 tex2Dgrad(sampler2D_float x, float2 t, float2 dx, float2 dy)     { return x.t.SampleGradient(x.s, t, dx, dy); }
float4 tex3Dgrad(sampler3D x, float3 t, float3 dx, float3 dy)       { return x.t.SampleGradient(x.s, t, dx, dy); }
float4 texCUBEgrad(samplerCUBE x, float3 t, float3 dx, float3 dy)   { return x.t.SampleGradient(x.s, t, dx, dy); }

float4 tex1Dproj(sampler1D s, in float2 t)      { return tex1D(s, t.x / t.y); }
float4 tex1Dproj(sampler1D s, in float4 t)      { return tex1D(s, t.x / t.w); }
float4 tex2Dproj(sampler2D s, in float3 t)      { return tex2D(s, t.xy / t.z); }
float4 tex2Dproj(sampler2D_float s, in float3 t)        { return tex2D(s, t.xy / t.z); }
float4 tex2Dproj(sampler2D s, in float4 t)      { return tex2D(s, t.xy / t.w); }
float4 tex3Dproj(sampler3D s, in float4 t)      { return tex3D(s, t.xyz / t.w); }
float4 texCUBEproj(samplerCUBE s, in float4 t)  { return texCUBE(s, t.xyz / t.w); }

#elif defined(SHADER_API_XBOX360)

float4 tex2Dproj(in sampler2D s, in float4 t) 
{ 
    float2 ti=t.xy / t.w;
    return tex2D( s, ti);
}

float4 tex2Dproj(in sampler2D s, in float3 t) 
{ 
    float2 ti=t.xy / t.z;
    return tex2D( s, ti);
}


#endif

#if defined(VAR_COMPILER_HLSL) || defined (SHADER_TARGET_GLSL)
#define FOGC FOG
#endif

// Use VFACE pixel shader input semantic in your shaders to get front-facing scalar value.
#if defined(VAR_COMPILER_CG)
#define VFACE FACE
#endif
#if defined(VAR_COMPILER_HLSL2GLSL)
#define FACE VFACE
#endif

#if defined(SHADER_API_PSSL)
#define SV_POSITION S_POSITION
#elif !defined(SHADER_API_D3D11) && !defined(SHADER_API_D3D11_9X)
#define SV_POSITION POSITION
#endif


#if (defined(SHADER_API_D3D9) || defined(SHADER_API_XBOX360) || defined(SHADER_API_PS3) || defined(SHADER_API_D3D11) || defined(SHADER_API_D3D11_9X) || defined(SHADER_API_PSP2) || defined(SHADER_API_PSSL)) && !defined(VAR_COMPILER_HLSLCC)
#define VAR_ATTEN_CHANNEL r
#else
#define VAR_ATTEN_CHANNEL a
#endif

#if defined(SHADER_API_D3D9) || defined(SHADER_API_XBOX360) || defined(SHADER_API_PSP2)
#define VAR_HALF_TEXEL_OFFSET
#endif

#if (defined(SHADER_API_D3D9) || defined(SHADER_API_XBOX360) || defined(SHADER_API_PS3) || defined(SHADER_API_D3D11) || defined(SHADER_API_D3D11_9X) || defined(SHADER_API_PSP2) || defined(SHADER_API_PSSL)) && !defined(VAR_COMPILER_HLSLCC)
#define VAR_UV_STARTS_AT_TOP 1
#endif

#if (defined(SHADER_API_D3D9) || defined(SHADER_API_XBOX360) || defined(SHADER_API_PS3) || defined(SHADER_API_D3D11) || defined(SHADER_API_D3D11_9X)) && !defined(VAR_COMPILER_HLSLCC)
#define VAR_NEAR_CLIP_VALUE (0.0)
#else
#define VAR_NEAR_CLIP_VALUE (-1.0)
#endif


#if defined(SHADER_API_D3D9)
#define VAR_MIGHT_NOT_HAVE_DEPTH_TEXTURE
#endif


#if (defined(SHADER_API_OPENGL) && !defined(SHADER_TARGET_GLSL)) || defined(SHADER_API_PSP2)
#define VAR_BUGGY_TEX2DPROJ4
#define VAR_PROJ_COORD(a) (a).xyw
#else
#define VAR_PROJ_COORD(a) a
#endif


// Platforms which do not use cascaded/screenspace shadow maps: more or less "mobile" platforms
#if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3) || defined(SHADER_API_GLES31) || defined(SHADER_API_METAL) || defined(SHADER_API_D3D11_9X)
#define VAR_NO_SCREENSPACE_SHADOWS
#endif

// Platforms which do not use RGBM lightmap compression, or DXT5nm normal map compression
#if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3) || defined(SHADER_API_GLES31) || defined(SHADER_API_METAL)
#define VAR_NO_RGBM
#define VAR_NO_DXT5nm
#endif

// Platforms which can support "framebuffer fetch" on some devices
#if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3) || defined(SHADER_API_GLES31)
#define VAR_FRAMEBUFFER_FETCH_AVAILABLE
#endif


// On most platforms, use floating point render targets to store depth of point
// light shadowmaps. However, on some others they either have issues, or aren't widely
// supported; in which case fallback to encoding depth into RGBA channels.
// Make sure this define matches GraphicsCaps.useRGBAForPointShadows.
#if defined(SHADER_API_GLES) || defined(SHADER_API_PSP2) || defined(SHADER_API_XBOX360) || defined(SHADER_API_PS3)
#define VAR_USE_RGBA_FOR_POINT_SHADOWS
#endif


#if defined(VAR_COMPILER_HLSL) || defined(VAR_COMPILER_HLSLCC)
#define VAR_INITIALIZE_OUTPUT(type,name) name = (type)0;
#else
#define VAR_INITIALIZE_OUTPUT(type,name)
#endif

#if defined(SHADER_API_D3D11) || defined(VAR_COMPILER_HLSLCC)
#define VAR_CAN_COMPILE_TESSELLATION 1
#   define VAR_domain                   domain
#   define VAR_partitioning         partitioning
#   define VAR_outputtopology           outputtopology
#   define VAR_patchconstantfunc        patchconstantfunc
#   define VAR_outputcontrolpoints  outputcontrolpoints
#elif defined(SHADER_API_PSSL)
#   define VAR_CAN_COMPILE_TESSELLATION 1

#   define SV_OutputControlPointID      S_OUTPUT_CONTROL_POINT_ID
#   define SV_TessFactor                S_EDGE_TESS_FACTOR
#   define SV_InsideTessFactor          S_INSIDE_TESS_FACTOR
#   define SV_DomainLocation            S_DOMAIN_LOCATION

#   define VAR_domain                   DOMAIN_PATCH_TYPE
#   define VAR_partitioning         PARTITIONING_TYPE
#   define VAR_outputtopology           OUTPUT_TOPOLOGY_TYPE
#   define VAR_patchconstantfunc        PATCH_CONSTANT_FUNC
#   define VAR_outputcontrolpoints  OUTPUT_CONTROL_POINTS

#   define  domain                      DOMAIN_PATCH_TYPE
#   define  partitioning                PARTITIONING_TYPE
#   define  outputtopology              OUTPUT_TOPOLOGY_TYPE
#   define  patchconstantfunc           PATCH_CONSTANT_FUNC
#   define  outputcontrolpoints         OUTPUT_CONTROL_POINTS

#   define  maxtessfactor               MAX_TESS_FACTOR
#   define  instance                    INSTANCE
#   define  numthreads                  NUM_THREADS
#   define  patchsize                   PATCH_SIZE
#   define  maxvertexcount              MAX_VERTEX_COUNT            
#   define  earlydepthstencil           FORCE_EARLY_DEPTH_STENCIL

#   define  GroupMemoryBarrierWithGroupSync ThreadGroupMemoryBarrierSync

// geometry shader
#   define TriangleStream               TriangleBuffer              
#   define PointStream                  PointBuffer                 
#   define LineStream                   LineBuffer                  
#   define triangle                 Triangle                    
#   define point                        Point                       
#   define line                     Line                        
#   define triangleadj                  AdjacentTriangle            
#   define lineadj                      AdjacentLine

// multimedia operations
#define msad4                       msad

#endif

#define VAR_SAMPLE_1CHANNEL(x,y) tex2D(x,y).a
#define VAR_ALPHA_CHANNEL a


#endif

#line 4 "MyShaderVariables.cginc"


#if defined (DIRECTIONAL_COOKIE) || defined (DIRECTIONAL)
#define USING_DIRECTIONAL_LIGHT
#endif



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

CBUFFER_START(MyPerCamera)
    uniform float4 _Time;
    uniform float4 _SinTime;
    uniform float4 _CosTime;
    uniform float4 var_DeltaTime; // dt, 1/dt, smoothdt, 1/smoothdt

    uniform float3 _WorldSpaceCameraPos;

    // x = 1 or -1 (-1 if projection is flipped)
    // y = near plane
    // z = far plane
    // w = 1/far plane
    uniform float4 _ProjectionParams;

    // x = width
    // y = height
    // z = 1 + 1.0/width
    // w = 1 + 1.0/height
    uniform float4 _ScreenParams;

    uniform float4 _ZBufferParams;

    // x = orthographic camera's width
    // y = orthographic camera's height
    // z = unused
    // w = 1.0 if camera is ortho, 0.0 if perspective
    uniform float4 var_OrthoParams;
CBUFFER_END


CBUFFER_START(MyPerCameraRare)
    uniform float4 var_CameraWorldClipPlanes[6];

    // Projection matrices of the camera. Note that this might be different from projection matrix
    // that is set right now, e.g. while rendering shadows the matrices below are still the projection
    // of original camera.
    uniform float4x4 var_CameraProjection;
    uniform float4x4 var_CameraInvProjection;
CBUFFER_END



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

CBUFFER_START(MyLighting)

    #ifdef USING_DIRECTIONAL_LIGHT
    uniform half4 _WorldSpaceLightPos0;
    #else
    uniform float4 _WorldSpaceLightPos0;
    #endif

    uniform float4 _LightPositionRange; // xyz = pos, w = 1/range

    float4 var_4LightPosX0;
    float4 var_4LightPosY0;
    float4 var_4LightPosZ0;
    half4 var_4LightAtten0;

    half4 var_LightColor[8];
    float4 var_LightPosition[8];
    // x = -1
    // y = 1
    // z = quadratic attenuation
    // w = range^2
    half4 var_LightAtten[8];
    float4 var_SpotDirection[8];

    // SH lighting environment
    half4 var_SHAr;
    half4 var_SHAg;
    half4 var_SHAb;
    half4 var_SHBr;
    half4 var_SHBg;
    half4 var_SHBb;
    half4 var_SHC;
CBUFFER_END

CBUFFER_START(MyLightingOld)
    half3 var_LightColor0, var_LightColor1, var_LightColor2, var_LightColor3; // keeping those only for any existing shaders; remove in 4.0
CBUFFER_END


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

CBUFFER_START(MyShadows)
    float4 var_ShadowSplitSpheres[4];
    float4 var_ShadowSplitSqRadii;
    float4 var_LightShadowBias;
    float4 _LightSplitsNear;
    float4 _LightSplitsFar;
    float4x4 var_World2Shadow[4];
    half4 _LightShadowData;
    float4 var_ShadowFadeCenterAndType;
CBUFFER_END

#define _World2Shadow var_World2Shadow[0]
#define _World2Shadow1 var_World2Shadow[1]
#define _World2Shadow2 var_World2Shadow[2]
#define _World2Shadow3 var_World2Shadow[3]


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

CBUFFER_START(MyPerDraw)
    float4x4 glstate_matrix_mvp;
    float4x4 glstate_matrix_modelview0;
    float4x4 glstate_matrix_invtrans_modelview0;
    #define VAR_MATRIX_MVP glstate_matrix_mvp
    #define VAR_MATRIX_MV glstate_matrix_modelview0
    #define VAR_MATRIX_IT_MV glstate_matrix_invtrans_modelview0

    uniform float4x4 _Object2World;
    uniform float4x4 _World2Object;
    uniform float4 var_LODFade; // x is the fade value ranging within [0,1]. y is x quantized into 16 levels
CBUFFER_END




CBUFFER_START(MyPerDrawRare)
    float4x4 glstate_matrix_transpose_modelview0;
    #define VAR_MATRIX_T_MV glstate_matrix_transpose_modelview0
CBUFFER_END



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

CBUFFER_START(MyPerFrame)

    float4x4 glstate_matrix_projection;
    float4   glstate_lightmodel_ambient;
    #define VAR_MATRIX_P glstate_matrix_projection
    #define VAR_LIGHTMODEL_AMBIENT glstate_lightmodel_ambient

    float4x4 var_MatrixV;
    float4x4 var_MatrixVP;
    #define VAR_MATRIX_V var_MatrixV
    #define VAR_MATRIX_VP var_MatrixVP

    fixed4 var_AmbientSky;
    fixed4 var_AmbientGround;

CBUFFER_END


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

CBUFFER_START(MyFog)
    uniform fixed4 var_FogColor;
    // x = density / sqrt(ln(2)), useful for Exp2 mode
    // y = density / ln(2), useful for Exp mode
    // z = -1/(end-start), useful for Linear mode
    // w = end/(end-start), useful for Linear mode
    uniform float4 var_FogParams;
CBUFFER_END


// ----------------------------------------------------------------------------
//  Deprecated

// There used to be fixed function-like texture matrices, defined as VAR_MATRIX_TEXTUREn. These are gone now; and are just defined to identity.
#define VAR_MATRIX_TEXTURE0 float4x4(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1)
#define VAR_MATRIX_TEXTURE1 float4x4(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1)
#define VAR_MATRIX_TEXTURE2 float4x4(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1)
#define VAR_MATRIX_TEXTURE3 float4x4(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1)


#endif

#line 4 "MyCG.cginc"



// Deprecated! Use SAMPLE_DEPTH_TEXTURE & SAMPLE_DEPTH_TEXTURE_PROJ instead!
#if defined(SHADER_API_PS3)
#   define VAR_SAMPLE_DEPTH(value) (dot((value).wxy, float3(0.996093809371817670572857294849, 0.0038909914428586627756752238080039, 1.5199185323666651467481343000015e-5)))
#elif defined(SHADER_API_PSP2)
#   define VAR_SAMPLE_DEPTH(value) (value).r
#else
#   define VAR_SAMPLE_DEPTH(value) (value).r
#endif


#if defined(SHADER_API_PS3)
#   define SAMPLE_DEPTH_TEXTURE(sampler, uv) (dot((tex2D(sampler, uv)).wxy, float3(0.996093809371817670572857294849, 0.0038909914428586627756752238080039, 1.5199185323666651467481343000015e-5)))
#elif defined(SHADER_API_PSP2) && !defined(SHADER_API_PSM)
#   define SAMPLE_DEPTH_TEXTURE(sampler, uv) (f1tex2D<float>(sampler, uv))
#else
#   define SAMPLE_DEPTH_TEXTURE(sampler, uv) (tex2D(sampler, uv).r)
#endif

#if defined(SHADER_API_PS3)
#   define SAMPLE_DEPTH_TEXTURE_PROJ(sampler, uv) (dot((tex2Dproj(sampler, uv)).wxy, float3(0.996093809371817670572857294849, 0.0038909914428586627756752238080039, 1.5199185323666651467481343000015e-5)))
#elif defined(SHADER_API_PSP2) && !defined(SHADER_API_PSM)
#   define SAMPLE_DEPTH_TEXTURE_PROJ(sampler, uv) (f1tex2Dproj<float>(sampler, uv))
#else
#   define SAMPLE_DEPTH_TEXTURE_PROJ(sampler, uv) (tex2Dproj(sampler, uv).r)
#endif

#if defined(SHADER_API_PSP2) && !defined(SHADER_API_PSM)
#define SAMPLE_DEPTH_TEXTURE_LOD(sampler, uv) (tex2Dlod<float>(sampler, uv))
#else
#define SAMPLE_DEPTH_TEXTURE_LOD(sampler, uv) (tex2Dlod(sampler, uv).r)
#endif

uniform fixed4 var_ColorSpaceGrey;
uniform fixed4 var_ColorSpaceDouble;

// -------------------------------------------------------------------
//  helper functions and macros used in many standard shaders


#if defined (DIRECTIONAL) || defined (DIRECTIONAL_COOKIE) || defined (POINT) || defined (SPOT) || defined (POINT_NOATT) || defined (POINT_COOKIE)
#define USING_LIGHT_MULTI_COMPILE
#endif

#define SCALED_NORMAL v.normal

struct appdata_base {
    float4 vertex : POSITION;
    float3 normal : NORMAL;
    float4 texcoord : TEXCOORD0;
};

struct appdata_tan {
    float4 vertex : POSITION;
    float4 tangent : TANGENT;
    float3 normal : NORMAL;
    float4 texcoord : TEXCOORD0;
};

struct appdata_full {
    float4 vertex : POSITION;
    float4 tangent : TANGENT;
    float3 normal : NORMAL;
    float4 texcoord : TEXCOORD0;
    float4 texcoord1 : TEXCOORD1;
    float4 texcoord2 : TEXCOORD2;
    float4 texcoord3 : TEXCOORD3;
#if defined(SHADER_API_XBOX360)
    half4 texcoord4 : TEXCOORD4;
    half4 texcoord5 : TEXCOORD5;
#endif
    fixed4 color : COLOR;
};

// Transforms direction from object to world space
inline float3 MyObjectToWorldDir( in float3 dir )
{
    return normalize(mul((float3x3)_Object2World, dir));
}

// Transforms direction from world to object space
inline float3 MyWorldToObjectDir( in float3 dir )
{
    return normalize(mul((float3x3)_World2Object, dir));
}

// Transforms normal from object to world space
inline float3 MyObjectToWorldNorm( in float3 norm )
{
    // Multiply by transposed inverse matrix, actually using transpose() generates badly optimized code
    return normalize(_World2Object[0].xyz * norm.x + _World2Object[1].xyz * norm.y + _World2Object[2].xyz * norm.z);
}

// Computes world space light direction, from world space position
inline float3 MyWorldSpaceLightDir( in float3 worldPos )
{
    #ifndef USING_LIGHT_MULTI_COMPILE
        return _WorldSpaceLightPos0.xyz - worldPos * _WorldSpaceLightPos0.w;
    #else
        #ifndef USING_DIRECTIONAL_LIGHT
        return _WorldSpaceLightPos0.xyz - worldPos;
        #else
        return _WorldSpaceLightPos0.xyz;
        #endif
    #endif
}

// Computes world space light direction, from object space position
// *Legacy* Please use MyWorldSpaceLightDir instead
inline float3 WorldSpaceLightDir( in float4 localPos )
{
    float3 worldPos = mul(_Object2World, localPos).xyz;
    return MyWorldSpaceLightDir(worldPos);
}

// Computes object space light direction
inline float3 ObjSpaceLightDir( in float4 v )
{
    float3 objSpaceLightPos = mul(_World2Object, _WorldSpaceLightPos0).xyz;
    #ifndef USING_LIGHT_MULTI_COMPILE
        return objSpaceLightPos.xyz - v.xyz * _WorldSpaceLightPos0.w;
    #else
        #ifndef USING_DIRECTIONAL_LIGHT
        return objSpaceLightPos.xyz - v.xyz;
        #else
        return objSpaceLightPos.xyz;
        #endif
    #endif
}

// Computes world space view direction, from object space position
inline float3 MyWorldSpaceViewDir( in float3 worldPos )
{
    return _WorldSpaceCameraPos.xyz - worldPos;
}

// Computes world space view direction, from object space position
// *Legacy* Please use MyWorldSpaceViewDir instead
inline float3 WorldSpaceViewDir( in float4 localPos )
{
    float3 worldPos = mul(_Object2World, localPos).xyz;
    return MyWorldSpaceViewDir(worldPos);
}

// Computes object space view direction
inline float3 ObjSpaceViewDir( in float4 v )
{
    float3 objSpaceCameraPos = mul(_World2Object, float4(_WorldSpaceCameraPos.xyz, 1)).xyz;
    return objSpaceCameraPos - v.xyz;
}

// Declares 3x3 matrix 'rotation', filled with tangent space basis
#define TANGENT_SPACE_ROTATION \
    float3 binormal = cross( normalize(v.normal), normalize(v.tangent.xyz) ) * v.tangent.w; \
    float3x3 rotation = float3x3( v.tangent.xyz, binormal, v.normal )




float3 Shade4PointLights (
    float4 lightPosX, float4 lightPosY, float4 lightPosZ,
    float3 lightColor0, float3 lightColor1, float3 lightColor2, float3 lightColor3,
    float4 lightAttenSq,
    float3 pos, float3 normal)
{
    // to light vectors
    float4 toLightX = lightPosX - pos.x;
    float4 toLightY = lightPosY - pos.y;
    float4 toLightZ = lightPosZ - pos.z;
    // squared lengths
    float4 lengthSq = 0;
    lengthSq += toLightX * toLightX;
    lengthSq += toLightY * toLightY;
    lengthSq += toLightZ * toLightZ;
    // NdotL
    float4 ndotl = 0;
    ndotl += toLightX * normal.x;
    ndotl += toLightY * normal.y;
    ndotl += toLightZ * normal.z;
    // correct NdotL
    float4 corr = rsqrt(lengthSq);
    ndotl = max (float4(0,0,0,0), ndotl * corr);
    // attenuation
    float4 atten = 1.0 / (1.0 + lengthSq * lightAttenSq);
    float4 diff = ndotl * atten;
    // final color
    float3 col = 0;
    col += lightColor0 * diff.x;
    col += lightColor1 * diff.y;
    col += lightColor2 * diff.z;
    col += lightColor3 * diff.w;
    return col;
}


float3 ShadeVertexLights (float4 vertex, float3 normal)
{
    float3 viewpos = mul (VAR_MATRIX_MV, vertex).xyz;
    float3 viewN = normalize (mul ((float3x3)VAR_MATRIX_IT_MV, normal));
    float3 lightColor = VAR_LIGHTMODEL_AMBIENT.xyz;
    for (int i = 0; i < 4; i++) {
        float3 toLight = var_LightPosition[i].xyz - viewpos.xyz * var_LightPosition[i].w;
        float lengthSq = dot(toLight, toLight);
        float atten = 1.0 / (1.0 + lengthSq * var_LightAtten[i].z);
        float diff = max (0, dot (viewN, normalize(toLight)));
        lightColor += var_LightColor[i].rgb * (diff * atten);
    }
    return lightColor;
}


// normal should be normalized, w=1.0
half3 ShadeSH9 (half4 normal)
{
    half3 x1, x2, x3;

    // Linear + constant polynomial terms
    x1.r = dot(var_SHAr,normal);
    x1.g = dot(var_SHAg,normal);
    x1.b = dot(var_SHAb,normal);

    // 4 of the quadratic polynomials
    half4 vB = normal.xyzz * normal.yzzx;
    x2.r = dot(var_SHBr,vB);
    x2.g = dot(var_SHBg,vB);
    x2.b = dot(var_SHBb,vB);

    // Final quadratic polynomial
    float vC = normal.x*normal.x - normal.y*normal.y;
    x3 = var_SHC.rgb * vC;
    return x1 + x2 + x3;
} 


// Transforms 2D UV by scale/bias property
#define TRANSFORM_TEX(tex,name) (tex.xy * name##_ST.xy + name##_ST.zw)

// Deprecated. Used to transform 4D UV by a fixed function texture matrix. Now just returns the passed UV.
#define TRANSFORM_UV(idx) v.texcoord.xy



struct v2f_vertex_lit {
    float2 uv   : TEXCOORD0;
    fixed4 diff : COLOR0;
    fixed4 spec : COLOR1;
};  

inline fixed4 VertexLight( v2f_vertex_lit i, sampler2D mainTex )
{
    fixed4 texcol = tex2D( mainTex, i.uv );
    fixed4 c;
    c.xyz = ( texcol.xyz * i.diff.xyz + i.spec.xyz * texcol.a ) * 2;
    c.w = texcol.w * i.diff.w;
    return c;
}


// Calculates UV offset for parallax bump mapping
inline float2 ParallaxOffset( half h, half height, half3 viewDir )
{
    h = h * height - height/2.0;
    float3 v = normalize(viewDir);
    v.z += 0.42;
    return h * (v.xy / v.z);
}


// Converts color to luminance (grayscale)
inline fixed Luminance( fixed3 c )
{
    return dot( c, fixed3(0.22, 0.707, 0.071) );
}

// Decodes HDR textures
// handles dLDR, RGBM formats
inline half3 DecodeHDR (half4 data, half4 decodeInstructions)
{
    // GLES2.0 support only Gamma mode, we can skip exponent
    // SM2.0 might be used in combination with SM3.0, so we can NOT skip exponent
    #if (defined(SHADER_API_GLES) && defined(SHADER_API_MOBILE))
        return (decodeInstructions.x * data.a) * data.rgb;
    #else
        return (decodeInstructions.x * pow(data.a, decodeInstructions.y)) * data.rgb;
    #endif
}

// Decodes lightmaps:
// - doubleLDR encoded on GLES
// - RGBM encoded with range [0;8] on other platforms using surface shaders
inline fixed3 DecodeLightmap( fixed4 color )
{
#if defined(VAR_NO_RGBM)
    return 2.0 * color.rgb;
#else
    // potentially faster to do the scalar multiplication
    // in parenthesis for scalar GPUs
    return (8.0 * color.a) * color.rgb;
#endif
}

// Decode LRB lightmaps, range [0;16]:
// - alpha: the low 8 bits of the 16-bit luminance value
// - red:   the high 8 bits of the 16-bit luminance value
// - green: scaled red
// - blue:  scaled blue
inline half3 DecodeLightmapLRB( fixed4 value )
{   
    half3 color         = half3 (value.g, 1.0f - value.g - value.b, value.b);
    half intensity      = (value.r + value.a / 256.0f) * 16.0f;
    half3 irradiance    = color * intensity;

    return irradiance;
}


// Helpers used in image effects. Most image effects use the same
// minimal vertex shader (vert_img).

struct appdata_img {
    float4 vertex : POSITION;
    half2 texcoord : TEXCOORD0;
};
struct v2f_img {
    float4 pos : SV_POSITION;
    half2 uv : TEXCOORD0;
};

float2 MultiplyUV (float4x4 mat, float2 inUV) {
    float4 temp = float4 (inUV.x, inUV.y, 0, 0);
    temp = mul (mat, temp);
    return temp.xy;
}

v2f_img vert_img( appdata_img v )
{
    v2f_img o;
    o.pos = mul (VAR_MATRIX_MVP, v.vertex);
    o.uv = v.texcoord;
    return o;
}


// Encoding/decoding [0..1) floats into 8 bit/channel RGBA. Note that 1.0 will not be encoded properly.
inline float4 EncodeFloatRGBA( float v )
{
    float4 kEncodeMul = float4(1.0, 255.0, 65025.0, 16581375.0);
    float kEncodeBit = 1.0/255.0;
    float4 enc = kEncodeMul * v;
    enc = frac (enc);
    enc -= enc.yzww * kEncodeBit;
    return enc;
}
inline float DecodeFloatRGBA( float4 enc )
{
    float4 kDecodeDot = float4(1.0, 1/255.0, 1/65025.0, 1/16581375.0);
    return dot( enc, kDecodeDot );
}

// Encoding/decoding [0..1) floats into 8 bit/channel RG. Note that 1.0 will not be encoded properly.
inline float2 EncodeFloatRG( float v )
{
    float2 kEncodeMul = float2(1.0, 255.0);
    float kEncodeBit = 1.0/255.0;
    float2 enc = kEncodeMul * v;
    enc = frac (enc);
    enc.x -= enc.y * kEncodeBit;
    return enc;
}
inline float DecodeFloatRG( float2 enc )
{
    float2 kDecodeDot = float2(1.0, 1/255.0);
    return dot( enc, kDecodeDot );
}


// Encoding/decoding view space normals into 2D 0..1 vector
inline float2 EncodeViewNormalStereo( float3 n )
{
    float kScale = 1.7777;
    float2 enc;
    enc = n.xy / (n.z+1);
    enc /= kScale;
    enc = enc*0.5+0.5;
    return enc;
}
inline float3 DecodeViewNormalStereo( float4 enc4 )
{
    float kScale = 1.7777;
    float3 nn = enc4.xyz*float3(2*kScale,2*kScale,0) + float3(-kScale,-kScale,1);
    float g = 2.0 / dot(nn.xyz,nn.xyz);
    float3 n;
    n.xy = g*nn.xy;
    n.z = g-1;
    return n;
}

inline float4 EncodeDepthNormal( float depth, float3 normal )
{
    float4 enc;
    enc.xy = EncodeViewNormalStereo (normal);
    enc.zw = EncodeFloatRG (depth);
    return enc;
}

inline void DecodeDepthNormal( float4 enc, out float depth, out float3 normal )
{
    depth = DecodeFloatRG (enc.zw);
    normal = DecodeViewNormalStereo (enc);
}

inline fixed3 UnpackNormalDXT5nm (fixed4 packednormal)
{
    fixed3 normal;
    normal.xy = packednormal.wy * 2 - 1;
    normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
    return normal;
}

inline fixed3 UnpackNormal(fixed4 packednormal)
{
#if defined(VAR_NO_DXT5nm)
    return packednormal.xyz * 2 - 1;
#else
    return UnpackNormalDXT5nm(packednormal);
#endif
}


// Z buffer to linear 0..1 depth (0 at eye, 1 at far plane)
inline float Linear01Depth( float z )
{
    return 1.0 / (_ZBufferParams.x * z + _ZBufferParams.y);
}
// Z buffer to linear depth
inline float LinearEyeDepth( float z )
{
    return 1.0 / (_ZBufferParams.z * z + _ZBufferParams.w);
}


// Depth render texture helpers
#if defined(VAR_MIGHT_NOT_HAVE_DEPTH_TEXTURE)
    #define VAR_TRANSFER_DEPTH(oo) oo = o.pos.zw
    #define VAR_OUTPUT_DEPTH(i) return i.x/i.y
#else
    #define VAR_TRANSFER_DEPTH(oo) 
    #define VAR_OUTPUT_DEPTH(i) return 0
#endif
#define DECODE_EYEDEPTH(i) LinearEyeDepth(i)
#define COMPUTE_EYEDEPTH(o) o = -mul( VAR_MATRIX_MV, v.vertex ).z
#define COMPUTE_DEPTH_01 -(mul( VAR_MATRIX_MV, v.vertex ).z * _ProjectionParams.w)
#define COMPUTE_VIEW_NORMAL normalize(mul((float3x3)VAR_MATRIX_IT_MV, v.normal))


// Projected screen position helpers
#define V2F_SCREEN_TYPE float4
inline float4 ComputeScreenPos (float4 pos) {
    float4 o = pos * 0.5f;
    #if defined(VAR_HALF_TEXEL_OFFSET)
    o.xy = float2(o.x, o.y*_ProjectionParams.x) + o.w * _ScreenParams.zw;
    #else
    o.xy = float2(o.x, o.y*_ProjectionParams.x) + o.w;
    #endif

    o.zw = pos.zw;
    return o;
}

inline float4 ComputeGrabScreenPos (float4 pos) {
    #if VAR_UV_STARTS_AT_TOP
    float scale = -1.0;
    #else
    float scale = 1.0;
    #endif
    float4 o = pos * 0.5f;
    o.xy = float2(o.x, o.y*scale) + o.w;
    o.zw = pos.zw;
    return o;
}

// snaps post-transformed position to screen pixels
inline float4 MyPixelSnap (float4 pos)
{
    float2 hpc = _ScreenParams.xy * 0.5f;
    #ifdef VAR_HALF_TEXEL_OFFSET
    float2 hpcO = float2(-0.5f, 0.5f);
    #else
    float2 hpcO = float2(0,0);
    #endif  
    float2 pixelPos = round ((pos.xy / pos.w) * hpc);
    pos.xy = (pixelPos + hpcO) / hpc * pos.w;
    return pos;
}

inline float2 TransformViewToProjection (float2 v) {
    return mul((float2x2)VAR_MATRIX_P, v);
}

inline float3 TransformViewToProjection (float3 v) {
    return mul((float3x3)VAR_MATRIX_P, v);
}

// Shadow caster pass helpers

float4 MyEncodeCubeShadowDepth (float z)
{
    #ifdef VAR_USE_RGBA_FOR_POINT_SHADOWS
    return EncodeFloatRGBA (min(z, 0.999));
    #else
    return z;
    #endif
}

float MyDecodeCubeShadowDepth (float4 vals)
{
    #ifdef VAR_USE_RGBA_FOR_POINT_SHADOWS
    return DecodeFloatRGBA (vals);
    #else
    return vals.r;
    #endif
}


#ifdef SHADOWS_CUBE
    #define V2F_SHADOW_CASTER float4 pos : SV_POSITION; float3 vec : TEXCOORD0
    #define TRANSFER_SHADOW_CASTER(o) o.vec = mul( _Object2World, v.vertex ).xyz - _LightPositionRange.xyz; o.pos = mul(VAR_MATRIX_MVP, v.vertex);
    #define SHADOW_CASTER_FRAGMENT(i) return MyEncodeCubeShadowDepth (length(i.vec) * _LightPositionRange.w);
#else
    #if defined(VAR_MIGHT_NOT_HAVE_DEPTH_TEXTURE)
    #define V2F_SHADOW_CASTER float4 pos : SV_POSITION; float4 hpos : TEXCOORD0
    #define TRANSFER_SHADOW_CASTER(o) \
        o.pos = mul(VAR_MATRIX_MVP, v.vertex); \
        o.pos.z += saturate(var_LightShadowBias.x/o.pos.w); \
        float clamped = max(o.pos.z, o.pos.w*VAR_NEAR_CLIP_VALUE); \
        o.pos.z = lerp(o.pos.z, clamped, var_LightShadowBias.y); \
        o.hpos = o.pos;
    #else
    #define V2F_SHADOW_CASTER float4 pos : SV_POSITION
    #define TRANSFER_SHADOW_CASTER(o) \
        o.pos = mul(VAR_MATRIX_MVP, v.vertex); \
        o.pos.z += saturate(var_LightShadowBias.x/o.pos.w); \
        float clamped = max(o.pos.z, o.pos.w*VAR_NEAR_CLIP_VALUE); \
        o.pos.z = lerp(o.pos.z, clamped, var_LightShadowBias.y);
    #endif
    #define SHADOW_CASTER_FRAGMENT(i) VAR_OUTPUT_DEPTH(i.hpos.zw);
#endif


// ------------------------------------------------------------------
//  Fog helpers
//
//  multi_compile_fog Will compile fog variants.
//  VAR_FOG_COORDS(texcoordindex) Declares the fog data interpolator.
//  VAR_TRANSFER_FOG(outputStruct,clipspacePos) Outputs fog data from the vertex shader.
//  VAR_APPLY_FOG(fogData,col) Applies fog to color "col". Automatically applies black fog when in forward-additive pass.
//  Can also use VAR_APPLY_FOG_COLOR to supply your own fog color.

// In case someone by accident tries to compile fog code in one of the g-buffer or shadow passes:
// treat it as fog is off.
#if defined(VAR_PASS_PREPASSBASE) || defined(VAR_PASS_DEFERRED) || defined(VAR_PASS_SHADOWCASTER)
#undef FOG_LINEAR
#undef FOG_EXP
#undef FOG_EXP2
#endif

#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
#define VAR_FOG_COORDS(idx) float fogCoord : TEXCOORD##idx;
#define VAR_TRANSFER_FOG(o,outpos) o.fogCoord = (outpos).z
#else
#define VAR_FOG_COORDS(idx)
#define VAR_TRANSFER_FOG(o,outpos)
#endif

#define VAR_FOG_LERP_COLOR(col,fogCol,fogFac) col.rgb = lerp((fogCol).rgb, (col).rgb, saturate(fogFac))


#if defined(FOG_LINEAR)
    // factor = (end-z)/(end-start) = z * (-1/(end-start)) + (end/(end-start))
    #define VAR_APPLY_FOG_COLOR(coord,col,fogCol) float fogFac = (coord) * var_FogParams.z + var_FogParams.w; VAR_FOG_LERP_COLOR(col,fogCol,fogFac)
#elif defined(FOG_EXP)
    // factor = exp(-density*z)
    #define VAR_APPLY_FOG_COLOR(coord,col,fogCol) float fogFac = var_FogParams.y * (coord); fogFac = exp2(-fogFac); VAR_FOG_LERP_COLOR(col,fogCol,fogFac)
#elif defined(FOG_EXP2)
    // factor = exp(-(density*z)^2)
    #define VAR_APPLY_FOG_COLOR(coord,col,fogCol) float fogFac = var_FogParams.x * (coord); fogFac = exp2(-fogFac*fogFac); VAR_FOG_LERP_COLOR(col,fogCol,fogFac)
#else
    #define VAR_APPLY_FOG_COLOR(coord,col,fogCol)
#endif

#ifdef VAR_PASS_FORWARDADD
    #define VAR_APPLY_FOG(coord,col) VAR_APPLY_FOG_COLOR(coord,col,fixed4(0,0,0,0))
#else
    #define VAR_APPLY_FOG(coord,col) VAR_APPLY_FOG_COLOR(coord,col,var_FogColor)
#endif


// ------------------------------------------------------------------
//  Deprecated things: these aren't used; kept here
//  just so that various existing shaders still compile, more or less.


// Note: deprecated shadow collector pass helpers
#ifdef SHADOW_COLLECTOR_PASS

#if !defined(SHADOWMAPSAMPLER_DEFINED)
VAR_DECLARE_SHADOWMAP(_ShadowMapTexture);
#endif

// Note: deprecated
#define V2F_SHADOW_COLLECTOR float4 pos : SV_POSITION; float3 _ShadowCoord0 : TEXCOORD0; float3 _ShadowCoord1 : TEXCOORD1; float3 _ShadowCoord2 : TEXCOORD2; float3 _ShadowCoord3 : TEXCOORD3; float4 _WorldPosViewZ : TEXCOORD4
#define TRANSFER_SHADOW_COLLECTOR(o)    \
    o.pos = mul(VAR_MATRIX_MVP, v.vertex); \
    float4 wpos = mul(_Object2World, v.vertex); \
    o._WorldPosViewZ.xyz = wpos; \
    o._WorldPosViewZ.w = -mul( VAR_MATRIX_MV, v.vertex ).z; \
    o._ShadowCoord0 = mul(var_World2Shadow[0], wpos).xyz; \
    o._ShadowCoord1 = mul(var_World2Shadow[1], wpos).xyz; \
    o._ShadowCoord2 = mul(var_World2Shadow[2], wpos).xyz; \
    o._ShadowCoord3 = mul(var_World2Shadow[3], wpos).xyz;

// Note: deprecated
#if defined (SHADOWS_NATIVE)
    #define SAMPLE_SHADOW_COLLECTOR_SHADOW(coord) \
    half shadow = VAR_SAMPLE_SHADOW(_ShadowMapTexture,coord); \
    shadow = _LightShadowData.r + shadow * (1-_LightShadowData.r);
#else
    #define SAMPLE_SHADOW_COLLECTOR_SHADOW(coord) \
    float shadow = SAMPLE_DEPTH_TEXTURE(_ShadowMapTexture, coord.xy ) < coord.z ? _LightShadowData.r : 1.0;
#endif

// Note: deprecated
#define COMPUTE_SHADOW_COLLECTOR_SHADOW(i, weights, shadowFade) \
    float4 coord = float4(i._ShadowCoord0 * weights[0] + i._ShadowCoord1 * weights[1] + i._ShadowCoord2 * weights[2] + i._ShadowCoord3 * weights[3], 1); \
    SAMPLE_SHADOW_COLLECTOR_SHADOW(coord) \
    float4 res; \
    res.x = saturate(shadow + shadowFade); \
    res.y = 1.0; \
    res.zw = EncodeFloatRG (1 - i._WorldPosViewZ.w * _ProjectionParams.w); \
    return res; 

// Note: deprecated
#if defined (SHADOWS_SPLIT_SPHERES)
#define SHADOW_COLLECTOR_FRAGMENT(i) \
    float3 fromCenter0 = i._WorldPosViewZ.xyz - var_ShadowSplitSpheres[0].xyz; \
    float3 fromCenter1 = i._WorldPosViewZ.xyz - var_ShadowSplitSpheres[1].xyz; \
    float3 fromCenter2 = i._WorldPosViewZ.xyz - var_ShadowSplitSpheres[2].xyz; \
    float3 fromCenter3 = i._WorldPosViewZ.xyz - var_ShadowSplitSpheres[3].xyz; \
    float4 distances2 = float4(dot(fromCenter0,fromCenter0), dot(fromCenter1,fromCenter1), dot(fromCenter2,fromCenter2), dot(fromCenter3,fromCenter3)); \
    float4 cascadeWeights = float4(distances2 < var_ShadowSplitSqRadii); \
    cascadeWeights.yzw = saturate(cascadeWeights.yzw - cascadeWeights.xyz); \
    float sphereDist = distance(i._WorldPosViewZ.xyz, var_ShadowFadeCenterAndType.xyz); \
    float shadowFade = saturate(sphereDist * _LightShadowData.z + _LightShadowData.w); \
    COMPUTE_SHADOW_COLLECTOR_SHADOW(i, cascadeWeights, shadowFade)
#else
#define SHADOW_COLLECTOR_FRAGMENT(i) \
    float4 viewZ = i._WorldPosViewZ.w; \
    float4 zNear = float4( viewZ >= _LightSplitsNear ); \
    float4 zFar = float4( viewZ < _LightSplitsFar ); \
    float4 cascadeWeights = zNear * zFar; \
    float shadowFade = saturate(i._WorldPosViewZ.w * _LightShadowData.z + _LightShadowData.w); \
    COMPUTE_SHADOW_COLLECTOR_SHADOW(i, cascadeWeights, shadowFade)
#endif

#endif // #ifdef SHADOW_COLLECTOR_PASS


#endif // VAR_CG_INCLUDED

#line 23 ""


float _TessEdge;
float _Displacement;


//=================================================================================================================================
// Buffers, Textures and Samplers
//=================================================================================================================================

Texture2D _MainTex;
SamplerState    sampler_MainTex;
Texture2D _DispTex;
SamplerState    sampler_DispTex;

//=================================================================================================================================
// Shader structures
//=================================================================================================================================


struct VS_RenderSceneInput
{
    float3 vertex : POSITION;
    float3 normal : NORMAL;
    float2 texcoord : TEXCOORD0;
};

struct HS_Input
{
    float4 f4Position   : POS;
    float3 f3Normal     : NORMAL;
    float2 f2TexCoord   : TEXCOORD;
};

struct HS_ConstantOutput
{
    // Tess factor for the FF HW block
    float fTessFactor[3]    : SV_TessFactor;
    float fInsideTessFactor : SV_InsideTessFactor;

    // Geometry cubic generated control points
    float3 f3B210    : POS3;
    float3 f3B120    : POS4;
    float3 f3B021    : POS5;
    float3 f3B012    : POS6;
    float3 f3B102    : POS7;
    float3 f3B201    : POS8;
    float3 f3B111    : CENTER;

    // Normal quadratic generated control points
    float3 f3N110    : NORMAL3;
    float3 f3N011    : NORMAL4;
    float3 f3N101    : NORMAL5;
};

struct HS_ControlPointOutput
{
    float3    f3Position    : POS;
    float3    f3Normal      : NORMAL;
    float2    f2TexCoord    : TEXCOORD;
};

struct DS_Output
{
    float4 f4Position   : SV_Position;
    float2 f2TexCoord   : TEXCOORD0;
    float4 f4Diffuse    : COLOR0;
};

struct PS_RenderSceneInput
{
    float4 f4Position   : SV_Position;
    float2 f2TexCoord   : TEXCOORD0;
    float4 f4Diffuse    : COLOR0;
};

struct PS_RenderOutput
{
    float4 f4Color      : SV_Target0;
};

PS_RenderSceneInput VS_RenderScene( VS_RenderSceneInput I )
{
    PS_RenderSceneInput O;

    O.f4Position = mul (VAR_MATRIX_MVP, float4(I.vertex, 1.0f));
    float3 viewN = mul ((float3x3)VAR_MATRIX_IT_MV, I.normal);

    // Calc diffuse color
    O.f4Diffuse.rgb = var_LightColor[0].rgb * max(0, dot(viewN, var_LightPosition[0].xyz)) + VAR_LIGHTMODEL_AMBIENT.rgb;
    O.f4Diffuse.a = 1.0f;

    // Pass through texture coords
    O.f2TexCoord = I.texcoord;

    return O;
}


HS_Input VS_RenderSceneWithTessellation( VS_RenderSceneInput I )
{
    HS_Input O;

    // To view space
    O.f4Position = mul(VAR_MATRIX_MV, float4(I.vertex,1.0f));
    O.f3Normal = mul ((float3x3)VAR_MATRIX_IT_MV, I.normal);

    O.f2TexCoord = I.texcoord;

    return O;
}


//=================================================================================================================================
// This hull shader passes the tessellation factors through to the HW tessellator,
// and the 10 (geometry), 6 (normal) control points of the PN-triangular patch to the domain shader
//=================================================================================================================================
HS_ConstantOutput HS_PNTrianglesConstant( InputPatch<HS_Input, 3> I )
{
    HS_ConstantOutput O = (HS_ConstantOutput)0;

    // Simply output the tessellation factors from constant space
    // for use by the FF tessellation unit
    O.fTessFactor[0] = O.fTessFactor[1] = O.fTessFactor[2] = _TessEdge;
    O.fInsideTessFactor = _TessEdge;

    // Assign Positions
    float3 f3B003 = I[0].f4Position.xyz;
    float3 f3B030 = I[1].f4Position.xyz;
    float3 f3B300 = I[2].f4Position.xyz;
    // And Normals
    float3 f3N002 = I[0].f3Normal;
    float3 f3N020 = I[1].f3Normal;
    float3 f3N200 = I[2].f3Normal;

    // Compute the cubic geometry control points
    // Edge control points
    O.f3B210 = ( ( 2.0f * f3B003 ) + f3B030 - ( dot( ( f3B030 - f3B003 ), f3N002 ) * f3N002 ) ) / 3.0f;
    O.f3B120 = ( ( 2.0f * f3B030 ) + f3B003 - ( dot( ( f3B003 - f3B030 ), f3N020 ) * f3N020 ) ) / 3.0f;
    O.f3B021 = ( ( 2.0f * f3B030 ) + f3B300 - ( dot( ( f3B300 - f3B030 ), f3N020 ) * f3N020 ) ) / 3.0f;
    O.f3B012 = ( ( 2.0f * f3B300 ) + f3B030 - ( dot( ( f3B030 - f3B300 ), f3N200 ) * f3N200 ) ) / 3.0f;
    O.f3B102 = ( ( 2.0f * f3B300 ) + f3B003 - ( dot( ( f3B003 - f3B300 ), f3N200 ) * f3N200 ) ) / 3.0f;
    O.f3B201 = ( ( 2.0f * f3B003 ) + f3B300 - ( dot( ( f3B300 - f3B003 ), f3N002 ) * f3N002 ) ) / 3.0f;
    // Center control point
    float3 f3E = ( O.f3B210 + O.f3B120 + O.f3B021 + O.f3B012 + O.f3B102 + O.f3B201 ) / 6.0f;
    float3 f3V = ( f3B003 + f3B030 + f3B300 ) / 3.0f;
    O.f3B111 = f3E + ( ( f3E - f3V ) / 2.0f );

    // Compute the quadratic normal control points
    float fV12 = 2.0f * dot( f3B030 - f3B003, f3N002 + f3N020 ) / dot( f3B030 - f3B003, f3B030 - f3B003 );
    O.f3N110 = normalize( f3N002 + f3N020 - fV12 * ( f3B030 - f3B003 ) );
    float fV23 = 2.0f * dot( f3B300 - f3B030, f3N020 + f3N200 ) / dot( f3B300 - f3B030, f3B300 - f3B030 );
    O.f3N011 = normalize( f3N020 + f3N200 - fV23 * ( f3B300 - f3B030 ) );
    float fV31 = 2.0f * dot( f3B003 - f3B300, f3N200 + f3N002 ) / dot( f3B003 - f3B300, f3B003 - f3B300 );
    O.f3N101 = normalize( f3N200 + f3N002 - fV31 * ( f3B003 - f3B300 ) );

    return O;
}

[domain("tri")]
[partitioning("fractional_odd")]
[outputtopology("triangle_cw")]
[patchconstantfunc("HS_PNTrianglesConstant")]
[outputcontrolpoints(3)]
HS_ControlPointOutput HS_PNTriangles( InputPatch<HS_Input, 3> I, uint uCPID : SV_OutputControlPointID )
{
    HS_ControlPointOutput O = (HS_ControlPointOutput)0;

    // Just pass through inputs = fast pass through mode triggered
    O.f3Position = I[uCPID].f4Position.xyz;
    O.f3Normal = I[uCPID].f3Normal;
    O.f2TexCoord = I[uCPID].f2TexCoord;

    return O;
}


//=================================================================================================================================
// This domain shader applies contol point weighting to the barycentric coords produced by the FF tessellator
//=================================================================================================================================
[domain("tri")]
DS_Output DS_PNTriangles( HS_ConstantOutput HSConstantData, const OutputPatch<HS_ControlPointOutput, 3> I, float3 f3BarycentricCoords : SV_DomainLocation )
{
    DS_Output O = (DS_Output)0;

    // The barycentric coordinates
    float fU = f3BarycentricCoords.x;
    float fV = f3BarycentricCoords.y;
    float fW = f3BarycentricCoords.z;

    // Precompute squares and squares * 3
    float fUU = fU * fU;
    float fVV = fV * fV;
    float fWW = fW * fW;
    float fUU3 = fUU * 3.0f;
    float fVV3 = fVV * 3.0f;
    float fWW3 = fWW * 3.0f;

    // Compute position from cubic control points and barycentric coords
    float3 f3Position = I[0].f3Position * fWW * fW +
                        I[1].f3Position * fUU * fU +
                        I[2].f3Position * fVV * fV +
                        HSConstantData.f3B210 * fWW3 * fU +
                        HSConstantData.f3B120 * fW * fUU3 +
                        HSConstantData.f3B201 * fWW3 * fV +
                        HSConstantData.f3B021 * fUU3 * fV +
                        HSConstantData.f3B102 * fW * fVV3 +
                        HSConstantData.f3B012 * fU * fVV3 +
                        HSConstantData.f3B111 * 6.0f * fW * fU * fV;

    // Compute normal from quadratic control points and barycentric coords
    float3 f3Normal =   I[0].f3Normal * fWW +
                        I[1].f3Normal * fUU +
                        I[2].f3Normal * fVV +
                        HSConstantData.f3N110 * fW * fU +
                        HSConstantData.f3N011 * fU * fV +
                        HSConstantData.f3N101 * fW * fV;

    // Normalize the interpolated normal
    f3Normal = normalize( f3Normal );

    // Linearly interpolate the texture coords
    O.f2TexCoord = I[0].f2TexCoord * fW + I[1].f2TexCoord * fU + I[2].f2TexCoord * fV;

    // Displacement map!
    float disp = _DispTex.SampleLevel (sampler_DispTex, O.f2TexCoord, 0).r * _Displacement;
    f3Position += f3Normal * disp;

    // Calc diffuse color
    O.f4Diffuse.rgb = var_LightColor[0].rgb * max( 0, dot( f3Normal, var_LightPosition[0].xyz ) ) + VAR_LIGHTMODEL_AMBIENT.rgb;
    O.f4Diffuse.a = 1.0f;

    // Transform position with projection matrix
    O.f4Position = mul (VAR_MATRIX_P, float4(f3Position.xyz,1.0));

    return O;
}


PS_RenderOutput PS_RenderSceneTextured( PS_RenderSceneInput I )
{
    PS_RenderOutput O;

    O.f4Color = _MainTex.Sample( sampler_MainTex, I.f2TexCoord ).r * I.f4Diffuse;

    return O;
}

output variable declared multiple times when variables are packed in single register

I found a situation that is not handled. When an output contains several components that are then packed in a single register, the crosscompiler emits the "out" variable multiple times with the same name(eg. VtxGeoOutput).

In the following example ParticleTexCoordScaleU,ParticleTexCoordScaleV and ParticleUVOrigin are all packed into register 2, the crosscompiler outputs "layout(location = 2) out vec4 VtxGeoOutput2;" 3 times.
Probably a simple fix would be to keep track of what output has been already declared and skip the subsequent declarations.

btw, thank you for this very useful project

Heres some data:

// hlsl input structure for a VS
struct VS_particle0_GATHER_Output {
float4 PixelPosition : SV_Position;
float4 ParticleColor : COMPUTED0;
float ParticleTexCoordScaleU : COMPUTED1;
float ParticleTexCoordScaleV : COMPUTED2;
float4 TLPosProj : COMPUTED3;
float2 ParticleUVOrigin : COMPUTED4;
float4 TRPosProj : COMPUTED5;
float4 BLPosProj : COMPUTED6;
float4 BRPosProj : COMPUTED7;

};

//D3DCompiler disassembly

// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position 0 xyzw 0 POS float xyzw
// COMPUTED 0 xyzw 1 NONE float xyzw
// COMPUTED 1 x 2 NONE float x
// COMPUTED 2 y 2 NONE float y
// COMPUTED 4 zw 2 NONE float zw
// COMPUTED 3 xyzw 3 NONE float xyzw
// COMPUTED 5 xyzw 4 NONE float xyzw
// COMPUTED 6 xyzw 5 NONE float xyzw
// COMPUTED 7 xyzw 6 NONE float xyzw
//

//HLSLCrossCompiler output declarations

layout(location = 1) out vec4 VtxGeoOutput1;

define Output1 VtxGeoOutput1

layout(location = 2) out vec4 VtxGeoOutput2; //1

define Output2 VtxGeoOutput2

layout(location = 2) out vec4 VtxGeoOutput2; //2
layout(location = 2) out vec4 VtxGeoOutput2; //3 times
layout(location = 3) out vec4 VtxGeoOutput3;

define Output3 VtxGeoOutput3

layout(location = 4) out vec4 VtxGeoOutput4;

define Output4 VtxGeoOutput4

layout(location = 5) out vec4 VtxGeoOutput5;

define Output5 VtxGeoOutput5

layout(location = 6) out vec4 VtxGeoOutput6;

define Output6 VtxGeoOutput6

Not support loop?

I got assert at line191 in decodeDX9.c.
The function is DecodeOperandDX9.

Value of ui32RegType is 15, which means OPERAND_TYPE_DX9_LOOP.
I use 'for loop' in shader.

My vertex shader is compiled as vs_2_0.
And, below is my HLSLcc command.

$ HLSLcc.exe -in=mytest.vso -out=result.glsl -lang=es100

Doesn't HLSLCrossCompiler support loop yet?

Regards.

group shared data always assumed to be single floats

The group shared data is always declared as a straight float array, regardless of the actual underlying type, and this causes garbage in output in some cases, as the name of the structured variable is uninitialized.

Example HLSL:
8<8<8<8<8<8<
Texture2D Input;
RWTexture2D Result;

define blocksize 8

define groupthreads (blocksize*blocksize)

groupshared float4 accum[groupthreads];

[numthreads(blocksize,blocksize,1)]
void main( uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint GI : SV_GroupIndex )
{
accum[GI] = Input[DTid.xy];

// Parallel reduction algorithm
GroupMemoryBarrierWithGroupSync();
if (GI < 32)
    accum[GI] += accum[32+GI];
GroupMemoryBarrierWithGroupSync();
if (GI < 16)
    accum[GI] += accum[16+GI];
GroupMemoryBarrierWithGroupSync();
if (GI < 8)
    accum[GI] += accum[8+GI];
GroupMemoryBarrierWithGroupSync();
if (GI < 4)
    accum[GI] += accum[4+GI];
GroupMemoryBarrierWithGroupSync();
if (GI < 2)
    accum[GI] += accum[2+GI];
GroupMemoryBarrierWithGroupSync();
if (GI < 1)
    accum[GI] += accum[1+GI];

if (GI == 0)
{                
    Result[uint2(Gid.x,Gid.y)] = accum[0] / groupthreads;
}

}
8<8<8<8<8<

Bytecode:

8<8<8<8<8<8<
//
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//
// Resource Bindings:
//
// Name Type Format Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// Input texture float4 2d 0 1
// Result UAV float4 2d 0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// no Input
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// no Output
cs_5_0
dcl_globalFlags refactoringAllowed
dcl_resource_texture2d (float,float,float,float) t0
dcl_uav_typed_texture2d (float,float,float,float) u0
dcl_input vThreadIDInGroupFlattened
dcl_input vThreadGroupID.xy
dcl_input vThreadID.xy
dcl_temps 3
dcl_tgsm_structured g0, 16, 64
dcl_thread_group 8, 8, 1
mov r0.xy, vThreadID.xyxx
mov r0.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r0.xyzw, r0.xyzw, t0.xyzw
store_structured g0.xyzw, vThreadIDInGroupFlattened.x, l(0), r0.xyzw
sync_g_t
ult r1.xyzw, vThreadIDInGroupFlattened.xxxx, l(32, 16, 8, 4)
if_nz r1.x
iadd r1.x, vThreadIDInGroupFlattened.x, l(32)
ld_structured r2.xyzw, r1.x, l(0), g0.xyzw
add r0.xyzw, r0.xyzw, r2.xyzw
store_structured g0.xyzw, vThreadIDInGroupFlattened.x, l(0), r0.xyzw
endif
sync_g_t
if_nz r1.y
iadd r0.x, vThreadIDInGroupFlattened.x, l(16)
ld_structured r0.xyzw, r0.x, l(0), g0.xyzw
ld_structured r2.xyzw, vThreadIDInGroupFlattened.x, l(0), g0.xyzw
add r0.xyzw, r0.xyzw, r2.xyzw
store_structured g0.xyzw, vThreadIDInGroupFlattened.x, l(0), r0.xyzw
endif
sync_g_t
if_nz r1.z
iadd r0.x, vThreadIDInGroupFlattened.x, l(8)
ld_structured r0.xyzw, r0.x, l(0), g0.xyzw
ld_structured r2.xyzw, vThreadIDInGroupFlattened.x, l(0), g0.xyzw
add r0.xyzw, r0.xyzw, r2.xyzw
store_structured g0.xyzw, vThreadIDInGroupFlattened.x, l(0), r0.xyzw
endif
sync_g_t
if_nz r1.w
iadd r0.x, vThreadIDInGroupFlattened.x, l(4)
ld_structured r0.xyzw, r0.x, l(0), g0.xyzw
ld_structured r1.xyzw, vThreadIDInGroupFlattened.x, l(0), g0.xyzw
add r0.xyzw, r0.xyzw, r1.xyzw
store_structured g0.xyzw, vThreadIDInGroupFlattened.x, l(0), r0.xyzw
endif
sync_g_t
ult r0.xy, vThreadIDInGroupFlattened.xxxx, l(2, 1, 0, 0)
if_nz r0.x
iadd r0.x, vThreadIDInGroupFlattened.x, l(2)
ld_structured r1.xyzw, r0.x, l(0), g0.xyzw
ld_structured r2.xyzw, vThreadIDInGroupFlattened.x, l(0), g0.xyzw
add r1.xyzw, r1.xyzw, r2.xyzw
store_structured g0.xyzw, vThreadIDInGroupFlattened.x, l(0), r1.xyzw
endif
sync_g_t
if_nz r0.y
ld_structured r0.xyzw, l(1), l(0), g0.xyzw
ld_structured r1.xyzw, l(0), l(0), g0.xyzw
add r0.xyzw, r0.xyzw, r1.xyzw
store_structured g0.xyzw, l(0), l(0), r0.xyzw
endif
if_z vThreadIDInGroupFlattened.x
ld_structured r0.xyzw, l(0), l(0), g0.xyzw
mul r0.xyzw, r0.xyzw, l(0.015625, 0.015625, 0.015625, 0.015625)
store_uav_typed u0.xyzw, vThreadGroupID.xyyy, r0.xyzw
endif
ret
// Approximately 58 instruction slots used
8<8<8<8<8<8<8<

Resulting GLSL:

8<8<8<8<8<8<8<8<

version 310 es

struct vec1 {
float x;
};
struct uvec1 {
uint x;
};
struct ivec1 {
int x;
};
precision lowp sampler3D;
precision lowp samplerCubeShadow;
precision lowp sampler2DShadow;
precision lowp sampler2DArray;
precision lowp sampler2DArrayShadow;
precision lowp isampler2D;
precision lowp isampler3D;
precision lowp isamplerCube;
precision lowp isampler2DArray;
precision lowp usampler2D;
precision lowp usampler3D;
precision lowp usamplerCube;
precision lowp usampler2DArray;
precision lowp isampler2DMS;
precision lowp usampler2D;
precision lowp usampler3D;
precision lowp usamplerCube;
precision lowp usampler2DArray;
precision lowp usampler2DMS;
precision lowp image2D;
precision lowp image3D;
precision lowp imageCube;
precision lowp image2DArray;
precision lowp iimage2D;
precision lowp iimage3D;
precision lowp iimageCube;
precision lowp uimage2DArray;
precision highp atomic_uint;
uniform sampler2D Input;
writeonly uniform image2D UAV0;
vec4 Temp[3];
ivec4 Temp_int[3];
uvec4 Temp_uint[3];
shared float TGSM0[256];
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
void main()
{
//--- Start Early Main ---
//--- End Early Main ---
//Instruction 0
//MOV
Temp_uint[0].xy = uvec4(gl_GlobalInvocationID.xyxx).xy;
//Instruction 1
//MOV
Temp[0].zw = vec4(vec4(0.000000, 0.000000, 0.000000, 0.000000)).zw;
//Instruction 2
//LD
Temp[0] = texelFetch(Input, ivec2((ivec4(Temp_uint[0])).xy), 0);
//Instruction 3
//STORE_STRUCTURED
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
//Instruction 4
//SYNC
groupMemoryBarrier();
memoryBarrierShared();
//Instruction 5
//ULT
Temp_uint[1] = uvec4(lessThan(uvec4(gl_LocalInvocationIndex.xxxx).xyzw, uvec4(uvec4(32u, 16u, 8u, 4u)).xyzw)) * 0xFFFFFFFFu;
//Instruction 6
//IF
if((Temp_uint[1].x)!=0u){
//Instruction 7
//IADD
Temp_uint[1].x = gl_LocalInvocationIndex.x + 32u;
//Instruction 8
//LD_STRUCTURED
Temp[2].x = TGSM0[Temp_uint[1].x].ô³üN´!;
Temp[2].y = TGSM0[Temp_uint[1].x].ô³üN´!;
Temp[2].z = TGSM0[Temp_uint[1].x].ô³üN´!;
Temp[2].w = TGSM0[Temp_uint[1].x].ô³üN´!;
//Instruction 9
//ADD
Temp[0] = vec4(Temp[0] + Temp[2]);
//Instruction 10
//STORE_STRUCTURED
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
//Instruction 11
//ENDIF
}
//Instruction 12
//SYNC
groupMemoryBarrier();
memoryBarrierShared();
//Instruction 13
//IF
if((Temp_uint[1].y)!=0u){
//Instruction 14
//IADD
Temp_uint[0].x = gl_LocalInvocationIndex.x + 16u;
//Instruction 15
//LD_STRUCTURED
Temp[0].x = TGSM0[Temp_uint[0].x].ô³üN´!;
Temp[0].y = TGSM0[Temp_uint[0].x].ô³üN´!;
Temp[0].z = TGSM0[Temp_uint[0].x].ô³üN´!;
Temp[0].w = TGSM0[Temp_uint[0].x].ô³üN´!;
//Instruction 16
//LD_STRUCTURED
Temp[2].x = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!;
Temp[2].y = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!;
Temp[2].z = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!;
Temp[2].w = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!;
//Instruction 17
//ADD
Temp[0] = vec4(Temp[0] + Temp[2]);
//Instruction 18
//STORE_STRUCTURED
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
//Instruction 19
//ENDIF
}
//Instruction 20
//SYNC
groupMemoryBarrier();
memoryBarrierShared();
//Instruction 21
//IF
if((Temp_uint[1].z)!=0u){
//Instruction 22
//IADD
Temp_uint[0].x = gl_LocalInvocationIndex.x + 8u;
//Instruction 23
//LD_STRUCTURED
Temp[0].x = TGSM0[Temp_uint[0].x].ô³üN´!;
Temp[0].y = TGSM0[Temp_uint[0].x].ô³üN´!;
Temp[0].z = TGSM0[Temp_uint[0].x].ô³üN´!;
Temp[0].w = TGSM0[Temp_uint[0].x].ô³üN´!;
//Instruction 24
//LD_STRUCTURED
Temp[2].x = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!;
Temp[2].y = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!;
Temp[2].z = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!;
Temp[2].w = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!;
//Instruction 25
//ADD
Temp[0] = vec4(Temp[0] + Temp[2]);
//Instruction 26
//STORE_STRUCTURED
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
//Instruction 27
//ENDIF
}
//Instruction 28
//SYNC
groupMemoryBarrier();
memoryBarrierShared();
//Instruction 29
//IF
if((Temp_uint[1].w)!=0u){
//Instruction 30
//IADD
Temp_uint[0].x = gl_LocalInvocationIndex.x + 4u;
//Instruction 31
//LD_STRUCTURED
Temp[0].x = TGSM0[Temp_uint[0].x].ô³üN´!;
Temp[0].y = TGSM0[Temp_uint[0].x].ô³üN´!;
Temp[0].z = TGSM0[Temp_uint[0].x].ô³üN´!;
Temp[0].w = TGSM0[Temp_uint[0].x].ô³üN´!;
//Instruction 32
//LD_STRUCTURED
Temp[1].x = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!;
Temp[1].y = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!;
Temp[1].z = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!;
Temp[1].w = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!;
//Instruction 33
//ADD
Temp[0] = vec4(Temp[0] + Temp[1]);
//Instruction 34
//STORE_STRUCTURED
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[0];
//Instruction 35
//ENDIF
}
//Instruction 36
//SYNC
groupMemoryBarrier();
memoryBarrierShared();
//Instruction 37
//ULT
Temp_uint[0].xy = uvec2(lessThan(uvec4(gl_LocalInvocationIndex.xxxx).xy, uvec4(uvec4(2u, 1u, 0u, 0u)).xy)) * 0xFFFFFFFFu;
//Instruction 38
//IF
if((Temp_uint[0].x)!=0u){
//Instruction 39
//IADD
Temp_uint[0].x = gl_LocalInvocationIndex.x + 2u;
//Instruction 40
//LD_STRUCTURED
Temp[1].x = TGSM0[Temp_uint[0].x].ô³üN´!;
Temp[1].y = TGSM0[Temp_uint[0].x].ô³üN´!;
Temp[1].z = TGSM0[Temp_uint[0].x].ô³üN´!;
Temp[1].w = TGSM0[Temp_uint[0].x].ô³üN´!;
//Instruction 41
//LD_STRUCTURED
Temp[2].x = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!;
Temp[2].y = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!;
Temp[2].z = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!;
Temp[2].w = TGSM0[gl_LocalInvocationIndex.x].ô³üN´!;
//Instruction 42
//ADD
Temp[1] = vec4(Temp[1] + Temp[2]);
//Instruction 43
//STORE_STRUCTURED
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[1];
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[1];
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[1];
TGSM0[gl_LocalInvocationIndex.x].ô³üN´! = Temp[1];
//Instruction 44
//ENDIF
}
//Instruction 45
//SYNC
groupMemoryBarrier();
memoryBarrierShared();
//Instruction 46
//IF
if((Temp_uint[0].y)!=0u){
//Instruction 47
//LD_STRUCTURED
Temp[0].x = TGSM0[1u].ô³üN´!;
Temp[0].y = TGSM0[1u].ô³üN´!;
Temp[0].z = TGSM0[1u].ô³üN´!;
Temp[0].w = TGSM0[1u].ô³üN´!;
//Instruction 48
//LD_STRUCTURED
Temp[1].x = TGSM0[0u].ô³üN´!;
Temp[1].y = TGSM0[0u].ô³üN´!;
Temp[1].z = TGSM0[0u].ô³üN´!;
Temp[1].w = TGSM0[0u].ô³üN´!;
//Instruction 49
//ADD
Temp[0] = vec4(Temp[0] + Temp[1]);
//Instruction 50
//STORE_STRUCTURED
TGSM0[0u].ô³üN´! = Temp[0];
TGSM0[0u].ô³üN´! = Temp[0];
TGSM0[0u].ô³üN´! = Temp[0];
TGSM0[0u].ô³üN´! = Temp[0];
//Instruction 51
//ENDIF
}
//Instruction 52
//IF
if((gl_LocalInvocationIndex.x)==0u){
//Instruction 53
//LD_STRUCTURED
Temp[0].x = TGSM0[0u].ô³üN´!;
Temp[0].y = TGSM0[0u].ô³üN´!;
Temp[0].z = TGSM0[0u].ô³üN´!;
Temp[0].w = TGSM0[0u].ô³üN´!;
//Instruction 54
//MUL
Temp[0] = vec4(Temp[0] * vec4(0.015625, 0.015625, 0.015625, 0.015625));
//Instruction 55
//STORE_UAV_TYPED
imageStore(UAV0, ivec2(gl_LocalInvocationID.xy), Temp[0]);
//Instruction 56
//ENDIF
}
//Instruction 57
//RET
return;
}

OPCODE_STORE_UAV_TYPED Index type cast wrong

Hi,

for the instruction OPCODE_STORE_UAV_TYPED, the coord parameters are already stored as an int in the temp registers or they need to be cast to int correctly. Currently a int/ivecX constructor is hard coded for the coord parameter and produces incorrect GLSL core.

dp2 result cast to ivec4 instead of vec4

in the following example the dp2 instruction result is passed to an ivec4 constructor, it's result gets truncated to integer and yields a wrong result


INPUT

cbuffer RenderTargetParams {
int Width;
int Height;
float AspectRatio;
}

struct VS_model0_ZNORMAL_Input {
float4 ObjectPosition : POSITION;
float3 Normal : NORMAL;

};

struct VS_model0_GATHER_Output {
float4 PixelPosition : SV_Position;
};

VS_model0_GATHER_Output main(VS_model0_ZNORMAL_Input input)
{
VS_model0_GATHER_Output output = (VS_model0_GATHER_Output)0;
float2 _screenuvnormalized;

_screenuvnormalized.xy = 1.0f - saturate(dot(input.ObjectPosition.xy,input.ObjectPosition.xy));
output.PixelPosition.xy = _screenuvnormalized;
output.PixelPosition.zw = float2(Width *2, Height *2);
return output;

}


OUTPUT

version 430

extension GL_ARB_shader_bit_encoding : require

struct vec1 {
float x;
};
struct uvec1 {
uint x;
};
struct ivec1 {
int x;
};
out gl_PerVertex {
vec4 gl_Position;
float gl_PointSize;
float gl_ClipDistance[];};
subroutine void SubroutineType();
layout(location = 0) uniform struct RenderTargetParamsVS_Type {
int Width;
int Height;
float AspectRatio;
} RenderTargetParamsVS;
layout(location = 0) in vec4 dcl_Input0;
vec4 Input0;

undef Output0

define Output0 phase0_Output0

vec4 phase0_Output0;
vec4 Temp[1];
ivec4 Temp_int[1];
uvec4 Temp_uint[1];
void main()
{
Input0 = dcl_Input0;
Temp_int[0].x = floatBitsToInt(ivec4(dot((Input0.xyxx).xy, (Input0.xyxx).xy)).x);
Temp_int[0].x = floatBitsToInt(vec4(min(intBitsToFloat(Temp_int[0]).x, 1.000000)).x);
Output0.xy = (vec4(-intBitsToFloat(Temp_int[0]).xxxx + vec4(1.000000, 1.000000, 0.000000, 0.000000))).xy;
Temp_int[0].xy = (RenderTargetParamsVS.Width << ivec4(0x1, 0x1, 0x0, 0x0)).xy;
Output0.zw = (vec4(Temp_int[0].xxxy).zw);
gl_Position = vec4(phase0_Output0);
return;
}

thank you for your time
Alberto

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.