Feat: added compile error output for shaders and implementet first ray
march
This commit is contained in:
4
fsq.vs
4
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);
|
||||
}
|
||||
)###";
|
||||
19
main.cpp
19
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<GLchar> errorLog(maxLength);
|
||||
char * errorLog = new char[maxLength]();
|
||||
glGetShaderInfoLog(fragmentShader, maxLength, &maxLength, errorLog);
|
||||
|
||||
printf("\nFrag Log: %s\n",errorLog);
|
||||
|
||||
}
|
||||
|
||||
return fragmentShader;
|
||||
}
|
||||
|
||||
|
||||
29
sdf.fs
29
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);
|
||||
}
|
||||
|
||||
}
|
||||
)###";
|
||||
Reference in New Issue
Block a user