From 5972ffa661a72f73efd13a8e9e30efb879ab0879 Mon Sep 17 00:00:00 2001 From: baldurk Date: Sun, 25 Jan 2015 19:31:47 +0000 Subject: [PATCH] Implement mesh-specific fragment shader to display secondary data --- renderdoc/Makefile | 5 +++ renderdoc/data/embedded_files.h | 2 + renderdoc/data/glsl/mesh.frag | 62 +++++++++++++++++++++++++++++ renderdoc/data/glsl/mesh.geom | 25 ++++++++++++ renderdoc/data/glsl/mesh.vert | 11 ++++- renderdoc/data/renderdoc.rc | 2 + renderdoc/data/resource.h | 2 + renderdoc/driver/gl/gl_debug.cpp | 12 +++++- renderdoc/renderdoc.vcxproj | 2 + renderdoc/renderdoc.vcxproj.filters | 6 +++ 10 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 renderdoc/data/glsl/mesh.frag create mode 100644 renderdoc/data/glsl/mesh.geom diff --git a/renderdoc/Makefile b/renderdoc/Makefile index 51cb90944..6ce0c2fcc 100644 --- a/renderdoc/Makefile +++ b/renderdoc/Makefile @@ -69,6 +69,8 @@ data/glsl/checkerboard.frago \ data/glsl/generic.frago \ data/glsl/generic.verto \ data/glsl/mesh.verto \ +data/glsl/mesh.frago \ +data/glsl/mesh.geomo \ data/glsl/text.verto \ data/glsl/text.frago \ data/glsl/histogram.compo \ @@ -102,6 +104,9 @@ $(OBJDIR)/%.verto: %.vert $(OBJDIR)/%.frago: %.frag @echo Object building $@ @$(OBJGEN) +$(OBJDIR)/%.geomo: %.geom + @echo Object building $@ + @$(OBJGEN) $(OBJDIR)/%.compo: %.comp @echo Object building $@ @$(OBJGEN) diff --git a/renderdoc/data/embedded_files.h b/renderdoc/data/embedded_files.h index ae607aea0..e4ba52471 100644 --- a/renderdoc/data/embedded_files.h +++ b/renderdoc/data/embedded_files.h @@ -36,6 +36,8 @@ DECLARE_EMBED(texdisplay_frag); DECLARE_EMBED(checkerboard_frag); DECLARE_EMBED(histogram_comp); DECLARE_EMBED(mesh_vert); +DECLARE_EMBED(mesh_frag); +DECLARE_EMBED(mesh_geom); DECLARE_EMBED(generic_vert); DECLARE_EMBED(generic_frag); DECLARE_EMBED(text_frag); diff --git a/renderdoc/data/glsl/mesh.frag b/renderdoc/data/glsl/mesh.frag new file mode 100644 index 000000000..156de3def --- /dev/null +++ b/renderdoc/data/glsl/mesh.frag @@ -0,0 +1,62 @@ +/****************************************************************************** + * 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. + ******************************************************************************/ + +in v2f +{ + vec4 secondary; + vec4 norm; +} IN; + +layout (location = 0) out vec4 color_out; + +uniform vec4 RENDERDOC_GenericFS_Color; + +uniform uint Mesh_DisplayFormat; + +void main(void) +{ + uint type = Mesh_DisplayFormat; + + if(type == MESHDISPLAY_SECONDARY) + { + color_out = vec4(IN.secondary.xyz, 1); + } + else if(type == MESHDISPLAY_SECONDARY_ALPHA) + { + color_out = vec4(IN.secondary.www, 1); + } + else if(type == MESHDISPLAY_FACELIT) + { + color_out = vec4(0, 1, 0, 1); + /* + float3 lightDir = normalize(float3(0, -0.3f, -1)); + + return float4(WireframeColour.xyz*saturate(dot(lightDir, IN.norm)), 1); + */ + } + else //if(type == MESHDISPLAY_SOLID) + { + color_out = vec4(RENDERDOC_GenericFS_Color.xyz, 1); + } +} diff --git a/renderdoc/data/glsl/mesh.geom b/renderdoc/data/glsl/mesh.geom new file mode 100644 index 000000000..494c5da04 --- /dev/null +++ b/renderdoc/data/glsl/mesh.geom @@ -0,0 +1,25 @@ +/****************************************************************************** + * 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 diff --git a/renderdoc/data/glsl/mesh.vert b/renderdoc/data/glsl/mesh.vert index 1ecac3821..01bfa4e02 100644 --- a/renderdoc/data/glsl/mesh.vert +++ b/renderdoc/data/glsl/mesh.vert @@ -25,10 +25,19 @@ #version 420 core layout (location = 0) in vec4 position; +layout (location = 1) in vec4 secondary; uniform mat4 ModelViewProj; +out v2f +{ + vec4 secondary; + vec4 norm; +} OUT; + void main(void) { - gl_Position = ModelViewProj * position; + gl_Position = ModelViewProj * position; + OUT.secondary = secondary; + OUT.norm = vec4(0, 0, 0, 0); } diff --git a/renderdoc/data/renderdoc.rc b/renderdoc/data/renderdoc.rc index f631e4eb0..28f7e8099 100644 --- a/renderdoc/data/renderdoc.rc +++ b/renderdoc/data/renderdoc.rc @@ -121,6 +121,8 @@ RESOURCE_text_vert TYPE_EMBED "glsl/text.vert" RESOURCE_text_frag TYPE_EMBED "glsl/text.frag" RESOURCE_texsample_h TYPE_EMBED "glsl/texsample.h" RESOURCE_histogram_comp TYPE_EMBED "glsl/histogram.comp" +RESOURCE_mesh_frag TYPE_EMBED "glsl/mesh.frag" +RESOURCE_mesh_geom TYPE_EMBED "glsl/mesh.geom" RESOURCE_sourcecodepro_ttf TYPE_EMBED "sourcecodepro.ttf" diff --git a/renderdoc/data/resource.h b/renderdoc/data/resource.h index 7a27e30d1..054458cab 100644 --- a/renderdoc/data/resource.h +++ b/renderdoc/data/resource.h @@ -23,6 +23,8 @@ #define RESOURCE_text_frag 210 #define RESOURCE_texsample_h 211 #define RESOURCE_histogram_comp 212 +#define RESOURCE_mesh_frag 213 +#define RESOURCE_mesh_geom 214 #define RESOURCE_sourcecodepro_ttf 301 diff --git a/renderdoc/driver/gl/gl_debug.cpp b/renderdoc/driver/gl/gl_debug.cpp index c55234373..907d7cc40 100644 --- a/renderdoc/driver/gl/gl_debug.cpp +++ b/renderdoc/driver/gl/gl_debug.cpp @@ -173,8 +173,10 @@ void GLReplay::InitDebugData() DebugData.genericProg = CreateShaderProgram(DebugData.genericvsSource.c_str(), DebugData.genericfsSource.c_str()); string meshvs = GetEmbeddedResource(mesh_vert); + string meshfs = GetEmbeddedResource(mesh_frag); + meshfs = glslheader + meshfs; - DebugData.meshProg = CreateShaderProgram(meshvs.c_str(), DebugData.genericfsSource.c_str()); + DebugData.meshProg = CreateShaderProgram(meshvs.c_str(), meshfs.c_str()); WrappedOpenGL &gl = *m_pDriver; @@ -1591,13 +1593,15 @@ void GLReplay::RenderMesh(uint32_t frameID, uint32_t eventID, const vector + + diff --git a/renderdoc/renderdoc.vcxproj.filters b/renderdoc/renderdoc.vcxproj.filters index 748ea601c..e8a767bfa 100644 --- a/renderdoc/renderdoc.vcxproj.filters +++ b/renderdoc/renderdoc.vcxproj.filters @@ -595,6 +595,12 @@ Resources\glsl + + Resources\glsl + + + Resources\glsl +