Working on fog, 2nd level, locations, dialogs
This commit is contained in:
1 parent
eac914e073
commit
c7b3f04cd4
38 files changed
+150471
-145
No files matched your search
@@ -0,0 +1,16 @@
|
||||
attribute vec3 vPosition;
|
||||
attribute vec2 vTexCoord;
|
||||
varying vec2 texCoord;
|
||||
varying float fogDistance;
|
||||
|
||||
uniform mat4 ProjectionModelViewMatrix;
|
||||
uniform mat4 ModelViewMatrix;
|
||||
uniform vec3 uPlayerEyePos;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 eyePos = ModelViewMatrix * vec4(vPosition.xyz, 1.0);
|
||||
fogDistance = length(eyePos.xyz - uPlayerEyePos);
|
||||
gl_Position = ProjectionModelViewMatrix * vec4(vPosition.xyz, 1.0);
|
||||
texCoord = vTexCoord;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
//precisionmediump float;
|
||||
uniform sampler2D Texture;
|
||||
varying vec2 texCoord;
|
||||
varying float fogDistance;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(Texture,texCoord).rgba;
|
||||
|
||||
if(color.a < 0.1)
|
||||
discard;
|
||||
|
||||
vec3 fogColor = vec3(0.53, 0.81, 0.92);
|
||||
float fogFactor = clamp((fogDistance - 30.0) / 10.0, 0.0, 1.0);
|
||||
vec3 finalColor = mix(color.rgb, fogColor, fogFactor);
|
||||
|
||||
gl_FragColor = vec4(finalColor, color.a);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
attribute vec3 vPosition;
|
||||
attribute vec2 vTexCoord;
|
||||
attribute vec3 vNormal;
|
||||
|
||||
varying vec2 texCoord;
|
||||
varying vec4 fragPosLightSpace;
|
||||
varying vec3 fragNormal;
|
||||
varying float fogDistance;
|
||||
|
||||
uniform mat4 ProjectionModelViewMatrix;
|
||||
uniform mat4 ModelViewMatrix;
|
||||
uniform mat4 uLightFromCamera;
|
||||
uniform vec3 uPlayerEyePos;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 eyePos = ModelViewMatrix * vec4(vPosition, 1.0);
|
||||
fogDistance = length(eyePos.xyz - uPlayerEyePos);
|
||||
gl_Position = ProjectionModelViewMatrix * vec4(vPosition, 1.0);
|
||||
texCoord = vTexCoord;
|
||||
fragPosLightSpace = uLightFromCamera * eyePos;
|
||||
fragNormal = mat3(ModelViewMatrix) * vNormal;
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
uniform sampler2D Texture;
|
||||
uniform sampler2D uShadowMap;
|
||||
uniform vec3 uLightDir;
|
||||
|
||||
varying vec2 texCoord;
|
||||
varying vec4 fragPosLightSpace;
|
||||
varying vec3 fragNormal;
|
||||
varying float fogDistance;
|
||||
|
||||
float computeShadow(vec4 lightSpacePos, vec3 normal)
|
||||
{
|
||||
vec3 projCoords = lightSpacePos.xyz / lightSpacePos.w;
|
||||
projCoords = projCoords * 0.5 + 0.5;
|
||||
|
||||
if (projCoords.x < 0.0 || projCoords.x > 1.0 ||
|
||||
projCoords.y < 0.0 || projCoords.y > 1.0 ||
|
||||
projCoords.z > 1.0)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
float currentDepth = projCoords.z;
|
||||
|
||||
// Slope-dependent bias: large for grazing angles, tiny for surfaces facing the light
|
||||
float bias = 0.0004;
|
||||
if (dot(normal, normal) > 0.001)
|
||||
{
|
||||
float cosTheta = dot(normalize(normal), -normalize(uLightDir));
|
||||
bias = max(0.002 * (1.0 - cosTheta), 0.0002);
|
||||
}
|
||||
|
||||
// 3x3 PCF (percentage-closer filtering) for softer shadows
|
||||
float shadow = 0.0;
|
||||
float texelSize = 1.0 / 2048.0;
|
||||
for (int x = -1; x <= 1; x++)
|
||||
{
|
||||
for (int y = -1; y <= 1; y++)
|
||||
{
|
||||
float pcfDepth = texture2D(uShadowMap, projCoords.xy + vec2(float(x), float(y)) * texelSize).r;
|
||||
shadow += currentDepth - bias > pcfDepth ? 1.0 : 0.0;
|
||||
}
|
||||
}
|
||||
shadow /= 9.0;
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(Texture, texCoord);
|
||||
|
||||
if (color.a < 0.1)
|
||||
discard;
|
||||
|
||||
float ambient = 0.4;
|
||||
float diffuseStrength = 0.6;
|
||||
|
||||
// Compute diffuse term; if normals are missing (zero-length) treat as fully lit
|
||||
float diffuse = 1.0;
|
||||
vec3 n = fragNormal;
|
||||
if (dot(n, n) > 0.001)
|
||||
{
|
||||
n = normalize(n);
|
||||
diffuse = max(dot(n, -normalize(uLightDir)), 0.0);
|
||||
}
|
||||
|
||||
float shadow = computeShadow(fragPosLightSpace, fragNormal);
|
||||
|
||||
// Shadow dims only the diffuse contribution; ambient is always present
|
||||
float lighting = ambient + diffuseStrength * diffuse * (1.0 - shadow);
|
||||
color.rgb *= lighting;
|
||||
|
||||
vec3 fogColor = vec3(0.53, 0.81, 0.92);
|
||||
float fogFactor = clamp((fogDistance - 30.0) / 10.0, 0.0, 1.0);
|
||||
color.rgb = mix(color.rgb, fogColor, fogFactor);
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D Texture;
|
||||
uniform sampler2D uShadowMap;
|
||||
uniform vec3 uLightDir;
|
||||
|
||||
varying vec2 texCoord;
|
||||
varying vec4 fragPosLightSpace;
|
||||
varying vec3 fragNormal;
|
||||
varying float fogDistance;
|
||||
|
||||
float computeShadow(vec4 lightSpacePos, vec3 normal)
|
||||
{
|
||||
vec3 projCoords = lightSpacePos.xyz / lightSpacePos.w;
|
||||
projCoords = projCoords * 0.5 + 0.5;
|
||||
|
||||
if (projCoords.x < 0.0 || projCoords.x > 1.0 ||
|
||||
projCoords.y < 0.0 || projCoords.y > 1.0 ||
|
||||
projCoords.z > 1.0)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
float currentDepth = projCoords.z;
|
||||
|
||||
float bias = 0.0004;
|
||||
if (dot(normal, normal) > 0.001)
|
||||
{
|
||||
float cosTheta = dot(normalize(normal), -normalize(uLightDir));
|
||||
bias = max(0.002 * (1.0 - cosTheta), 0.0002);
|
||||
}
|
||||
|
||||
float shadow = 0.0;
|
||||
float texelSize = 1.0 / 2048.0;
|
||||
for (int x = -1; x <= 1; x++)
|
||||
{
|
||||
for (int y = -1; y <= 1; y++)
|
||||
{
|
||||
float pcfDepth = texture2D(uShadowMap, projCoords.xy + vec2(float(x), float(y)) * texelSize).r;
|
||||
shadow += currentDepth - bias > pcfDepth ? 1.0 : 0.0;
|
||||
}
|
||||
}
|
||||
shadow /= 9.0;
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(Texture, texCoord);
|
||||
|
||||
if (color.a < 0.1)
|
||||
discard;
|
||||
|
||||
float ambient = 0.4;
|
||||
float diffuseStrength = 0.6;
|
||||
|
||||
float diffuse = 1.0;
|
||||
vec3 n = fragNormal;
|
||||
if (dot(n, n) > 0.001)
|
||||
{
|
||||
n = normalize(n);
|
||||
diffuse = max(dot(n, -normalize(uLightDir)), 0.0);
|
||||
}
|
||||
|
||||
float shadow = computeShadow(fragPosLightSpace, fragNormal);
|
||||
|
||||
float lighting = ambient + diffuseStrength * diffuse * (1.0 - shadow);
|
||||
color.rgb *= lighting;
|
||||
|
||||
vec3 fogColor = vec3(0.53, 0.81, 0.92);
|
||||
float fogFactor = clamp((fogDistance - 30.0) / 10.0, 0.0, 1.0);
|
||||
color.rgb = mix(color.rgb, fogColor, fogFactor);
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
attribute vec3 vPosition;
|
||||
attribute vec2 vTexCoord;
|
||||
attribute vec4 aBoneIndices0;
|
||||
attribute vec2 aBoneIndices1;
|
||||
attribute vec4 aBoneWeights0;
|
||||
attribute vec2 aBoneWeights1;
|
||||
|
||||
varying vec2 texCoord;
|
||||
varying float fogDistance;
|
||||
|
||||
uniform mat4 ProjectionModelViewMatrix;
|
||||
uniform mat4 ModelViewMatrix;
|
||||
uniform mat4 uBoneMatrices[64];
|
||||
uniform vec3 uPlayerEyePos;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 skinnedPos = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
vec4 originalPos = vec4(vPosition, 1.0);
|
||||
float totalWeight = 0.0;
|
||||
|
||||
if (aBoneWeights0.x > 0.0) {
|
||||
skinnedPos += uBoneMatrices[int(aBoneIndices0.x)] * originalPos * aBoneWeights0.x;
|
||||
totalWeight += aBoneWeights0.x;
|
||||
}
|
||||
if (aBoneWeights0.y > 0.0) {
|
||||
skinnedPos += uBoneMatrices[int(aBoneIndices0.y)] * originalPos * aBoneWeights0.y;
|
||||
totalWeight += aBoneWeights0.y;
|
||||
}
|
||||
if (aBoneWeights0.z > 0.0) {
|
||||
skinnedPos += uBoneMatrices[int(aBoneIndices0.z)] * originalPos * aBoneWeights0.z;
|
||||
totalWeight += aBoneWeights0.z;
|
||||
}
|
||||
if (aBoneWeights0.w > 0.0) {
|
||||
skinnedPos += uBoneMatrices[int(aBoneIndices0.w)] * originalPos * aBoneWeights0.w;
|
||||
totalWeight += aBoneWeights0.w;
|
||||
}
|
||||
if (aBoneWeights1.x > 0.0) {
|
||||
skinnedPos += uBoneMatrices[int(aBoneIndices1.x)] * originalPos * aBoneWeights1.x;
|
||||
totalWeight += aBoneWeights1.x;
|
||||
}
|
||||
if (aBoneWeights1.y > 0.0) {
|
||||
skinnedPos += uBoneMatrices[int(aBoneIndices1.y)] * originalPos * aBoneWeights1.y;
|
||||
totalWeight += aBoneWeights1.y;
|
||||
}
|
||||
|
||||
if (totalWeight < 0.001) {
|
||||
skinnedPos = originalPos;
|
||||
}
|
||||
|
||||
vec4 eyePos = ModelViewMatrix * skinnedPos;
|
||||
fogDistance = length(eyePos.xyz - uPlayerEyePos);
|
||||
gl_Position = ProjectionModelViewMatrix * skinnedPos;
|
||||
texCoord = vTexCoord;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
attribute vec3 vPosition;
|
||||
attribute vec2 vTexCoord;
|
||||
attribute vec3 vNormal;
|
||||
attribute vec4 aBoneIndices0;
|
||||
attribute vec2 aBoneIndices1;
|
||||
attribute vec4 aBoneWeights0;
|
||||
attribute vec2 aBoneWeights1;
|
||||
|
||||
varying vec2 texCoord;
|
||||
varying vec4 fragPosLightSpace;
|
||||
varying vec3 fragNormal;
|
||||
varying float fogDistance;
|
||||
|
||||
uniform mat4 ProjectionModelViewMatrix;
|
||||
uniform mat4 ModelViewMatrix;
|
||||
uniform mat4 uLightFromCamera;
|
||||
uniform mat4 uBoneMatrices[64];
|
||||
uniform vec3 uPlayerEyePos;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 skinnedPos = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
vec3 skinnedNormal = vec3(0.0, 0.0, 0.0);
|
||||
vec4 originalPos = vec4(vPosition, 1.0);
|
||||
float totalWeight = 0.0;
|
||||
|
||||
if (aBoneWeights0.x > 0.0) {
|
||||
skinnedPos += uBoneMatrices[int(aBoneIndices0.x)] * originalPos * aBoneWeights0.x;
|
||||
skinnedNormal += mat3(uBoneMatrices[int(aBoneIndices0.x)]) * vNormal * aBoneWeights0.x;
|
||||
totalWeight += aBoneWeights0.x;
|
||||
}
|
||||
if (aBoneWeights0.y > 0.0) {
|
||||
skinnedPos += uBoneMatrices[int(aBoneIndices0.y)] * originalPos * aBoneWeights0.y;
|
||||
skinnedNormal += mat3(uBoneMatrices[int(aBoneIndices0.y)]) * vNormal * aBoneWeights0.y;
|
||||
totalWeight += aBoneWeights0.y;
|
||||
}
|
||||
if (aBoneWeights0.z > 0.0) {
|
||||
skinnedPos += uBoneMatrices[int(aBoneIndices0.z)] * originalPos * aBoneWeights0.z;
|
||||
skinnedNormal += mat3(uBoneMatrices[int(aBoneIndices0.z)]) * vNormal * aBoneWeights0.z;
|
||||
totalWeight += aBoneWeights0.z;
|
||||
}
|
||||
if (aBoneWeights0.w > 0.0) {
|
||||
skinnedPos += uBoneMatrices[int(aBoneIndices0.w)] * originalPos * aBoneWeights0.w;
|
||||
skinnedNormal += mat3(uBoneMatrices[int(aBoneIndices0.w)]) * vNormal * aBoneWeights0.w;
|
||||
totalWeight += aBoneWeights0.w;
|
||||
}
|
||||
if (aBoneWeights1.x > 0.0) {
|
||||
skinnedPos += uBoneMatrices[int(aBoneIndices1.x)] * originalPos * aBoneWeights1.x;
|
||||
skinnedNormal += mat3(uBoneMatrices[int(aBoneIndices1.x)]) * vNormal * aBoneWeights1.x;
|
||||
totalWeight += aBoneWeights1.x;
|
||||
}
|
||||
if (aBoneWeights1.y > 0.0) {
|
||||
skinnedPos += uBoneMatrices[int(aBoneIndices1.y)] * originalPos * aBoneWeights1.y;
|
||||
skinnedNormal += mat3(uBoneMatrices[int(aBoneIndices1.y)]) * vNormal * aBoneWeights1.y;
|
||||
totalWeight += aBoneWeights1.y;
|
||||
}
|
||||
|
||||
if (totalWeight < 0.001) {
|
||||
skinnedPos = originalPos;
|
||||
skinnedNormal = vNormal;
|
||||
}
|
||||
|
||||
vec4 eyePos = ModelViewMatrix * skinnedPos;
|
||||
fogDistance = length(eyePos.xyz - uPlayerEyePos);
|
||||
gl_Position = ProjectionModelViewMatrix * skinnedPos;
|
||||
texCoord = vTexCoord;
|
||||
fragPosLightSpace = uLightFromCamera * eyePos;
|
||||
fragNormal = mat3(ModelViewMatrix) * skinnedNormal;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
precision mediump float;
|
||||
uniform sampler2D Texture;
|
||||
varying vec2 texCoord;
|
||||
varying float fogDistance;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(Texture,texCoord).rgba;
|
||||
|
||||
if(color.a < 0.1)
|
||||
discard;
|
||||
|
||||
vec3 fogColor = vec3(0.53, 0.81, 0.92);
|
||||
float fogFactor = clamp((fogDistance - 30.0) / 10.0, 0.0, 1.0);
|
||||
vec3 finalColor = mix(color.rgb, fogColor, fogFactor);
|
||||
|
||||
gl_FragColor = vec4(finalColor, color.a);
|
||||
}
|
||||
Reference in new issue
Block a user