Commit 224c559f authored by Johannes Braun's avatar Johannes Braun
Browse files

don't mind this commit, just testing around

parent 22ba22ef
......@@ -4,7 +4,7 @@
<item name="window_size_x" value="1440"/>
<item name="window_size_y" value="900"/>
<item name="vsync" value="0"/>
<item name="msaa" value="4"/>
<item name="msaa" value="2"/>
</group>
<group name="linespace">
......
......@@ -110,6 +110,6 @@ vec2 rand2D(int seed){
return hammersley2d(uint(rand(seed) * RANDOM_SAMPLING_FACTOR), INV_RANDOM_SAMPLING_FACTOR);
}
uniform int random_seed;
uniform int random_seed = 0;
#endif
......@@ -74,8 +74,8 @@ void main()
// TODO: Quite not that optimal.
float fresnel = clamp(schlickFresnel(-normalize(position.xyz - camera_position), normalize(normal.xyz), 1, 1.56), 0, 1);
float shininess = specular.a * fresnel;
shininess = mix(specular.a/2.f, specular.a, fresnel);
float shininess = specular.a;// * fresnel;
//shininess = mix(specular.a/2.f, specular.a, fresnel);
// environment reflection. Use the shininess value (which is the specular exponent divided by 100) as an interpolation value between the cubemap LODs.
float environment_factor = smoothstep(0.f, 1.f, 1 - shininess);
......@@ -84,12 +84,13 @@ void main()
final_color_part = vec4(0);
for(int i=0; i<b_lights.length() && !is_transparent; i++){
LightWithShadowmap light_and_map = b_lights[i];
final_color_part += phong(light_and_map, position.xyz, normal.xyz, camera_position, diffuse, specular, shininess) / b_lights.length();
final_color_part += phong(light_and_map, environment, position.xyz, normal.xyz, camera_position, diffuse, specular, shininess) / b_lights.length();
//final_color_part += ggxDistribution(normal.xyz, ggxHalfView(normalize(light_and_map.light.position.xyz - position.xyz), normalize(camera_position-position.xyz)), 0.5f);
}
// Now we can add the previously calculated environment reflection or refraction
vec4 reflection_tint = is_transparent ? diffuse : specular;
final_color_part = mix(final_color_part, reflection_tint * environment_reflect, shininess);
//final_color_part = mix(final_color_part, reflection_tint * environment_reflect, shininess);
}
// Add resulting color to the finished image, and compensate for multisampling
......
#ifndef __GBUFFER_LIGHTS_GLH
#define __GBUFFER_LIGHTS_GLH
#include <screenshader/gbuffer/cook_torrance.glsl>
struct Attenuation
{
float constant;
......@@ -139,37 +141,33 @@ bool sampleLight(const in LightWithShadowmap light_and_map, const in vec3 positi
return u_light_sample[light_and_map.light.data.light_type % 4](light_and_map, position, normal, camera, point_to_light, color);
}
float chiGGX(float v)
{
return v > 0 ? 1 : 0;
}
float GGX_Distribution(vec3 n, vec3 h, float alpha)
{
float NoH = dot(n,h);
float alpha2 = alpha * alpha;
float NoH2 = NoH * NoH;
float den = NoH2 * alpha2 + (1 - NoH2);
return (chiGGX(NoH) * alpha2) / ( 3.141592f * den * den );
}
float GGX_PartialGeometryTerm(vec3 v, vec3 n, vec3 h, float alpha)
{
float VoH2 = clamp(dot(v,h), 0, 1);
float chi = chiGGX( VoH2 / clamp(dot(v,n), 0, 1) );
VoH2 = VoH2 * VoH2;
float tan2 = ( 1 - VoH2 ) / VoH2;
return (chi * 2) / ( 1 + sqrt( 1 + alpha * alpha * tan2 ) );
}
vec4 phong(const in LightWithShadowmap light_and_map, const in vec3 position, const in vec3 normal, const in vec3 camera, const in vec4 diffuse, const in vec4 specular, float shininess, bool metallic = false)
vec4 phong(const in LightWithShadowmap light_and_map, samplerCube environment, const in vec3 position, const in vec3 normal, const in vec3 camera, const in vec4 diffuse, const in vec4 specular_color, float shininess, bool metallic = false)
{
vec4 color = vec4(0, 0, 0, 1);
vec3 point_to_light;
if(light_and_map.sampleLight(position, normal, camera, point_to_light, color)) {
vec3 eye = normalize(camera-position.xyz);
// vec3 half_vector = normalize(eye + point_to_light);
// vec3 half_view = ggxHalfView(point_to_light, eye);
// float roughness = 1-shininess;
//
// float metallic = 0.f;
//
// vec3 k_specular;
// vec3 specular = ggxSpecular(environment, normal.xyz, point_to_light, eye, roughness, normalResponse(diffuse.xyz, 1.56, metallic), k_specular);
// vec3 k_diffuse = clamp((1-k_specular) * (1-metallic), 0, 1);
//
// vec3 irradiance = textureLod(environment, normal, 8).rgb;
// vec3 diff = PI * diffuse.xyz * irradiance;
//
// return vec4(clamp(abs(k_diffuse * diff + k_specular * specular), 0, 1), 1);
// vec4 diffuse = color
// * ggxDistribution(normal, half_view, 1-shininess)
// * ggxPartialGeometry(eye, normal, half_view, 1-shininess)
// * vec4(fresnelSchlick(dot(eye, half_view), normalResponse(diffuse.rgb, 1.56, 1.f)), 1);
// return clamp(diffuse, 0, 1);
vec3 half_vector = normalize(eye + point_to_light);
vec3 reflection_vec = normalize(reflect(-point_to_light, normalize(normal.xyz)));
//DIFFUSE
......@@ -180,11 +178,15 @@ vec4 phong(const in LightWithShadowmap light_and_map, const in vec3 position, co
float cos_phi_n = pow(max(dot(reflection_vec, eye), 0.0f), 5+shininess*95);
// float cos_phi_n = GGX_Distribution(normal, half_vector, 1-shininess);
float f_metallic = metallic ? 1 :0;
float roughness = 1-shininess;
vec3 fresnel = fresnelSchlick(dot(eye, half_vector), normalResponse(diffuse.xyz, 1.56, f_metallic));
vec3 reflection = textureLod(environment, reflection_vec, roughness * 8).rgb;
vec4 phong_diffuse = (diffuse * cos_phi * color);
//If the material is metallic, tint the specular color with the diffuse color.
vec4 phong_specular = ((metallic ? diffuse : vec4(1)) * specular * cos_phi_n * color);
return phong_diffuse + phong_specular;
vec4 phong_specular = ((metallic ? diffuse : vec4(1)) * specular_color * cos_phi_n * color);
return (phong_diffuse + phong_specular);
}
else
{
......
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