Browse Source

逐像素 慢反射

master
ubuntu20 4 years ago
parent
commit
430c399023
  1. 25
      Res/diffuse.fs
  2. 15
      Res/diffuse.vs
  3. 4
      renderFramework.vcxproj
  4. 4
      renderFramework.vcxproj.filters
  5. 2
      scene.cpp

25
Res/diffuse.fs

@ -0,0 +1,25 @@
#ifdef GL_ES
precision mediump float;
#endif
uniform vec4 U_AmbientMaterial;
uniform vec4 U_AmbientLight;
uniform vec4 U_LightPos;
uniform vec4 U_DiffuseMaterial;
uniform vec4 U_DiffuseLight;
varying vec4 V_Normal;
void main()
{
//ambient
vec4 ambirntColor = U_AmbientMaterial*U_AmbientLight;
//diffuse
vec3 L = normalize(U_LightPos.xyz - vec3(0));
vec3 n = normalize(V_Normal.xyz);
float diffuseIntensity = max(0.0, dot(L,n));
vec4 diffuseColor = U_DiffuseMaterial * U_DiffuseLight * diffuseIntensity;
gl_FragColor=ambirntColor + diffuseColor;
}

15
Res/diffuse.vs

@ -0,0 +1,15 @@
#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;
varying vec4 V_Normal;
void main(){
V_Normal = normal * IT_ModelMatrix;
gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * position;
}

4
renderFramework.vcxproj

@ -149,8 +149,8 @@
<ClInclude Include="vertexbuffer.h" />
</ItemGroup>
<ItemGroup>
<None Include="Res\ambient.fs" />
<None Include="Res\ambient.vs" />
<None Include="Res\diffuse.fs" />
<None Include="Res\diffuse.vs" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

4
renderFramework.vcxproj.filters

@ -62,10 +62,10 @@
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="Res\ambient.fs">
<None Include="Res\diffuse.fs">
<Filter>源文件</Filter>
</None>
<None Include="Res\ambient.vs">
<None Include="Res\diffuse.vs">
<Filter>源文件</Filter>
</None>
</ItemGroup>

2
scene.cpp

@ -13,7 +13,7 @@ FullScreenQuad *fsq;
void Init()
{
model.Init("Res/Sphere.obj");
model.mShader->Init("Res/ambient.vs", "Res/ambient.fs");
model.mShader->Init("Res/diffuse.vs", "Res/diffuse.fs");
model.SetPosition(0.0f, 0.0f, 0.0f);
//设置环境光参数

Loading…
Cancel
Save