diff --git a/fsq.vs b/fsq.vs index c53f5a8..b2bb5d6 100644 --- a/fsq.vs +++ b/fsq.vs @@ -3,11 +3,11 @@ R"###( layout (location = 0) in vec2 aPos; layout (location = 1) in vec2 aTexCoords; -out vec2 TexCoords; +out vec2 texCoords; void main() { - TexCoords = aTexCoords; + texCoords = aTexCoords; gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0); } -)###"; \ No newline at end of file +)###"; diff --git a/main.cpp b/main.cpp index c12ebc2..9cd9fec 100644 --- a/main.cpp +++ b/main.cpp @@ -14,7 +14,7 @@ const char *fragmentShaderSource = /*void framebuffer_size_callback(GLFWwindow* window, int width, int height) { - glViewport(0, 0, width, height); + glViewport(0, 0, wdth, height); }*/ void processInput(GLFWwindow *window) @@ -37,6 +37,23 @@ unsigned int compFragmentShader() { fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL); glCompileShader(fragmentShader); + + GLint isCompiled = 0; + glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &isCompiled); + if(isCompiled == GL_FALSE) + { + GLint maxLength = 0; + glGetShaderiv(fragmentShader, GL_INFO_LOG_LENGTH, &maxLength); + + // The maxLength includes the NULL character + //std::vector errorLog(maxLength); + char * errorLog = new char[maxLength](); + glGetShaderInfoLog(fragmentShader, maxLength, &maxLength, errorLog); + + printf("\nFrag Log: %s\n",errorLog); + + } + return fragmentShader; } diff --git a/sdf.fs b/sdf.fs index c61435a..bd53af9 100644 --- a/sdf.fs +++ b/sdf.fs @@ -1,9 +1,36 @@ R"###( #version 330 core + out vec4 FragColor; +in vec2 texCoords; + +vec3 center = vec3(0.0f,0.0f,20.0f); +float radius = 5.0f; + +float sphereMin(vec3 pos){ + return length(pos - center) - radius; +} void main() { - FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f); + vec3 ray = vec3(texCoords.x, texCoords.y,2.0f); + ray = (ray - 0.5f) * 2; + vec3 pos = ray; + float min = sphereMin(ray); + + while( (min < 100.0f) && (min > 0.1f) ) { + ray = normalize(ray); + ray = ray * min; + pos = pos + ray; + min = sphereMin(pos); + } + + + if(min <= 0.2f){ + FragColor = vec4(texCoords.x, texCoords.y, 0.2f, 1.0f); + } else { + FragColor = vec4(0.0f,0.0f,0.0f,1.0f); + } + } -)###"; \ No newline at end of file +)###";