Browse Source

点光源和blin

master
blobt 4 years ago
parent
commit
1735bdd3ff
  1. BIN
      .vs/shader3/v14/.suo
  2. 4
      main.cpp
  3. 0
      res/shader/dirLight.fs
  4. 0
      res/shader/dirLight.vs
  5. 31
      res/shader/test.fs

BIN
.vs/shader3/v14/.suo

4
main.cpp

@ -96,8 +96,8 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
float ambientLightColor[] = {0.4f,0.4f,0.4f,1.0f};
float ambientMaterial[] = { 0.2f,0.2f,0.2f,1.0f };
float diffuseLightColor[] = { 1.0f,1.0f,1.0f,1.0f };
float diffuseMaterial[] = { 0.8f,0.8f,0.8f,1.0f };
float lightPos[] = {1.0f,1.0f,0.0f,0.0f};
float diffuseMaterial[] = { 0.6f,0.6f,0.6f,1.0f };
float lightPos[] = {3.0f,3.0f,0.0f,1.0f};
float specularLightColor[] = { 1.0f,1.0f,1.0f,1.0f };
float specularMaterial[] = { 1.0f,1.0f,1.0f,1.0f };
float eyePos[] = { 0.0f,0.0f,0.0f };

res/shader/pointLight.fs → res/shader/dirLight.fs

res/shader/pointLight.vs → res/shader/dirLight.vs

31
res/shader/test.fs

@ -17,20 +17,35 @@ void main()
vec4 ambientColor = U_AmbientLightColor * U_AmbientMaterial;
//diffuse
vec3 L = normalize(U_LightPos.xyz);
vec3 L = vec3(0.0);
float distance = 0.0;
float attenuation = 1.0;
//light attribute
float constantFactor=0.5;
float linearFactor=0.3;
float expFactor=0.1;
if(U_LightPos.w==0.0){
//
L = normalize(U_LightPos.xyz);
} else {
//
//model point -> light pos
L = normalize(U_LightPos.xyz - V_WorldPos);
distance = length(U_LightPos.xyz - V_WorldPos);
attenuation = 1.0 / (constantFactor + linearFactor * distance + expFactor * distance * distance);
}
vec3 N = normalize(V_Normal);
float diffuseIntensity = max(0.0, dot(L,N));
vec4 diffuseColor = U_DiffuseLightColor * U_DiffuseMaterial * diffuseIntensity;
//specular
//vec3 reflectDir = normalize(reflect(-L,N));//-Lreflect
//vec3 viewDir = normalize(U_EyePos - V_WorldPos);
//vec4 specularColor = U_SpecularLightColor * U_SpecularMaterial * pow(max(0.0, dot(viewDir,reflectDir)), 64.0);
float diffuseIntensity = max(0.0, dot(L,N));
vec4 diffuseColor = U_DiffuseLightColor * U_DiffuseMaterial * diffuseIntensity * attenuation;
//specular blin
vec3 viewDir = normalize(U_EyePos - V_WorldPos);
vec3 M = normalize(L + viewDir);
vec4 specularColor = U_SpecularLightColor * U_SpecularMaterial * pow(max(0.0, dot(M,N)), 64.0);
vec4 specularColor = U_SpecularLightColor * U_SpecularMaterial * pow(max(0.0, dot(M,N)), 64.0) * attenuation;
gl_FragColor = ambientColor + diffuseColor + specularColor;
Loading…
Cancel
Save