Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/shaders/glsl/model_common.vs
#version 120 | #version 120 | ||||
#extension GL_ARB_draw_instanced : enable | |||||
uniform mat4 transform; | uniform mat4 transform; | ||||
uniform vec3 cameraPos; | uniform vec3 cameraPos; | ||||
#ifdef GL_ES | #ifdef GL_ES | ||||
uniform mediump vec3 sunDir; | uniform mediump vec3 sunDir; | ||||
uniform mediump vec3 sunColor; | uniform mediump vec3 sunColor; | ||||
#else | #else | ||||
uniform vec3 sunDir; | uniform vec3 sunDir; | ||||
uniform vec3 sunColor; | uniform vec3 sunColor; | ||||
#endif | #endif | ||||
uniform vec2 losTransform; | uniform vec2 losTransform; | ||||
uniform mat4 shadowTransform; | uniform mat4 shadowTransform; | ||||
uniform mat4 instancingTransform; | uniform mat4 instancingTransform; | ||||
uniform mat4 instancingTransformReal[MAX_INSTANCES]; | |||||
#if USE_SHADOW_SAMPLER && USE_SHADOW_PCF | #if USE_SHADOW_SAMPLER && USE_SHADOW_PCF | ||||
uniform vec4 shadowScale; | uniform vec4 shadowScale; | ||||
#endif | #endif | ||||
#if USE_WIND | #if USE_WIND | ||||
uniform vec4 sim_time; | uniform vec4 sim_time; | ||||
uniform vec4 windData; | uniform vec4 windData; | ||||
Show All 36 Lines | |||||
#if USE_GPU_SKINNING | #if USE_GPU_SKINNING | ||||
const int MAX_INFLUENCES = 4; | const int MAX_INFLUENCES = 4; | ||||
const int MAX_BONES = 64; | const int MAX_BONES = 64; | ||||
uniform mat4 skinBlendMatrices[MAX_BONES]; | uniform mat4 skinBlendMatrices[MAX_BONES]; | ||||
attribute vec4 a_skinJoints; | attribute vec4 a_skinJoints; | ||||
attribute vec4 a_skinWeights; | attribute vec4 a_skinWeights; | ||||
#endif | #endif | ||||
vec4 fakeCos(vec4 x) | vec4 fakeCos(vec4 x) | ||||
{ | { | ||||
vladislavbelov: `0` means nothing here, should be called `a_instancing`, numbers are only for the dummy… | |||||
vec4 tri = abs(fract(x + 0.5) * 2.0 - 1.0); | vec4 tri = abs(fract(x + 0.5) * 2.0 - 1.0); | ||||
return tri * tri *(3.0 - 2.0 * tri); | return tri * tri *(3.0 - 2.0 * tri); | ||||
} | } | ||||
void main() | void main() | ||||
{ | { | ||||
#if USE_GPU_SKINNING | #if USE_GPU_SKINNING | ||||
vec3 p = vec3(0.0); | vec3 p = vec3(0.0); | ||||
vec3 n = vec3(0.0); | vec3 n = vec3(0.0); | ||||
for (int i = 0; i < MAX_INFLUENCES; ++i) { | for (int i = 0; i < MAX_INFLUENCES; ++i) { | ||||
int joint = int(a_skinJoints[i]); | int joint = int(a_skinJoints[i]); | ||||
if (joint != 0xff) { | if (joint != 0xff) { | ||||
mat4 m = skinBlendMatrices[joint]; | mat4 m = skinBlendMatrices[joint]; | ||||
p += vec3(m * vec4(a_vertex, 1.0)) * a_skinWeights[i]; | p += vec3(m * vec4(a_vertex, 1.0)) * a_skinWeights[i]; | ||||
n += vec3(m * vec4(a_normal, 0.0)) * a_skinWeights[i]; | n += vec3(m * vec4(a_normal, 0.0)) * a_skinWeights[i]; | ||||
} | } | ||||
} | } | ||||
vec4 position = instancingTransform * vec4(p, 1.0); | vec4 position = instancingTransformReal[gl_InstanceIDARB] * vec4(p, 1.0); | ||||
mat3 normalMatrix = mat3(instancingTransform[0].xyz, instancingTransform[1].xyz, instancingTransform[2].xyz); | mat3 normalMatrix = mat3(instancingTransformReal[gl_InstanceIDARB][0].xyz, instancingTransformReal[gl_InstanceIDARB][1].xyz, instancingTransformReal[gl_InstanceIDARB][2].xyz); | ||||
Done Inline ActionsCan you call this without USE_INSTANCING? Stan: Can you call this without USE_INSTANCING? | |||||
Done Inline Actionsno wraitii: no | |||||
Not Done Inline ActionsSorry didn't mean to be cryptic, I was wondering what happens if that define is undefined e.g #USE_INSTANCING = 0 would remove the attribute mat4 a_instancing; which might crash on some drivers no? Stan: Sorry didn't mean to be cryptic, I was wondering what happens if that define is undefined e.g… | |||||
Done Inline ActionsGPU_SKINNING implies USE_INSTANCING here. wraitii: GPU_SKINNING implies USE_INSTANCING here. | |||||
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 = instancingTransformReal[gl_InstanceIDARB] * vec4(a_vertex, 1.0); | ||||
mat3 normalMatrix = mat3(instancingTransform[0].xyz, instancingTransform[1].xyz, instancingTransform[2].xyz); | mat3 normalMatrix = mat3(instancingTransformReal[gl_InstanceIDARB][0].xyz, instancingTransformReal[gl_InstanceIDARB][1].xyz, instancingTransformReal[gl_InstanceIDARB][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 = instancingTransformReal[gl_InstanceIDARB][3]; | ||||
modelPos = fract(modelPos); | modelPos = fract(modelPos); | ||||
modelPos = clamp(modelPos, 0.4, 1.0); | modelPos = clamp(modelPos, 0.4, 1.0); | ||||
// crude measure of wind intensity | // crude measure of wind intensity | ||||
float abswind = abs(wind.x) + abs(wind.y); | float abswind = abs(wind.x) + abs(wind.y); | ||||
vec4 cosVec; | vec4 cosVec; | ||||
// these determine the speed of the wind's "cosine" waves. | // these determine the speed of the wind's "cosine" waves. | ||||
cosVec.w = 0.0; | cosVec.w = 0.0; | ||||
cosVec.x = sim_time.x * modelPos[0] + position.x; | cosVec.x = sim_time.x * modelPos[0] + position.x; | ||||
cosVec.y = sim_time.x * modelPos[2] / 3.0 + instancingTransform[3][0]; | cosVec.y = sim_time.x * modelPos[2] / 3.0 + instancingTransformReal[gl_InstanceIDARB][3][0]; | ||||
cosVec.z = sim_time.x * abswind / 4.0 + position.z; | cosVec.z = sim_time.x * abswind / 4.0 + position.z; | ||||
// calculate "cosines" in parallel, using a smoothed triangle wave | // calculate "cosines" in parallel, using a smoothed triangle wave | ||||
cosVec = fakeCos(cosVec); | cosVec = fakeCos(cosVec); | ||||
float limit = clamp((a_vertex.x * a_vertex.z * a_vertex.y) / 3000.0, 0.0, 0.2); | float limit = clamp((a_vertex.x * a_vertex.z * a_vertex.y) / 3000.0, 0.0, 0.2); | ||||
float diff = cosVec.x * limit; | float diff = cosVec.x * limit; | ||||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
0 means nothing here, should be called a_instancing, numbers are only for the dummy attributes.