Browse Source

点光源架构调整

master
blobt 4 years ago
parent
commit
0b1e137032
  1. BIN
      .vs/shader3/v14/.suo
  2. 4
      main.cpp
  3. 39
      res/shader/pointLight.fs
  4. 19
      res/shader/pointLight.vs
  5. 32
      res/shader/specular.fs
  6. 19
      res/shader/specular.vs
  7. 11
      res/shader/test.fs
  8. 3
      res/shader/test.vs

BIN
.vs/shader3/v14/.suo

4
main.cpp

@ -97,7 +97,7 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
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};
float lightPos[] = {1.0f,1.0f,0.0f,0.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 };
@ -137,7 +137,7 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
glUniform4fv(gpuProgram.GetLocation("U_AmbientMaterial"), 1, ambientMaterial);
glUniform4fv(gpuProgram.GetLocation("U_DiffuseLightColor"), 1, diffuseLightColor);
glUniform4fv(gpuProgram.GetLocation("U_DiffuseMaterial"), 1, diffuseMaterial);
glUniform3fv(gpuProgram.GetLocation("U_LightPos"), 1, lightPos);
glUniform4fv(gpuProgram.GetLocation("U_LightPos"), 1, lightPos);
glUniform4fv(gpuProgram.GetLocation("U_SpecularLightColor"), 1, specularLightColor);
glUniform4fv(gpuProgram.GetLocation("U_SpecularMaterial"), 1, specularMaterial);
glUniform3fv(gpuProgram.GetLocation("U_EyePos"), 1, eyePos);

39
res/shader/pointLight.fs

@ -0,0 +1,39 @@
uniform vec4 U_AmbientLightColor;
uniform vec4 U_AmbientMaterial;
uniform vec4 U_LightPos;
uniform vec4 U_DiffuseLightColor;
uniform vec4 U_DiffuseMaterial;
uniform vec3 U_EyePos;
uniform vec4 U_SpecularLightColor;
uniform vec4 U_SpecularMaterial;
varying vec3 V_Normal;
varying vec3 V_WorldPos;
void main()
{
//ambient
vec4 ambientColor = U_AmbientLightColor * U_AmbientMaterial;
//diffuse
vec3 L = vec3(0.0);
if(U_LightPos.w==0.0){
//
L = normalize(U_LightPos.xyz);
} else {
//
//model point -> light pos
}
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);
gl_FragColor = ambientColor + diffuseColor + specularColor;
}

19
res/shader/pointLight.vs

@ -0,0 +1,19 @@
attribute vec3 pos;
attribute vec2 texcoord;
attribute vec3 normal;
uniform mat4 M;
uniform mat4 P;
uniform mat4 V;
uniform mat4 NM;//Normal Matrix 使用来修正法线的
varying vec3 V_Normal;
varying vec3 V_WorldPos;
void main()
{
V_Normal = mat3(NM)*normal;
vec4 worldPos = M * vec4(pos, 1.0);
V_WorldPos = worldPos.xyz;
gl_Position=P*V*M*vec4(pos,1.0);
}

32
res/shader/specular.fs

@ -0,0 +1,32 @@
uniform vec4 U_AmbientLightColor;
uniform vec4 U_AmbientMaterial;
uniform vec3 U_LightPos;
uniform vec4 U_DiffuseLightColor;
uniform vec4 U_DiffuseMaterial;
uniform vec3 U_EyePos;
uniform vec4 U_SpecularLightColor;
uniform vec4 U_SpecularMaterial;
varying vec3 V_Normal;
varying vec3 V_WorldPos;
void main()
{
//ambient
vec4 ambientColor = U_AmbientLightColor * U_AmbientMaterial;
//diffuse
vec3 N = normalize(V_Normal);
vec3 L = normalize(U_LightPos);
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);
gl_FragColor = ambientColor + diffuseColor + specularColor;
}

19
res/shader/specular.vs

@ -0,0 +1,19 @@
attribute vec3 pos;
attribute vec2 texcoord;
attribute vec3 normal;
uniform mat4 M;
uniform mat4 P;
uniform mat4 V;
uniform mat4 NM;//Normal Matrix 使用来修正法线的
varying vec3 V_Normal;
varying vec3 V_WorldPos;
void main()
{
V_Normal = mat3(NM)*normal;
vec4 worldPos = M * vec4(pos, 1.0);
V_WorldPos = worldPos.xyz;
gl_Position=P*V*M*vec4(pos,1.0);
}

11
res/shader/test.fs

@ -1,6 +1,6 @@
uniform vec4 U_AmbientLightColor;
uniform vec4 U_AmbientMaterial;
uniform vec3 U_LightPos;
uniform vec4 U_LightPos;
uniform vec4 U_DiffuseLightColor;
uniform vec4 U_DiffuseMaterial;
uniform vec3 U_EyePos;
@ -17,8 +17,15 @@ void main()
vec4 ambientColor = U_AmbientLightColor * U_AmbientMaterial;
//diffuse
vec3 L = vec3(0.0);
if(U_LightPos.w==0.0){
//ÕâÊÇ·½Ïò¹â
L = normalize(U_LightPos.xyz);
} else {
//ÕâÊǵã¹âÔ´
//model point -> light pos
}
vec3 N = normalize(V_Normal);
vec3 L = normalize(U_LightPos);
float diffuseIntensity = max(0.0, dot(L,N));
vec4 diffuseColor = U_DiffuseLightColor * U_DiffuseMaterial * diffuseIntensity;

3
res/shader/test.vs

@ -12,7 +12,8 @@ varying vec3 V_WorldPos;
void main()
{
V_Normal = mat3(NM)*normal;
V_WorldPos = M * vec4(pos, 1.0);
vec4 worldPos = M * vec4(pos, 1.0);
V_WorldPos = worldPos.xyz;
gl_Position=P*V*M*vec4(pos,1.0);
}
Loading…
Cancel
Save