blobt
5 years ago
7 changed files with 77 additions and 10 deletions
-
BIN.vs/shader2/v14/.suo
-
34main.cpp
-
BINres/image/niutou.bmp
-
25res/shader/diffuse.fs
-
20res/shader/diffuse.vs
-
4shader2.vcxproj
-
4shader2.vcxproj.filters
@ -0,0 +1,25 @@ |
|||
uniform sampler2D U_MainTexture; |
|||
varying vec3 V_Normal; |
|||
varying vec4 V_WorldPos;//µ±Ç°µÄλÖà |
|||
varying vec2 V_Texcoord; |
|||
|
|||
void main() { |
|||
|
|||
vec3 lightPos = vec3(0.0, 10.0, 0.0); |
|||
vec3 L=lightPos; |
|||
L = normalize(L); |
|||
vec3 n = normalize(V_Normal); |
|||
|
|||
|
|||
//ambient |
|||
vec4 AmbientLightColor = vec4(0.2, 0.2, 0.2, 1.0); |
|||
vec4 AmbientMaterial = vec4(0.2, 0.2, 0.2, 1.0); |
|||
vec4 AmbientColor = AmbientLightColor*AmbientMaterial; |
|||
|
|||
//diffuse |
|||
vec4 DiffuseLightColor = vec4(1.0,1.0,1.0,1.0); |
|||
vec4 DiffuseMaterial = vec4(0.8, 0.8, 0.8, 1.0); |
|||
vec4 diffuseColor = DiffuseLightColor*DiffuseMaterial*max(0.0, dot(L,n)); |
|||
|
|||
gl_FragColor = AmbientColor + texture2D(U_MainTexture, V_Texcoord) * diffuseColor; |
|||
} |
@ -0,0 +1,20 @@ |
|||
attribute vec3 pos; |
|||
attribute vec2 texcoord; |
|||
attribute vec3 normal; |
|||
attribute vec3 offset; |
|||
|
|||
uniform mat4 M; |
|||
uniform mat4 V; |
|||
uniform mat4 P; |
|||
uniform mat4 NM; |
|||
|
|||
varying vec3 V_Normal; |
|||
varying vec4 V_WorldPos;//µ±Ç°µÄλÖà |
|||
varying vec2 V_Texcoord; |
|||
|
|||
void main() { |
|||
V_Normal = mat3(NM)*normal; |
|||
V_WorldPos = M * vec4(pos, 1.0) + vec4(offset, 1.0f); |
|||
V_Texcoord = texcoord; |
|||
gl_Position = P*V*V_WorldPos; |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue