Close to seeing something on the screen :D!

parent acdb3a8c
......@@ -9,6 +9,8 @@ SRCDIR = src
INCDIR = inc
OBJDIR = obj
BINDIR = bin
SHABIN = $(BINDIR)/shaders
SHADIR = shaders
#Flags
TARGET = learn
......@@ -20,6 +22,13 @@ CXX = g++
LINKER = g++
LFLAGS = -Wall -I$(INCDIR) $(LIBS)
#Shader Compilation - output to SPIR-V bytecode
GL = $(VULKAN_SDK_PATH)/bin/glslangValidator
GLFLAGS = -V
V_SHAD = $(SHADIR)/shader.vert
F_SHAD = $(SHADIR)/shader.frag
#Internal Vars
SOURCES := $(wildcard $(SRCDIR)/*.cpp)
......@@ -28,7 +37,7 @@ OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
#Main Rules
$(BINDIR)/$(TARGET): $(OBJECTS)
$(BINDIR)/$(TARGET): $(OBJECTS) vertex-shader fragment-shader
@$(LINKER) $(OBJECTS) $(LFLAGS) -o $@
@echo "Successfully linked "$@" at "$(shell date)
......@@ -38,7 +47,15 @@ $(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp
.PHONY: clean
clean:
-rm -f obj/* bin/*
-rm -rf obj/* bin/*
vertex-shader:
-mkdir -p $(SHABIN)
@$(GL) $(GLFLAGS) $(V_SHAD) -o $(SHABIN)/vert.spv
fragment-shader:
-mkdir -p $(SHABIN)
@$(GL) $(GLFLAGS) $(F_SHAD) -o $(SHABIN)/frag.spv
install:
@echo "Not Yet Implemented"
File added
File added
#version 450
#extension GL_ARB_separate_shader_objects : enable
// We need this extension for vulkan shaders to work.
//Input the fragment color from framebuffer 0, coming from the rasterizer.
layout(location = 0) in vec3 fragColor;
//There's no builtin to output the current fragment's color.
// We need our own output variable. layout(...) is the index of the framebuffer; 0, in this case.
layout(location = 0) out vec4 outColor;
//Called once per fragment.
void main() {
outColor = vec4(fragColor, 1.0); //outColor will automatically fill in missing colors - be interpolated.
// Since, fragColor only is truly defined where the vertices are.
//outColor is linked to the framebuffer existing at index 0.
}
#version 450
#extension GL_ARB_separate_shader_objects : enable
// We need this extension for vulkan shaders to work.
//GLSL functions using global variables.
//Output the fragment color to the framebuffer existing at index 0.
layout(location = 0) out vec3 fragColor;
out gl_PerVertex {
vec4 gl_Position;
};
vec2 positions[3] = vec2[](
vec2(0.0, -0.5),
vec2(0.5, 0.5),
vec2(-0.5, 0.5)
);
//Let's make per-vertex colors!
vec3 colors[3] = vec3[](
vec3(1.0, 0.0, 0.0),
vec3(0.0, 1.0, 0.0),
vec3(0.0, 0.0, 1.0)
);
// Main is invoked for every vertex.
void main() {
// gl_VertexIndex contains the index of the current vertex.
// Usually indexing into the vertex buffer - here, into the hardcoded positions array.
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
fragColor = colors[gl_VertexIndex]; //Set the per-vertex fragment color. The fragment shader will interpolate.
//The position is made from these positions with dummy z and w components, to make clip coordinates.
//gl_Position is, as a global variable, the output.
}
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment