diff --git a/Res/diffuse_vs .vs b/Res/diffuse_vs .vs
new file mode 100644
index 0000000..a93c5f8
--- /dev/null
+++ b/Res/diffuse_vs .vs
@@ -0,0 +1,30 @@
+#ifdef GL_ES
+precision mediump float;
+#endif;
+attribute vec4 position;
+attribute vec4 texcoord;
+attribute vec2 normal;
+uniform mat4 ModelMatrix;
+uniform mat4 ViewMatrix;
+uniform mat4 ProjectionMatrix;
+uniform mat4 IT_ModelMatrix;
+uniform vec4 U_AmbientMaterial;
+uniform vec4 U_AmbientLight;
+uniform vec4 U_LightPos;
+uniform vec4 U_DiffuseMaterial;
+uniform vec4 U_DiffuseLight;
+varying vec4 V_Color;
+void main(){
+ //ambient
+ vec4 ambientColor = U_AmbientMaterial*U_AmbientLight;
+
+ //diffuse
+ vec3 L = normalize(U_LightPos.xyz - vec3(0));
+ vec3 n = normalize(IT_ModelMatrix * normal.xyz);
+ float diffuseIntensity = max(0.0, dot(L,n));
+ vec4 diffuseColor = U_DiffuseMaterial * U_DiffuseLight * diffuseIntensity;
+
+ V_Color = ambientColor + diffuseColor;
+
+ gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * position;
+}
\ No newline at end of file
diff --git a/Res/diffuse_vs.fs b/Res/diffuse_vs.fs
new file mode 100644
index 0000000..2f90d25
--- /dev/null
+++ b/Res/diffuse_vs.fs
@@ -0,0 +1,8 @@
+#ifdef GL_ES
+precision mediump float;
+#endif
+varying vec4 V_Color;
+void main()
+{
+ gl_FragColor=V_Color;
+}
\ No newline at end of file
diff --git a/Res/diffuse_vs.vs b/Res/diffuse_vs.vs
new file mode 100644
index 0000000..7e4564b
--- /dev/null
+++ b/Res/diffuse_vs.vs
@@ -0,0 +1,30 @@
+#ifdef GL_ES
+precision mediump float;
+#endif;
+attribute vec4 position;
+attribute vec4 texcoord;
+attribute vec4 normal;
+uniform mat4 ModelMatrix;
+uniform mat4 ViewMatrix;
+uniform mat4 ProjectionMatrix;
+uniform mat4 IT_ModelMatrix;
+uniform vec4 U_AmbientMaterial;
+uniform vec4 U_AmbientLight;
+uniform vec4 U_LightPos;
+uniform vec4 U_DiffuseMaterial;
+uniform vec4 U_DiffuseLight;
+varying vec4 V_Color;
+void main(){
+ //ambient
+ vec4 ambientColor = U_AmbientMaterial*U_AmbientLight;
+
+ //diffuse
+ vec3 L = normalize(U_LightPos.xyz - vec3(0));
+ vec3 n = normalize((IT_ModelMatrix * normal).xyz);
+ float diffuseIntensity = max(0.0, dot(L,n));
+ vec4 diffuseColor = U_DiffuseMaterial * U_DiffuseLight * diffuseIntensity;
+
+ V_Color = ambientColor + diffuseColor;
+
+ gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * position;
+}
\ No newline at end of file
diff --git a/renderFramework.vcxproj b/renderFramework.vcxproj
index 556173e..6e7117f 100644
--- a/renderFramework.vcxproj
+++ b/renderFramework.vcxproj
@@ -149,11 +149,10 @@
-
-
+
+
-
diff --git a/renderFramework.vcxproj.filters b/renderFramework.vcxproj.filters
index 2cbce03..1219cc8 100644
--- a/renderFramework.vcxproj.filters
+++ b/renderFramework.vcxproj.filters
@@ -68,13 +68,10 @@
源文件
-
+
源文件
-
- 源文件
-
-
+
源文件
diff --git a/scene.cpp b/scene.cpp
index 41cf287..208f27b 100644
--- a/scene.cpp
+++ b/scene.cpp
@@ -13,10 +13,13 @@ FullScreenQuad *fsq;
void Init()
{
model.Init("Res/Sphere.obj");
- model.mShader->Init("Res/ambient_vs.vs", "Res/ambient_vs.fs");
+ model.mShader->Init("Res/diffuse_vs.vs", "Res/diffuse_vs.fs");
model.SetPosition(0.0f, 0.0f, 0.0f);
model.SetAmbientMaterial(0.1f, 0.1f, 0.1f, 1.0f);
model.mShader->SetVec4("U_AmbientLight", 0.1f, 0.1f, 0.1f, 1.0f);
+ model.SetDiffuseMaterial(0.4f, 0.4f, 0.4f, 1.0f);
+ model.mShader->SetVec4("U_DiffuseLight", 0.8f, 0.8f, 0.8f, 1.0f);
+ model.mShader->SetVec4("U_LightPos", 0.0f, 1.0f, 0.0f, 0.0f);
viewMatrix = glm::lookAt(cameraPos, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
fsq = new FullScreenQuad();
fsq->Init();
@@ -32,6 +35,8 @@ void SetViewPortSize(float width, float height)
fbo->Finish();
fbo->Bind();
+ glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
model.Draw(viewMatrix, projectionMatrix, cameraPos.x, cameraPos.y, cameraPos.z);
fbo->Unbind();
}