light working
This commit is contained in:
1 parent
d2a081588f
commit
7fc9a5e5d6
9 files changed
+356
-111
No files matched your search
@@ -0,0 +1,46 @@
|
||||
uniform sampler2D Texture;
|
||||
uniform float FogBeginDistance;
|
||||
uniform float FogEndDistance;
|
||||
|
||||
varying vec2 texCoord;
|
||||
varying vec3 vertexPos;
|
||||
varying vec3 normal;
|
||||
varying vec3 absoluteVertexPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
//vec3 norm = normalize(normal)*0.5 + vec3(0.5, 0.5, 0.5);
|
||||
//gl_FragColor = vec4(norm, 1.0);
|
||||
|
||||
vec3 norm = normalize(normal);
|
||||
|
||||
vec3 lightPos = vec3(-2, 5, 0);
|
||||
|
||||
vec3 lightVec = absoluteVertexPos - lightPos;
|
||||
|
||||
float coef = max(dot(-normalize(lightVec),norm),0.2);
|
||||
|
||||
float coef2 = clamp((15.0 - length(lightVec))/10.0, 0.2, 1.0);
|
||||
|
||||
vec4 texColor = texture2D(Texture,texCoord).rgba;
|
||||
|
||||
gl_FragColor = vec4(texColor.rgb*coef2*coef, 1.0);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
//Night
|
||||
//vec4 fogColor = vec4(0.25, 0.55, 1.0, 1.0);
|
||||
vec4 fogColor = vec4(0.05, 0.05, 0.1, 1.0);
|
||||
|
||||
|
||||
|
||||
float fogDistCoef = (vertexPos.z - FogBeginDistance) / (FogEndDistance - FogBeginDistance);
|
||||
|
||||
fogDistCoef = clamp(fogDistCoef, 0.0, 1.0);
|
||||
|
||||
vec4 resultColor = mix(texColor*coef2, fogColor, fogDistCoef);
|
||||
|
||||
gl_FragColor = vec4(resultColor.rgb, 1.0);*/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
attribute vec3 vPosition;
|
||||
attribute vec2 vTexCoord;
|
||||
attribute vec3 vNormal;
|
||||
|
||||
uniform mat4 ProjectionMatrix;
|
||||
uniform mat3 ModelRotateMatrix;
|
||||
uniform vec3 ModelTranslateVector;
|
||||
|
||||
varying vec2 texCoord;
|
||||
varying vec3 vertexPos;
|
||||
varying vec3 absoluteVertexPos;
|
||||
varying vec3 normal;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 realVertexPos = vec4(ModelRotateMatrix * vPosition.xyz + ModelTranslateVector, 1.0);
|
||||
gl_Position = ProjectionMatrix * realVertexPos;
|
||||
vertexPos = gl_Position.xyz;
|
||||
|
||||
absoluteVertexPos = vPosition;
|
||||
|
||||
texCoord = vTexCoord.st;
|
||||
|
||||
normal = vNormal;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
uniform sampler2D Texture;
|
||||
uniform sampler2D NormalMap;
|
||||
uniform float FogBeginDistance;
|
||||
uniform float FogEndDistance;
|
||||
|
||||
varying vec2 texCoord;
|
||||
varying vec3 vertexPos;
|
||||
varying vec3 normal;
|
||||
varying vec3 absoluteVertexPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
//vec3 norm = normalize(normal)*0.5 + vec3(0.5, 0.5, 0.5);
|
||||
//gl_FragColor = vec4(norm, 1.0);
|
||||
|
||||
vec3 norm = normalize(normal);
|
||||
|
||||
vec3 lightPos = vec3(-2, 5, 0);
|
||||
|
||||
vec3 lightVec = absoluteVertexPos - lightPos;
|
||||
|
||||
float coef = max(dot(-normalize(lightVec),norm),0.2);
|
||||
|
||||
float coef2 = clamp((15.0 - length(lightVec))/10.0, 0.2, 1.0);
|
||||
|
||||
vec4 texColor = texture2D(NormalMap,texCoord).rgba;
|
||||
|
||||
gl_FragColor = vec4(texColor.rgb*coef2*coef, 1.0);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
//Night
|
||||
//vec4 fogColor = vec4(0.25, 0.55, 1.0, 1.0);
|
||||
vec4 fogColor = vec4(0.05, 0.05, 0.1, 1.0);
|
||||
|
||||
|
||||
|
||||
float fogDistCoef = (vertexPos.z - FogBeginDistance) / (FogEndDistance - FogBeginDistance);
|
||||
|
||||
fogDistCoef = clamp(fogDistCoef, 0.0, 1.0);
|
||||
|
||||
vec4 resultColor = mix(texColor*coef2, fogColor, fogDistCoef);
|
||||
|
||||
gl_FragColor = vec4(resultColor.rgb, 1.0);*/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
attribute vec3 vPosition;
|
||||
attribute vec2 vTexCoord;
|
||||
attribute vec3 vNormal;
|
||||
|
||||
uniform mat4 ProjectionMatrix;
|
||||
uniform mat3 ModelRotateMatrix;
|
||||
uniform vec3 ModelTranslateVector;
|
||||
|
||||
varying vec2 texCoord;
|
||||
varying vec3 vertexPos;
|
||||
varying vec3 absoluteVertexPos;
|
||||
varying vec3 normal;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 realVertexPos = vec4(ModelRotateMatrix * vPosition.xyz + ModelTranslateVector, 1.0);
|
||||
gl_Position = ProjectionMatrix * realVertexPos;
|
||||
vertexPos = gl_Position.xyz;
|
||||
|
||||
absoluteVertexPos = vPosition;
|
||||
|
||||
texCoord = vTexCoord.st;
|
||||
|
||||
normal = vNormal;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
uniform samplerCube Env;
|
||||
|
||||
varying vec3 dir;
|
||||
|
||||
void main(){
|
||||
gl_FragColor = textureCube(Env, normalize(dir));
|
||||
|
||||
vec4 fogColor = vec4(0.05, 0.05, 0.1, 1.0);
|
||||
|
||||
float coef = dir.y+1.0;
|
||||
coef = clamp(coef, 0.0, 1.0);
|
||||
|
||||
gl_FragColor = mix(gl_FragColor,fogColor, coef);
|
||||
|
||||
//if (dir.z < 0)
|
||||
//{
|
||||
// gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
//}
|
||||
//gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
attribute vec3 vPosition;
|
||||
|
||||
uniform mat4 ProjectionMatrix;
|
||||
uniform mat3 ModelRotateMatrix;
|
||||
uniform vec3 ModelTranslateVector;
|
||||
|
||||
varying vec3 dir;
|
||||
|
||||
void main(){
|
||||
vec4 realVertexPos = vec4(ModelRotateMatrix * vPosition.xyz + ModelTranslateVector, 1.0);
|
||||
gl_Position = ProjectionMatrix * realVertexPos;
|
||||
|
||||
dir = -vPosition;
|
||||
}
|
||||
Reference in new issue
Block a user