Add mesh shaders to project

This commit is contained in:
baldurk
2015-12-31 22:38:55 +01:00
parent bebcf1b781
commit b51b50329f
11 changed files with 270 additions and 2 deletions
+3
View File
@@ -71,6 +71,9 @@ data/spv/textfs.spvo \
data/spv/genericvs.spvo \
data/spv/genericfs.spvo \
data/spv/fixedcolfs.spvo \
data/spv/meshvs.spvo \
data/spv/meshgs.spvo \
data/spv/meshfs.spvo \
data/sourcecodepro.ttfo
.PHONY: all
+3
View File
@@ -55,5 +55,8 @@ DECLARE_EMBED(textfs_spv);
DECLARE_EMBED(genericvs_spv);
DECLARE_EMBED(genericfs_spv);
DECLARE_EMBED(fixedcolfs_spv);
DECLARE_EMBED(meshvs_spv);
DECLARE_EMBED(meshgs_spv);
DECLARE_EMBED(meshfs_spv);
#undef DECLARE_EMBED
+3
View File
@@ -139,6 +139,9 @@ RESOURCE_textfs_spv TYPE_EMBED "spv/textfs.spv"
RESOURCE_genericvs_spv TYPE_EMBED "spv/genericvs.spv"
RESOURCE_genericfs_spv TYPE_EMBED "spv/genericfs.spv"
RESOURCE_fixedcolfs_spv TYPE_EMBED "spv/fixedcolfs.spv"
RESOURCE_meshvs_spv TYPE_EMBED "spv/meshvs.spv"
RESOURCE_meshgs_spv TYPE_EMBED "spv/meshfs.spv"
RESOURCE_meshfs_spv TYPE_EMBED "spv/meshfs.spv"
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
+3
View File
@@ -41,6 +41,9 @@
#define RESOURCE_genericvs_spv 406
#define RESOURCE_genericfs_spv 407
#define RESOURCE_fixedcolfs_spv 408
#define RESOURCE_meshvs_spv 409
#define RESOURCE_meshgs_spv 410
#define RESOURCE_meshfs_spv 411
#if !defined(STRINGIZE)
#define STRINGIZE2(a) #a
+78
View File
@@ -0,0 +1,78 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2015 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#version 420 core
// VKTODOHIGH LunarG sample driver doesn't support in/out blocks yet it seems
/*
in v2f
{
vec4 secondary;
vec4 norm;
} IN;
*/
layout (location = 0) in vec4 INsecondary;
layout (location = 1) in vec4 INnorm;
layout (binding = 0, std140) uniform meshuniforms
{
mat4 mvp;
mat4 invProj;
vec4 color;
uint displayFormat;
uint homogenousInput;
vec2 pointSpriteSize;
} Mesh;
layout (location = 0) out vec4 color_out;
#define MESHDISPLAY_SOLID 0x1
#define MESHDISPLAY_FACELIT 0x2
#define MESHDISPLAY_SECONDARY 0x3
#define MESHDISPLAY_SECONDARY_ALPHA 0x4
void main(void)
{
uint type = Mesh.displayFormat;
if(type == MESHDISPLAY_SECONDARY)
{
color_out = vec4(INsecondary.xyz, 1);
}
else if(type == MESHDISPLAY_SECONDARY_ALPHA)
{
color_out = vec4(INsecondary.www, 1);
}
else if(type == MESHDISPLAY_FACELIT)
{
vec3 lightDir = normalize(vec3(0, -0.3f, -1));
color_out = vec4(Mesh.color.xyz*abs(dot(lightDir, INnorm.xyz)), 1);
}
else //if(type == MESHDISPLAY_SOLID)
{
color_out = vec4(Mesh.color.xyz, 1);
}
}
+73
View File
@@ -0,0 +1,73 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2015 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#version 420 core
layout(triangles, invocations = 1) in;
layout(triangle_strip, max_vertices = 3) out;
in v2f
{
vec4 secondary;
vec4 norm;
} IN[];
out v2f
{
vec4 secondary;
vec4 norm;
} OUT;
layout (binding = 0, std140) uniform meshuniforms
{
mat4 mvp;
mat4 invProj;
vec4 color;
uint displayFormat;
uint homogenousInput;
vec2 pointSpriteSize;
} Mesh;
out gl_PerVertex
{
vec4 gl_Position;
float gl_PointSize;
float gl_ClipDistance[];
};
void main()
{
vec4 faceEdgeA = (Mesh.invProj * gl_in[1].gl_Position) - (Mesh.invProj * gl_in[0].gl_Position);
vec4 faceEdgeB = (Mesh.invProj * gl_in[2].gl_Position) - (Mesh.invProj * gl_in[0].gl_Position);
vec3 faceNormal = normalize( cross(faceEdgeA.xyz, faceEdgeB.xyz) );
for(int i=0; i < 3; i++)
{
gl_Position = gl_in[i].gl_Position;
OUT.secondary = IN[i].secondary;
OUT.norm = vec4(faceNormal.xyz, 1);
EmitVertex();
}
EndPrimitive();
}
+81
View File
@@ -0,0 +1,81 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2014 Crytek
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#version 420 core
layout (location = 0) in vec4 position;
layout (location = 1) in vec4 secondary;
layout (binding = 0, std140) uniform meshuniforms
{
mat4 mvp;
mat4 invProj;
vec4 color;
uint displayFormat;
uint homogenousInput;
vec2 pointSpriteSize;
} Mesh;
out gl_PerVertex
{
vec4 gl_Position;
float gl_PointSize;
float gl_ClipDistance[];
};
// VKTODOHIGH LunarG sample driver doesn't support in/out blocks yet it seems
/*
out v2f
{
vec4 secondary;
vec4 norm;
} OUT;
*/
layout (location = 0) out vec4 OUTsecondary;
layout (location = 1) out vec4 OUTnorm;
void main(void)
{
vec2 psprite[4] =
{
vec2(-1.0f, -1.0f),
vec2(-1.0f, 1.0f),
vec2( 1.0f, -1.0f),
vec2( 1.0f, 1.0f)
};
vec4 pos = position;
if(Mesh.homogenousInput == 0)
pos = vec4(position.xyz, 1);
gl_Position = Mesh.mvp * pos;
gl_Position.xy += Mesh.pointSpriteSize.xy*0.01f*psprite[gl_VertexID%4]*gl_Position.w;
OUTsecondary = secondary;
OUTnorm = vec4(0, 0, 1, 1);
// GL->VK conventions
gl_Position.y = -gl_Position.y;
gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;
}
+1 -1
View File
@@ -27,7 +27,7 @@
layout (binding = 3) uniform sampler2D tex0;
layout (location = 0) out vec4 color_out;
// LunarG sample driver doesn't support in/out blocks yet it seems
// VKTODOHIGH LunarG sample driver doesn't support in/out blocks yet it seems
/*
in v2f
{
+1 -1
View File
@@ -57,7 +57,7 @@ out gl_PerVertex
float gl_ClipDistance[];
};
// LunarG sample driver doesn't support in/out blocks yet it seems
// VKTODOHIGH LunarG sample driver doesn't support in/out blocks yet it seems
/*
out v2f
{
+6
View File
@@ -367,6 +367,12 @@
<None Include="data\spv\generic.vert" />
<None Include="data\spv\genericfs.spv" />
<None Include="data\spv\genericvs.spv" />
<None Include="data\spv\mesh.frag" />
<None Include="data\spv\mesh.geom" />
<None Include="data\spv\mesh.vert" />
<None Include="data\spv\meshfs.spv" />
<None Include="data\spv\meshgs.spv" />
<None Include="data\spv\meshvs.spv" />
<None Include="data\spv\texdisplay.frag" />
<None Include="data\spv\texdisplayfs.spv" />
<None Include="data\spv\text.frag" />
+18
View File
@@ -478,6 +478,24 @@
<None Include="data\spv\fixedcolfs.spv">
<Filter>Resources\spv</Filter>
</None>
<None Include="data\spv\mesh.frag">
<Filter>Resources\spv</Filter>
</None>
<None Include="data\spv\mesh.geom">
<Filter>Resources\spv</Filter>
</None>
<None Include="data\spv\mesh.vert">
<Filter>Resources\spv</Filter>
</None>
<None Include="data\spv\meshgs.spv">
<Filter>Resources\spv</Filter>
</None>
<None Include="data\spv\meshvs.spv">
<Filter>Resources\spv</Filter>
</None>
<None Include="data\spv\meshfs.spv">
<Filter>Resources\spv</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="data\renderdoc.rc">