Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/shaders/glsl/model_common.vs
Show All 16 Lines | |||||
#if USE_WIND | #if USE_WIND | ||||
uniform vec4 sim_time; | uniform vec4 sim_time; | ||||
uniform vec4 windData; | uniform vec4 windData; | ||||
#endif | #endif | ||||
varying vec4 v_lighting; | varying vec4 v_lighting; | ||||
varying vec2 v_tex; | varying vec2 v_tex; | ||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_AO | #if USE_AO | ||||
varying vec2 v_tex2; | varying vec2 v_tex2; | ||||
#endif | #endif | ||||
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX | |||||
varying vec4 v_normal; | varying vec4 v_normal; | ||||
varying vec3 v_eyeVec; | |||||
varying vec3 v_half; | |||||
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX | |||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && (USE_NORMAL_MAP || USE_PARALLAX) | #if (USE_INSTANCING || USE_GPU_SKINNING) && (USE_NORMAL_MAP || USE_PARALLAX) | ||||
varying vec4 v_tangent; | varying vec4 v_tangent; | ||||
//varying vec3 v_bitangent; | //varying vec3 v_bitangent; | ||||
#endif | #endif | ||||
#if USE_SPECULAR || USE_SPECULAR_MAP | |||||
varying vec3 v_half; | |||||
#endif | |||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_PARALLAX | |||||
varying vec3 v_eyeVec; | |||||
#endif | |||||
#endif | #endif | ||||
attribute vec3 a_vertex; | attribute vec3 a_vertex; | ||||
attribute vec3 a_normal; | attribute vec3 a_normal; | ||||
#if (USE_INSTANCING || USE_GPU_SKINNING) | #if (USE_INSTANCING || USE_GPU_SKINNING) | ||||
attribute vec4 a_tangent; | attribute vec4 a_tangent; | ||||
#endif | #endif | ||||
attribute vec2 a_uv0; | attribute vec2 a_uv0; | ||||
Show All 30 Lines | #if USE_GPU_SKINNING | ||||
} | } | ||||
vec4 position = instancingTransform * vec4(p, 1.0); | vec4 position = instancingTransform * vec4(p, 1.0); | ||||
mat3 normalMatrix = mat3(instancingTransform[0].xyz, instancingTransform[1].xyz, instancingTransform[2].xyz); | mat3 normalMatrix = mat3(instancingTransform[0].xyz, instancingTransform[1].xyz, instancingTransform[2].xyz); | ||||
vec3 normal = normalMatrix * normalize(n); | vec3 normal = normalMatrix * normalize(n); | ||||
#if (USE_NORMAL_MAP || USE_PARALLAX) | #if (USE_NORMAL_MAP || USE_PARALLAX) | ||||
vec3 tangent = normalMatrix * a_tangent.xyz; | vec3 tangent = normalMatrix * a_tangent.xyz; | ||||
#endif | #endif | ||||
#else | #else | ||||
#if (USE_INSTANCING) | #if (USE_INSTANCING) | ||||
vec4 position = instancingTransform * vec4(a_vertex, 1.0); | vec4 position = instancingTransform * vec4(a_vertex, 1.0); | ||||
mat3 normalMatrix = mat3(instancingTransform[0].xyz, instancingTransform[1].xyz, instancingTransform[2].xyz); | mat3 normalMatrix = mat3(instancingTransform[0].xyz, instancingTransform[1].xyz, instancingTransform[2].xyz); | ||||
vec3 normal = normalMatrix * a_normal; | vec3 normal = normalMatrix * a_normal; | ||||
#if (USE_NORMAL_MAP || USE_PARALLAX) | #if (USE_NORMAL_MAP || USE_PARALLAX) | ||||
vec3 tangent = normalMatrix * a_tangent.xyz; | vec3 tangent = normalMatrix * a_tangent.xyz; | ||||
#endif | #endif | ||||
#else | #else | ||||
vec4 position = vec4(a_vertex, 1.0); | vec4 position = vec4(a_vertex, 1.0); | ||||
vec3 normal = a_normal; | vec3 normal = a_normal; | ||||
#endif | #endif | ||||
#endif | #endif | ||||
#if USE_WIND | #if USE_WIND | ||||
vec2 wind = windData.xy; | vec2 wind = windData.xy; | ||||
// fractional part of model position, clamped to >.4 | // fractional part of model position, clamped to >.4 | ||||
vec4 modelPos = instancingTransform[3]; | vec4 modelPos = instancingTransform[3]; | ||||
Show All 23 Lines | #if USE_WIND | ||||
// swaying of trunk based on distance from ground (higher parts sway more) | // swaying of trunk based on distance from ground (higher parts sway more) | ||||
position.xz += diff + diff2 * wind; | position.xz += diff + diff2 * wind; | ||||
#endif | #endif | ||||
gl_Position = transform * position; | gl_Position = transform * position; | ||||
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX | vec3 eyeVec = cameraPos.xyz - position.xyz; | ||||
vec3 sunVec = -sunDir; | |||||
v_normal.xyz = normal; | v_normal.xyz = normal; | ||||
v_eyeVec = eyeVec; | |||||
v_half = normalize(normalize(sunVec) + normalize(eyeVec)); | |||||
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX | |||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && (USE_NORMAL_MAP || USE_PARALLAX) | #if (USE_INSTANCING || USE_GPU_SKINNING) && (USE_NORMAL_MAP || USE_PARALLAX) | ||||
v_tangent.xyz = tangent; | v_tangent.xyz = tangent; | ||||
vec3 bitangent = cross(v_normal.xyz, v_tangent.xyz) * a_tangent.w; | vec3 bitangent = cross(v_normal.xyz, v_tangent.xyz) * a_tangent.w; | ||||
v_normal.w = bitangent.x; | v_normal.w = bitangent.x; | ||||
v_tangent.w = bitangent.y; | v_tangent.w = bitangent.y; | ||||
v_lighting.w = bitangent.z; | v_lighting.w = bitangent.z; | ||||
#endif | #endif | ||||
#if USE_SPECULAR || USE_SPECULAR_MAP || USE_PARALLAX | |||||
vec3 eyeVec = cameraPos.xyz - position.xyz; | |||||
#if USE_SPECULAR || USE_SPECULAR_MAP | |||||
vec3 sunVec = -sunDir; | |||||
v_half = normalize(sunVec + normalize(eyeVec)); | |||||
#endif | |||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_PARALLAX | |||||
v_eyeVec = eyeVec; | |||||
#endif | |||||
#endif | |||||
#endif | #endif | ||||
v_lighting.xyz = max(0.0, dot(normal, -sunDir)) * sunColor; | v_lighting.xyz = max(0.0, dot(normal, -sunDir)) * sunColor; | ||||
v_tex = a_uv0; | v_tex = a_uv0; | ||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_AO | #if USE_AO | ||||
v_tex2 = a_uv1; | v_tex2 = a_uv1; | ||||
#endif | #endif | ||||
calculatePositionInShadowSpace(position); | calculatePositionInShadowSpace(position); | ||||
calculateLOSCoordinates(position.xz); | calculateLOSCoordinates(position.xz); | ||||
} | } |
Wildfire Games · Phabricator