0
我正在嘗試實現Blinn-Phong,Cool-Torrance和GGX light模型。我已經實現了前兩種燈光模型,但現在我試圖修復並找出如何在漫反射和光澤之間進行插值。在片段着色器中內插/混合反射和發亮
我的場景將由3行(每行是上述光模型之一)和10個球體組成,其中每個球體具有光澤因子.1較大並且立方體貼圖爲反射/漫反射紋理。
我想找到一些有用的關於如何做這種插值,但我想我現在使用谷歌搜索錯誤的東西。
我的片段着色器代碼現在看起來像這樣。 PS,我很抱歉代碼中留下的所有評論,但我相信它會幫助你看到我正在嘗試做什麼。
#version 410 core
#include "../Global/GlobalShader.inc"
#include "../Global/GlobalMesh.inc"
#include "../Global/GlobalLight.inc"
in vec3 Position;
in vec3 Normal;
in vec2 TexCoord;
uniform vec3 cameraPosition;
uniform samplerCube skybox;
uniform DirectionalLight directionalLight;
float specularStrength = 16.0; // to be implemented and be send at parameter
out vec4 gl_FragColor;
vec4 calculateDirectionalLight1(Light light, vec3 direction, vec3 normal, vec3 worldPosition, float specularIntensity, vec3 eyePosition, Material material, vec2 texCoord, vec4 diffuse)
{
vec3 diffuseFactor = (light.color * diffuse * (light.intensity * clamp(dot(normal, direction), 0.0, 1.0)));
vec3 viewDir = normalize(eyePosition - worldPosition);
vec3 reflectDir = normalize(reflect(-direction, normal));
float shininess = (material.shininess/1000.0);
float specularFactor = pow(clamp(dot(viewDir, reflectDir), 0.0, 1.0), specularIntensity);
vec3 specularColor = (light.color * material.specular) * (specularFactor * shininess);
//return vec4(pow((diffuseFactor + specularColor + light.ambient), GAMMA), 1.0);
return vec4(pow((diffuseFactor + specularColor), GAMMA), 1.0);
//return specularColor;
//return diffuseFactor;
//return shininess;
//return diffuse;
}
void main() {
vec4 tempColor = vec4(0.2);
//vec4 tempColor = vec4(1.0, 0.0, 0.0, 0.0);
//vec4 diffuse = vec4(texture(material.texture.diffuse, TexCoord.st).rgb, 1.0); // *material.diffuse) - vec4(1.0 - material.specular);
vec3 I = normalize(Position - cameraPosition);
vec3 R = reflect(I, normalize(Normal));
vec4 reflection = texture(skybox, R);
// fix blending/interpolation for light
float shininess = (material.shininess/1000.0);
//gl_FragColor = diffuse * (reflection * shininess) * material.specular;
//vec4 tempFinalDiffuse = mix(diffuse, reflection, shininess);
vec4 tempFinalDiffuse = mix(tempColor, reflection, shininess);
vec4 light = vec4(1.0);
light = calculateDirectionalLight1(directionalLight.light, directionalLight.position, Normal, Position, specularStrength, cameraPosition, material, TexCoord, tempFinalDiffuse);
//gl_FragColor = mix(tempFinalDiffuse, light, shininess);
//gl_FragColor = diffuse;
//gl_FragColor = vec4(shininess);
//gl_FragColor = tempFinalDiffuse * light;
//gl_FragColor = reflection;
gl_FragColor = light;
//gl_FragColor = tempFinalDiffuse;
}
「漫和光澤之間的插值*。*」你爲什麼會之間插入「瀰漫」和「光澤」? –
我不知道任何其他方式如何在改變光澤因子時混合/內插漫反射和鏡面反射。所以當材料很粗糙時,它不會反映任何東西,它什麼時候會反映更多。我在這裏做錯了什麼,或者我理解錯了什麼? –