diff options
author | Sebastian Park <SebPark03@gmail.com> | 2024-04-23 12:06:00 -0400 |
---|---|---|
committer | Sebastian Park <SebPark03@gmail.com> | 2024-04-23 12:06:00 -0400 |
commit | 12ec81fd1624e9b06e03d9a53a1873f63fe99c3b (patch) | |
tree | db528688bbf888cf0f147a698d061f5c7ae89560 /resources | |
parent | a556b45abf18f1bd509daaf63b66b7d55e9fd291 (diff) | |
parent | 6a5806b82c44a2cae481a6015d1a0f390e4b8445 (diff) |
Merge branch 'shaders'
Diffstat (limited to 'resources')
-rw-r--r-- | resources/images/anamorphic.jpg | bin | 0 -> 29950 bytes | |||
-rw-r--r-- | resources/images/caustic_sample.jpg | bin | 0 -> 87477 bytes | |||
-rw-r--r-- | resources/images/sand_text.jpg | bin | 0 -> 23150 bytes | |||
-rw-r--r-- | resources/images/uv1 copy.png | bin | 48020 -> 0 bytes | |||
-rw-r--r-- | resources/images/uv1.png | bin | 86064 -> 48020 bytes | |||
-rw-r--r-- | resources/images/uv1_cut.png | bin | 0 -> 86064 bytes | |||
-rwxr-xr-x | resources/shaders/shader.frag | 44 | ||||
-rwxr-xr-x | resources/shaders/shader.vert | 19 | ||||
-rw-r--r-- | resources/shaders/texture.frag | 24 | ||||
-rw-r--r-- | resources/shaders/texture.vert | 15 |
10 files changed, 85 insertions, 17 deletions
diff --git a/resources/images/anamorphic.jpg b/resources/images/anamorphic.jpg Binary files differnew file mode 100644 index 0000000..c3dceaf --- /dev/null +++ b/resources/images/anamorphic.jpg diff --git a/resources/images/caustic_sample.jpg b/resources/images/caustic_sample.jpg Binary files differnew file mode 100644 index 0000000..b6fec46 --- /dev/null +++ b/resources/images/caustic_sample.jpg diff --git a/resources/images/sand_text.jpg b/resources/images/sand_text.jpg Binary files differnew file mode 100644 index 0000000..6a64486 --- /dev/null +++ b/resources/images/sand_text.jpg diff --git a/resources/images/uv1 copy.png b/resources/images/uv1 copy.png Binary files differdeleted file mode 100644 index fcf4825..0000000 --- a/resources/images/uv1 copy.png +++ /dev/null diff --git a/resources/images/uv1.png b/resources/images/uv1.png Binary files differindex 82ff8ac..fcf4825 100644 --- a/resources/images/uv1.png +++ b/resources/images/uv1.png diff --git a/resources/images/uv1_cut.png b/resources/images/uv1_cut.png Binary files differnew file mode 100644 index 0000000..82ff8ac --- /dev/null +++ b/resources/images/uv1_cut.png diff --git a/resources/shaders/shader.frag b/resources/shaders/shader.frag index fc78890..7df2588 100755 --- a/resources/shaders/shader.frag +++ b/resources/shaders/shader.frag @@ -8,6 +8,7 @@ in vec3 pos; in vec3 refrPos; in float refrProb; in vec2 uv; +in float matIor; uniform sampler2D texture_img; @@ -22,6 +23,20 @@ uniform vec2 widthBounds; uniform vec2 lengthBounds; //uniform float test = 0; +float rand(vec2 n) { + return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453); +} + +float rand(float n) { + return fract(sin(n) * 43758.5453123); +} + +float rand(vec4 n) { +// vec2 first2 = vec2(n[0], n[1]); +//// return 1.f; + return rand(vec2(n[0] * rand(n[2]), n[1] * rand(n[3]))); +} + vec2 uvFromWorldPoint(vec3 point) { float u = (point.x - widthBounds[0]) / (widthBounds[1] - widthBounds[0]); float v = (point.z - lengthBounds[0]) / (lengthBounds[1] - lengthBounds[0]); @@ -47,21 +62,32 @@ void main() { // fragColor = vec4(fragColor.x, 0.f, fragColor.z, 1.f); // fragColor = vec4(test, test, test, 1.f); vec2 refrUV = uvFromWorldPoint(refrPos); - vec4 transmissive = vec4(vec3(refrUV, 1.f - refrUV.y), 1.f); + float beerAtt = exp(-length((pos - refrPos)) * 0.2f); // TODO: Make uniform + + vec4 diffuse = vec4(red * d, green * d, blue * d, 1.0f); + vec4 specular = vec4(1, 1, 1, 1) * pow(spec, 10.f); +// vec4 transmissive = vec4(vec3(refrUV, 1.f - refrUV.y), 1.f); + float waterBlurriness = 0.f; + vec2 refrUVBlurry = (1 - beerAtt) * vec2(rand(refrUV), rand(vec4(pos, d))) * waterBlurriness + refrUV; + vec4 transmissive = texture(sampler, vec2(refrUVBlurry)); + +// refrProb *= beerAtt; - fragColor = 0.25f * vec4(red * d, green * d, blue * d, 1.0f); // Diffuse - fragColor += 0.75f * vec4(1, 1, 1, 1) * pow(spec, 10.f); // Specular TODO: Pass multiplications as uniforms. + fragColor = 0.75f * diffuse; // Diffuse + fragColor += 0.6f * specular; // Specular TODO: Pass multiplications as uniforms. fragColor = clamp(fragColor, 0.f, 1.f); // Clamp - fragColor *= (1 - (refrProb / 1.f)); - fragColor += (refrProb / 1.5f) * transmissive; + fragColor *= (1 - ((beerAtt * refrProb) / 1.f)); + fragColor += ((beerAtt * refrProb) / 1.5f) * transmissive; // fragColor = transmissive * refrProb; fragColor = vec4(vec3(fragColor), 1.5f); // Dividing refrProb by 2 just for heuristic. Want more phong to show through. // fragColor = clamp(fragColor, 0.f, 1.f); // fragColor = vec4(refrProb, 0.f, 0.f, 1.f); - - // assign texture - fragColor = texture(texture_img, uv); - + // TODO: ACTUAL LIGHTING MODEL SHOULD BE SOMETHING LIKE + // VELOCITY * DIFFUSE + // (1 - refrProb) * SPECULAR + // refrProb * (BEER * TRANSMISSIVE + (1 - beerAtt) * VOLUME (which is somewhat diffuse too?)) + // Transmissive shouldn't just get darker, but blurrier as beer attenuation lowers. +// fragColor = texture(sampler, vec2(refrUV)); } diff --git a/resources/shaders/shader.vert b/resources/shaders/shader.vert index 8447dd9..750a4da 100755 --- a/resources/shaders/shader.vert +++ b/resources/shaders/shader.vert @@ -21,13 +21,15 @@ out vec3 pos; out vec3 refrPos; out float refrProb; out vec2 uv; +out float matIor; vec4 getRefrPos() { - float depth = -1.f; // TODO: Pass as uniform + float depth = -3.f; // TODO: Pass as uniform vec3 w_o = normalize(pos - camera_worldSpace); float cos_theta_i = dot(-w_o, normal_worldSpace); float n_i = 1; float n_t = 1.33f; +// matIor = n_t; float determinant = 1.f - (pow((n_i / n_t), 2.f) * (1.f - pow(cos_theta_i, 2.f))); float r0 = pow((n_i - n_t) / (n_i + n_t), 2.f); // variable required to calculate probability of reflection @@ -52,10 +54,11 @@ vec4 getRefrPos() { } void main() { - float depth = -2.f; - float dist = position.y - depth; +// float depth = -4.f; +// float dist = position.y - depth; float width = 81.f * 2.f; float length = 81.f * 2.f; + matIor = 1.33f; normal_cameraSpace = normalize(inverse(transpose(mat3(view))) * inverseTransposeModel * normal); camera_worldSpace = vec3(inverseView * vec4(0.f, 0.f, 0.f, 1.f)); @@ -63,11 +66,11 @@ void main() { pos = vec3(model * vec4(position, 1.f)); //vec3(model * vec4(objSpacePos, 1.f)); // pos = position; - float depthScale = dist / normal.y; - vec3 groundContactPoint = -(normal * depthScale) + position; // carries down to ground - groundContactPoint = vec3(model * vec4(position, 1)); - uv = vec2((position.x + 81.f) / (162.f), groundContactPoint.z); - uv = vec2(texCoords); +// float depthScale = dist / normal.y; +// vec3 groundContactPoint = -(normal * depthScale) + position; // carries down to ground +// groundContactPoint = vec3(model * vec4(position, 1)); +// uv = vec2((position.x + 81.f) / (162.f), groundContactPoint.z); +// uv = vec2(normal); vec4 refrPos_and_prob = getRefrPos(); refrPos = vec3(refrPos_and_prob); refrProb = clamp(refrPos_and_prob.w, 0.f, 1.f); diff --git a/resources/shaders/texture.frag b/resources/shaders/texture.frag new file mode 100644 index 0000000..c7a5956 --- /dev/null +++ b/resources/shaders/texture.frag @@ -0,0 +1,24 @@ +#version 330 core + +// TASK 16: Create a UV coordinate in variable +in vec2 uv; + +// TASK 8: Add a sampler2D uniform +uniform sampler2D sampler; + +// TASK 29: Add a bool on whether or not to filter the texture +uniform bool filtered; + +out vec4 fragColor; + +void main() +{ + // TASK 17: Set fragColor using the sampler2D at the UV coordinate + fragColor = texture(sampler, uv); + + // TASK 33: Invert fragColor's r, g, and b color channels if your bool is true + if(filtered){ + fragColor = vec4(1) - fragColor; + fragColor.w = 1; + } +} diff --git a/resources/shaders/texture.vert b/resources/shaders/texture.vert new file mode 100644 index 0000000..c87f366 --- /dev/null +++ b/resources/shaders/texture.vert @@ -0,0 +1,15 @@ +#version 330 core + +// TASK 15: add a second layout variable representing a UV coordinate +layout (location = 0) in vec3 position; +layout (location = 1) in vec2 uv_raw; + +// TASK 16: create an "out" variable representing a UV coordinate +out vec2 uv; + +void main() { + // TASK 16: assign the UV layout variable to the UV "out" variable + uv = uv_raw; + + gl_Position = vec4(position, 1.0); +} |