mirror of https://github.com/axmolengine/axmol.git
369 lines
9.2 KiB
C
369 lines
9.2 KiB
C
#if !defined(__EMSCRIPTEN__)
|
|
static const char sprite_lit_vs_gl2[] = R"(#version 120
|
|
#ifdef GL_ARB_shading_language_420pack
|
|
#extension GL_ARB_shading_language_420pack : require
|
|
#endif
|
|
|
|
struct VS_Input
|
|
{
|
|
vec3 Pos;
|
|
vec4 Color;
|
|
vec4 Normal;
|
|
vec4 Tangent;
|
|
vec2 UV1;
|
|
vec2 UV2;
|
|
};
|
|
|
|
struct VS_Output
|
|
{
|
|
vec4 PosVS;
|
|
vec4 Color;
|
|
vec2 UV;
|
|
vec3 WorldN;
|
|
vec3 WorldB;
|
|
vec3 WorldT;
|
|
vec4 PosP;
|
|
};
|
|
|
|
struct VS_ConstantBuffer
|
|
{
|
|
mat4 mCamera;
|
|
mat4 mCameraProj;
|
|
vec4 mUVInversed;
|
|
vec4 mflipbookParameter;
|
|
};
|
|
|
|
uniform VS_ConstantBuffer CBVS0;
|
|
|
|
attribute vec3 Input_Pos;
|
|
attribute vec4 Input_Color;
|
|
attribute vec4 Input_Normal;
|
|
attribute vec4 Input_Tangent;
|
|
attribute vec2 Input_UV1;
|
|
attribute vec2 Input_UV2;
|
|
varying vec4 _VSPS_Color;
|
|
varying vec2 _VSPS_UV;
|
|
varying vec3 _VSPS_WorldN;
|
|
varying vec3 _VSPS_WorldB;
|
|
varying vec3 _VSPS_WorldT;
|
|
varying vec4 _VSPS_PosP;
|
|
|
|
VS_Output _main(VS_Input Input)
|
|
{
|
|
VS_Output Output = VS_Output(vec4(0.0), vec4(0.0), vec2(0.0), vec3(0.0), vec3(0.0), vec3(0.0), vec4(0.0));
|
|
vec4 worldNormal = vec4((Input.Normal.xyz - vec3(0.5)) * 2.0, 0.0);
|
|
vec4 worldTangent = vec4((Input.Tangent.xyz - vec3(0.5)) * 2.0, 0.0);
|
|
vec4 worldBinormal = vec4(cross(worldNormal.xyz, worldTangent.xyz), 0.0);
|
|
vec4 worldPos = vec4(Input.Pos.x, Input.Pos.y, Input.Pos.z, 1.0);
|
|
Output.PosVS = CBVS0.mCameraProj * worldPos;
|
|
Output.Color = Input.Color;
|
|
vec2 uv1 = Input.UV1;
|
|
uv1.y = CBVS0.mUVInversed.x + (CBVS0.mUVInversed.y * uv1.y);
|
|
Output.UV = uv1;
|
|
Output.WorldN = worldNormal.xyz;
|
|
Output.WorldB = worldBinormal.xyz;
|
|
Output.WorldT = worldTangent.xyz;
|
|
Output.PosP = Output.PosVS;
|
|
return Output;
|
|
}
|
|
|
|
void main()
|
|
{
|
|
VS_Input Input;
|
|
Input.Pos = Input_Pos;
|
|
Input.Color = Input_Color;
|
|
Input.Normal = Input_Normal;
|
|
Input.Tangent = Input_Tangent;
|
|
Input.UV1 = Input_UV1;
|
|
Input.UV2 = Input_UV2;
|
|
VS_Output flattenTemp = _main(Input);
|
|
gl_Position = flattenTemp.PosVS;
|
|
_VSPS_Color = flattenTemp.Color;
|
|
_VSPS_UV = flattenTemp.UV;
|
|
_VSPS_WorldN = flattenTemp.WorldN;
|
|
_VSPS_WorldB = flattenTemp.WorldB;
|
|
_VSPS_WorldT = flattenTemp.WorldT;
|
|
_VSPS_PosP = flattenTemp.PosP;
|
|
}
|
|
|
|
)";
|
|
|
|
static const char sprite_lit_vs_gl3[] = R"(#version 330
|
|
#ifdef GL_ARB_shading_language_420pack
|
|
#extension GL_ARB_shading_language_420pack : require
|
|
#endif
|
|
|
|
struct VS_Input
|
|
{
|
|
vec3 Pos;
|
|
vec4 Color;
|
|
vec4 Normal;
|
|
vec4 Tangent;
|
|
vec2 UV1;
|
|
vec2 UV2;
|
|
};
|
|
|
|
struct VS_Output
|
|
{
|
|
vec4 PosVS;
|
|
vec4 Color;
|
|
vec2 UV;
|
|
vec3 WorldN;
|
|
vec3 WorldB;
|
|
vec3 WorldT;
|
|
vec4 PosP;
|
|
};
|
|
|
|
struct VS_ConstantBuffer
|
|
{
|
|
mat4 mCamera;
|
|
mat4 mCameraProj;
|
|
vec4 mUVInversed;
|
|
vec4 mflipbookParameter;
|
|
};
|
|
|
|
uniform VS_ConstantBuffer CBVS0;
|
|
|
|
layout(location = 0) in vec3 Input_Pos;
|
|
layout(location = 1) in vec4 Input_Color;
|
|
layout(location = 2) in vec4 Input_Normal;
|
|
layout(location = 3) in vec4 Input_Tangent;
|
|
layout(location = 4) in vec2 Input_UV1;
|
|
layout(location = 5) in vec2 Input_UV2;
|
|
centroid out vec4 _VSPS_Color;
|
|
centroid out vec2 _VSPS_UV;
|
|
out vec3 _VSPS_WorldN;
|
|
out vec3 _VSPS_WorldB;
|
|
out vec3 _VSPS_WorldT;
|
|
out vec4 _VSPS_PosP;
|
|
|
|
VS_Output _main(VS_Input Input)
|
|
{
|
|
VS_Output Output = VS_Output(vec4(0.0), vec4(0.0), vec2(0.0), vec3(0.0), vec3(0.0), vec3(0.0), vec4(0.0));
|
|
vec4 worldNormal = vec4((Input.Normal.xyz - vec3(0.5)) * 2.0, 0.0);
|
|
vec4 worldTangent = vec4((Input.Tangent.xyz - vec3(0.5)) * 2.0, 0.0);
|
|
vec4 worldBinormal = vec4(cross(worldNormal.xyz, worldTangent.xyz), 0.0);
|
|
vec4 worldPos = vec4(Input.Pos.x, Input.Pos.y, Input.Pos.z, 1.0);
|
|
Output.PosVS = worldPos * CBVS0.mCameraProj;
|
|
Output.Color = Input.Color;
|
|
vec2 uv1 = Input.UV1;
|
|
uv1.y = CBVS0.mUVInversed.x + (CBVS0.mUVInversed.y * uv1.y);
|
|
Output.UV = uv1;
|
|
Output.WorldN = worldNormal.xyz;
|
|
Output.WorldB = worldBinormal.xyz;
|
|
Output.WorldT = worldTangent.xyz;
|
|
Output.PosP = Output.PosVS;
|
|
return Output;
|
|
}
|
|
|
|
void main()
|
|
{
|
|
VS_Input Input;
|
|
Input.Pos = Input_Pos;
|
|
Input.Color = Input_Color;
|
|
Input.Normal = Input_Normal;
|
|
Input.Tangent = Input_Tangent;
|
|
Input.UV1 = Input_UV1;
|
|
Input.UV2 = Input_UV2;
|
|
VS_Output flattenTemp = _main(Input);
|
|
gl_Position = flattenTemp.PosVS;
|
|
_VSPS_Color = flattenTemp.Color;
|
|
_VSPS_UV = flattenTemp.UV;
|
|
_VSPS_WorldN = flattenTemp.WorldN;
|
|
_VSPS_WorldB = flattenTemp.WorldB;
|
|
_VSPS_WorldT = flattenTemp.WorldT;
|
|
_VSPS_PosP = flattenTemp.PosP;
|
|
}
|
|
|
|
)";
|
|
|
|
#endif
|
|
|
|
static const char sprite_lit_vs_gles2[] = R"(
|
|
|
|
struct VS_Input
|
|
{
|
|
vec3 Pos;
|
|
vec4 Color;
|
|
vec4 Normal;
|
|
vec4 Tangent;
|
|
vec2 UV1;
|
|
vec2 UV2;
|
|
};
|
|
|
|
struct VS_Output
|
|
{
|
|
vec4 PosVS;
|
|
vec4 Color;
|
|
vec2 UV;
|
|
vec3 WorldN;
|
|
vec3 WorldB;
|
|
vec3 WorldT;
|
|
vec4 PosP;
|
|
};
|
|
|
|
struct VS_ConstantBuffer
|
|
{
|
|
mat4 mCamera;
|
|
mat4 mCameraProj;
|
|
vec4 mUVInversed;
|
|
vec4 mflipbookParameter;
|
|
};
|
|
|
|
uniform VS_ConstantBuffer CBVS0;
|
|
|
|
attribute vec3 Input_Pos;
|
|
attribute vec4 Input_Color;
|
|
attribute vec4 Input_Normal;
|
|
attribute vec4 Input_Tangent;
|
|
attribute vec2 Input_UV1;
|
|
attribute vec2 Input_UV2;
|
|
varying vec4 _VSPS_Color;
|
|
varying vec2 _VSPS_UV;
|
|
varying vec3 _VSPS_WorldN;
|
|
varying vec3 _VSPS_WorldB;
|
|
varying vec3 _VSPS_WorldT;
|
|
varying vec4 _VSPS_PosP;
|
|
|
|
VS_Output _main(VS_Input Input)
|
|
{
|
|
VS_Output Output = VS_Output(vec4(0.0), vec4(0.0), vec2(0.0), vec3(0.0), vec3(0.0), vec3(0.0), vec4(0.0));
|
|
vec4 worldNormal = vec4((Input.Normal.xyz - vec3(0.5)) * 2.0, 0.0);
|
|
vec4 worldTangent = vec4((Input.Tangent.xyz - vec3(0.5)) * 2.0, 0.0);
|
|
vec4 worldBinormal = vec4(cross(worldNormal.xyz, worldTangent.xyz), 0.0);
|
|
vec4 worldPos = vec4(Input.Pos.x, Input.Pos.y, Input.Pos.z, 1.0);
|
|
Output.PosVS = CBVS0.mCameraProj * worldPos;
|
|
Output.Color = Input.Color;
|
|
vec2 uv1 = Input.UV1;
|
|
uv1.y = CBVS0.mUVInversed.x + (CBVS0.mUVInversed.y * uv1.y);
|
|
Output.UV = uv1;
|
|
Output.WorldN = worldNormal.xyz;
|
|
Output.WorldB = worldBinormal.xyz;
|
|
Output.WorldT = worldTangent.xyz;
|
|
Output.PosP = Output.PosVS;
|
|
return Output;
|
|
}
|
|
|
|
void main()
|
|
{
|
|
VS_Input Input;
|
|
Input.Pos = Input_Pos;
|
|
Input.Color = Input_Color;
|
|
Input.Normal = Input_Normal;
|
|
Input.Tangent = Input_Tangent;
|
|
Input.UV1 = Input_UV1;
|
|
Input.UV2 = Input_UV2;
|
|
VS_Output flattenTemp = _main(Input);
|
|
gl_Position = flattenTemp.PosVS;
|
|
_VSPS_Color = flattenTemp.Color;
|
|
_VSPS_UV = flattenTemp.UV;
|
|
_VSPS_WorldN = flattenTemp.WorldN;
|
|
_VSPS_WorldB = flattenTemp.WorldB;
|
|
_VSPS_WorldT = flattenTemp.WorldT;
|
|
_VSPS_PosP = flattenTemp.PosP;
|
|
}
|
|
|
|
)";
|
|
|
|
static const char sprite_lit_vs_gles3[] = R"(#version 300 es
|
|
|
|
struct VS_Input
|
|
{
|
|
vec3 Pos;
|
|
vec4 Color;
|
|
vec4 Normal;
|
|
vec4 Tangent;
|
|
vec2 UV1;
|
|
vec2 UV2;
|
|
};
|
|
|
|
struct VS_Output
|
|
{
|
|
vec4 PosVS;
|
|
vec4 Color;
|
|
vec2 UV;
|
|
vec3 WorldN;
|
|
vec3 WorldB;
|
|
vec3 WorldT;
|
|
vec4 PosP;
|
|
};
|
|
|
|
struct VS_ConstantBuffer
|
|
{
|
|
mat4 mCamera;
|
|
mat4 mCameraProj;
|
|
vec4 mUVInversed;
|
|
vec4 mflipbookParameter;
|
|
};
|
|
|
|
uniform VS_ConstantBuffer CBVS0;
|
|
|
|
layout(location = 0) in vec3 Input_Pos;
|
|
layout(location = 1) in vec4 Input_Color;
|
|
layout(location = 2) in vec4 Input_Normal;
|
|
layout(location = 3) in vec4 Input_Tangent;
|
|
layout(location = 4) in vec2 Input_UV1;
|
|
layout(location = 5) in vec2 Input_UV2;
|
|
centroid out vec4 _VSPS_Color;
|
|
centroid out vec2 _VSPS_UV;
|
|
out vec3 _VSPS_WorldN;
|
|
out vec3 _VSPS_WorldB;
|
|
out vec3 _VSPS_WorldT;
|
|
out vec4 _VSPS_PosP;
|
|
|
|
VS_Output _main(VS_Input Input)
|
|
{
|
|
VS_Output Output = VS_Output(vec4(0.0), vec4(0.0), vec2(0.0), vec3(0.0), vec3(0.0), vec3(0.0), vec4(0.0));
|
|
vec4 worldNormal = vec4((Input.Normal.xyz - vec3(0.5)) * 2.0, 0.0);
|
|
vec4 worldTangent = vec4((Input.Tangent.xyz - vec3(0.5)) * 2.0, 0.0);
|
|
vec4 worldBinormal = vec4(cross(worldNormal.xyz, worldTangent.xyz), 0.0);
|
|
vec4 worldPos = vec4(Input.Pos.x, Input.Pos.y, Input.Pos.z, 1.0);
|
|
Output.PosVS = worldPos * CBVS0.mCameraProj;
|
|
Output.Color = Input.Color;
|
|
vec2 uv1 = Input.UV1;
|
|
uv1.y = CBVS0.mUVInversed.x + (CBVS0.mUVInversed.y * uv1.y);
|
|
Output.UV = uv1;
|
|
Output.WorldN = worldNormal.xyz;
|
|
Output.WorldB = worldBinormal.xyz;
|
|
Output.WorldT = worldTangent.xyz;
|
|
Output.PosP = Output.PosVS;
|
|
return Output;
|
|
}
|
|
|
|
void main()
|
|
{
|
|
VS_Input Input;
|
|
Input.Pos = Input_Pos;
|
|
Input.Color = Input_Color;
|
|
Input.Normal = Input_Normal;
|
|
Input.Tangent = Input_Tangent;
|
|
Input.UV1 = Input_UV1;
|
|
Input.UV2 = Input_UV2;
|
|
VS_Output flattenTemp = _main(Input);
|
|
gl_Position = flattenTemp.PosVS;
|
|
_VSPS_Color = flattenTemp.Color;
|
|
_VSPS_UV = flattenTemp.UV;
|
|
_VSPS_WorldN = flattenTemp.WorldN;
|
|
_VSPS_WorldB = flattenTemp.WorldB;
|
|
_VSPS_WorldT = flattenTemp.WorldT;
|
|
_VSPS_PosP = flattenTemp.PosP;
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
static const char* get_sprite_lit_vs (EffekseerRendererGL::OpenGLDeviceType deviceType)
|
|
{
|
|
#if !defined(__EMSCRIPTEN__)
|
|
if (deviceType == EffekseerRendererGL::OpenGLDeviceType::OpenGL3)
|
|
return sprite_lit_vs_gl3;
|
|
if (deviceType == EffekseerRendererGL::OpenGLDeviceType::OpenGL2)
|
|
return sprite_lit_vs_gl2;
|
|
#endif
|
|
if (deviceType == EffekseerRendererGL::OpenGLDeviceType::OpenGLES3)
|
|
return sprite_lit_vs_gles3;
|
|
if (deviceType == EffekseerRendererGL::OpenGLDeviceType::OpenGLES2)
|
|
return sprite_lit_vs_gles2;
|
|
return nullptr;
|
|
}
|
|
|