1
0
forked from 0ad/0ad

Remove conditional defines as those served a very doubtful purpose with parallax, replacing it with something dynamic in the shader. This cleans the C++ side of the renderer as conditional defines were very ugly.

This was SVN commit r16430.
This commit is contained in:
wraitii 2015-03-15 12:22:36 +00:00
parent 5a4ddb52a2
commit f29d059617
16 changed files with 56 additions and 150 deletions

View File

@ -6,12 +6,7 @@
<alternative material="basic_trans_ao_spec.xml" quality="8"/>
<alternative material="alphatest_ao_parallax_spec.xml" if="CFG_FORCE_ALPHATEST"/>
<conditional_define name="USE_PARALLAX_MAP" value="1" type="draw_range" conf="PARALLAX_DIST"/>
<conditional_define name="USE_HQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_HQ_DIST"/>
<conditional_define name="USE_VHQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_VHQ_DIST"/>
<!-- <define name="USE_SELF_LIGHT" value="1"/> -->
<define name="USE_PARALLAX" value="1"/>
<!-- Settings for effects above:
First value: Normal mapping intensity.

View File

@ -6,13 +6,7 @@
<alternative material="basic_trans_spec.xml" quality="8"/>
<alternative material="alphatest_ao_parallax_spec.xml" if="CFG_FORCE_ALPHATEST"/>
<conditional_define name="USE_PARALLAX_MAP" value="1" type="draw_range" conf="PARALLAX_DIST"/>
<conditional_define name="USE_HQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_HQ_DIST"/>
<conditional_define name="USE_VHQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_VHQ_DIST"/>
<!-- <define name="USE_SELF_LIGHT" value="1"/> -->
<!--<define name="USE_AO" value="1"/>-->
<define name="USE_PARALLAX" value="1"/>
<!-- Settings for effects above:
First value: Normal mapping intensity.

View File

@ -20,13 +20,6 @@ element material {
attribute name { text },
attribute value { text }
}* &
element conditional_define {
attribute name { text },
attribute value { text },
attribute type { text },
(attribute conf { text }
| ( attribute min { xsd:float }?, attribute max { xsd:float }? ))
}* &
element uniform {
attribute name { text },
attribute value { list { # X Y Z W

View File

@ -3,12 +3,7 @@
<shader effect="model"/>
<alternative material="no_trans_ao.xml" quality="8"/>
<conditional_define name="USE_PARALLAX_MAP" value="1" type="draw_range" conf="PARALLAX_DIST"/>
<conditional_define name="USE_HQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_HQ_DIST"/>
<conditional_define name="USE_VHQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_VHQ_DIST"/>
<!-- <define name="USE_SELF_LIGHT" value="1"/> -->
<define name="USE_PARALLAX" value="1"/>
<!-- Settings for effects above:
First value: Normal mapping intensity.

View File

@ -4,9 +4,7 @@
<alternative material="player_trans_ao.xml" quality="8"/>
<define name="USE_PLAYERCOLOR" value="1"/>
<conditional_define name="USE_PARALLAX_MAP" value="1" type="draw_range" conf="PARALLAX_DIST"/>
<conditional_define name="USE_HQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_HQ_DIST"/>
<conditional_define name="USE_VHQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_VHQ_DIST"/>
<define name="USE_PARALLAX" value="1"/>
<uniform name="effectSettings" value="1.0 50.0 0.0075 0.6"/>

View File

@ -4,12 +4,7 @@
<alternative material="player_trans_ao_spec.xml" quality="8"/>
<define name="USE_PLAYERCOLOR" value="1"/>
<conditional_define name="USE_PARALLAX_MAP" value="1" type="draw_range" conf="PARALLAX_DIST"/>
<conditional_define name="USE_HQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_HQ_DIST"/>
<conditional_define name="USE_VHQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_VHQ_DIST"/>
<!-- <define name="USE_SELF_LIGHT" value="1"/> -->
<define name="USE_PARALLAX" value="1"/>
<!-- Settings for effects above:
First value: Normal mapping intensity.

View File

@ -4,13 +4,6 @@
<alternative material="player_trans_ao.xml" quality="3"/>
<define name="USE_PLAYERCOLOR" value="1"/>
<!--<conditional_define name="USE_PARALLAX_MAP" value="1" type="draw_range" conf="PARALLAX_DIST"/>
<conditional_define name="USE_HQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_HQ_DIST"/>
<conditional_define name="USE_VHQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_VHQ_DIST"/>-->
<!-- <define name="USE_SELF_LIGHT" value="1"/> -->
<!-- Settings for effects above:
First value: Normal mapping intensity.
Second value: Specular power.

View File

@ -4,9 +4,7 @@
<alternative material="player_trans.xml" quality="8"/>
<define name="USE_PLAYERCOLOR" value="1"/>
<conditional_define name="USE_PARALLAX_MAP" value="1" type="draw_range" conf="PARALLAX_DIST"/>
<conditional_define name="USE_HQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_HQ_DIST"/>
<conditional_define name="USE_VHQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_VHQ_DIST"/>
<define name="USE_PARALLAX" value="1"/>
<!--<define name="USE_SPECULAR_MAP" value="1"/>
<define name="USE_SELF_LIGHT" value="1"/>-->

View File

@ -4,9 +4,7 @@
<alternative material="player_trans_spec.xml" quality="8"/>
<define name="USE_PLAYERCOLOR" value="1"/>
<conditional_define name="USE_PARALLAX_MAP" value="1" type="draw_range" conf="PARALLAX_DIST"/>
<conditional_define name="USE_HQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_HQ_DIST"/>
<conditional_define name="USE_VHQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_VHQ_DIST"/>
<define name="USE_PARALLAX" value="1"/>
<!-- <define name="USE_SELF_LIGHT" value="1"/> -->

View File

@ -10,9 +10,7 @@
COMMENT: Pixels that are exactly white are calculated more efficiently (on average)
if dynamic branching is supported by the player's GPU.
EFFICIENCY: This is a moderately expensive effect, so use with care. -->
<conditional_define name="USE_PARALLAX_MAP" value="1" type="draw_range" conf="PARALLAX_DIST"/>
<conditional_define name="USE_HQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_HQ_DIST"/>
<conditional_define name="USE_VHQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_VHQ_DIST"/>
<define name="USE_PARALLAX" value="1"/>
<!-- REQUIRES: Actor must provide a texture named "normTex", where the RGB channels
are a normal map corresponding to XYZ normals.

View File

@ -10,8 +10,7 @@
COMMENT: Pixels that are exactly white are calculated more efficiently (on average)
if dynamic branching is supported by the player's GPU.
EFFICIENCY: This is a moderately expensive effect, so use with care. -->
<conditional_define name="USE_PARALLAX_MAP" value="1" type="draw_range" conf="PARALLAX_DIST"/>
<conditional_define name="USE_HQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_HQ_DIST"/>
<define name="USE_PARALLAX" value="1"/>
<!-- REQUIRES: Actor must provide a texture named "normTex", where the RGB channels
are a normal map corresponding to XYZ normals.

View File

@ -3,9 +3,7 @@
<shader effect="model_transparent"/>
<alpha_blending/>
<define name="USE_TRANSPARENT" value="1"/>
<conditional_define name="USE_PARALLAX_MAP" value="1" type="draw_range" conf="PARALLAX_DIST"/>
<conditional_define name="USE_HQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_HQ_DIST"/>
<conditional_define name="USE_VHQ_PARALLAX" value="1" type="draw_range" conf="PARALLAX_VHQ_DIST"/>
<define name="USE_PARALLAX" value="1"/>
<uniform name="effectSettings" value="1.0 50.0 0.0075 0.85"/>
<renderquery name="sim_time"/>

View File

@ -47,20 +47,20 @@ varying vec2 v_los;
uniform vec3 specularColor;
#endif
#if USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX_MAP || USE_AO
#if USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX || USE_AO
uniform vec4 effectSettings;
#endif
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX_MAP
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX
varying vec4 v_normal;
#if (USE_INSTANCING || USE_GPU_SKINNING) && (USE_NORMAL_MAP || USE_PARALLAX_MAP)
#if (USE_INSTANCING || USE_GPU_SKINNING) && (USE_NORMAL_MAP || USE_PARALLAX)
varying vec4 v_tangent;
//varying vec3 v_bitangent;
#endif
#if USE_SPECULAR || USE_SPECULAR_MAP
varying vec3 v_half;
#endif
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_PARALLAX_MAP
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_PARALLAX
varying vec3 v_eyeVec;
#endif
#endif
@ -113,84 +113,45 @@ void main()
{
vec2 coord = v_tex;
#if (USE_INSTANCING || USE_GPU_SKINNING) && (USE_PARALLAX_MAP || USE_NORMAL_MAP)
#if (USE_INSTANCING || USE_GPU_SKINNING) && (USE_PARALLAX || USE_NORMAL_MAP)
vec3 bitangent = vec3(v_normal.w, v_tangent.w, v_lighting.w);
mat3 tbn = mat3(v_tangent.xyz, bitangent, v_normal.xyz);
#endif
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_PARALLAX_MAP
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_PARALLAX
{
float h = texture2D(normTex, coord).a;
vec3 eyeDir = normalize(v_eyeVec * tbn);
float dist = length(v_eyeVec);
float s;
vec2 move;
float height = 1.0;
float scale = effectSettings.z;
scale = (scale * (float(PARALLAX_DIST_MAX) - dist)) / float(PARALLAX_DIST_MAX);
int iter = int(min(30, 70.0/dist));
if (iter > 0.01)
{
float s = 1.0/iter;
float t = s;
move = vec2(-eyeDir.x, eyeDir.y) * scale / (eyeDir.z * iter);
vec2 nil = vec2(0.0);
float iter = 8.0;
#if USE_HQ_PARALLAX
iter = 16.0;
#if USE_VHQ_PARALLAX
iter = 24.0;
#endif
#endif
s = 1.0 / iter;
float t = s;
move = vec2(-eyeDir.x, eyeDir.y) * scale / (eyeDir.z * iter);
vec2 nil = vec2(0.0);
#define PARALLAX_ITER {\
height -= t;\
t = (h < height) ? s : 0.0;\
vec2 temp = (h < height) ? move : nil;\
coord += temp;\
h = texture2D(normTex, coord).a;\
}
// 8 iterations of parallax
PARALLAX_ITER
PARALLAX_ITER
PARALLAX_ITER
PARALLAX_ITER
PARALLAX_ITER
PARALLAX_ITER
PARALLAX_ITER
PARALLAX_ITER
// an additional 8 iterations for the HQ parallax
#if USE_HQ_PARALLAX
PARALLAX_ITER
PARALLAX_ITER
PARALLAX_ITER
PARALLAX_ITER
PARALLAX_ITER
PARALLAX_ITER
PARALLAX_ITER
PARALLAX_ITER
#if USE_VHQ_PARALLAX
PARALLAX_ITER
PARALLAX_ITER
PARALLAX_ITER
PARALLAX_ITER
PARALLAX_ITER
PARALLAX_ITER
PARALLAX_ITER
PARALLAX_ITER
#endif
#endif
// Move back to where we collided with the surface.
// This assumes the surface is linear between the sample point before we
// intersect the surface and after we intersect the surface
float hp = texture2D(normTex, coord - move).a;
coord -= move * ((h - height) / (s + h - hp));
for (int i = 0; i < iter; ++i) {
height -= t;
t = (h < height) ? s : 0.0;
vec2 temp = (h < height) ? move : nil;
coord += temp;
h = texture2D(normTex, coord).a;
}
// Move back to where we collided with the surface.
// This assumes the surface is linear between the sample point before we
// intersect the surface and after we intersect the surface
float hp = texture2D(normTex, coord - move).a;
coord -= move * ((h - height) / (s + h - hp));
}
}
#endif

View File

@ -34,16 +34,16 @@ varying vec2 v_los;
varying vec2 v_tex2;
#endif
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX_MAP
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX
varying vec4 v_normal;
#if (USE_INSTANCING || USE_GPU_SKINNING) && (USE_NORMAL_MAP || USE_PARALLAX_MAP)
#if (USE_INSTANCING || USE_GPU_SKINNING) && (USE_NORMAL_MAP || USE_PARALLAX)
varying vec4 v_tangent;
//varying vec3 v_bitangent;
#endif
#if USE_SPECULAR || USE_SPECULAR_MAP
varying vec3 v_half;
#endif
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_PARALLAX_MAP
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_PARALLAX
varying vec3 v_eyeVec;
#endif
#endif
@ -88,7 +88,7 @@ void main()
vec4 position = instancingTransform * vec4(p, 1.0);
mat3 normalMatrix = mat3(instancingTransform[0].xyz, instancingTransform[1].xyz, instancingTransform[2].xyz);
vec3 normal = normalMatrix * normalize(n);
#if (USE_NORMAL_MAP || USE_PARALLAX_MAP)
#if (USE_NORMAL_MAP || USE_PARALLAX)
vec3 tangent = normalMatrix * a_tangent.xyz;
#endif
#else
@ -96,7 +96,7 @@ void main()
vec4 position = instancingTransform * vec4(a_vertex, 1.0);
mat3 normalMatrix = mat3(instancingTransform[0].xyz, instancingTransform[1].xyz, instancingTransform[2].xyz);
vec3 normal = normalMatrix * a_normal;
#if (USE_NORMAL_MAP || USE_PARALLAX_MAP)
#if (USE_NORMAL_MAP || USE_PARALLAX)
vec3 tangent = normalMatrix * a_tangent.xyz;
#endif
#else
@ -142,10 +142,10 @@ void main()
gl_Position = transform * position;
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX_MAP
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX
v_normal.xyz = normal;
#if (USE_INSTANCING || USE_GPU_SKINNING) && (USE_NORMAL_MAP || USE_PARALLAX_MAP)
#if (USE_INSTANCING || USE_GPU_SKINNING) && (USE_NORMAL_MAP || USE_PARALLAX)
v_tangent.xyz = tangent;
vec3 bitangent = cross(v_normal.xyz, v_tangent.xyz) * a_tangent.w;
v_normal.w = bitangent.x;
@ -153,13 +153,13 @@ void main()
v_lighting.w = bitangent.z;
#endif
#if USE_SPECULAR || USE_SPECULAR_MAP || USE_PARALLAX_MAP
#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_MAP
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_PARALLAX
v_eyeVec = eyeVec;
#endif
#endif

View File

@ -48,23 +48,20 @@ varying vec2 v_blend;
uniform vec3 specularColor;
#endif
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX_MAP || USE_AO
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_AO
uniform vec4 effectSettings;
#endif
varying vec3 v_normal;
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX_MAP
#if USE_NORMAL_MAP || USE_PARALLAX_MAP
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP
#if USE_NORMAL_MAP
varying vec4 v_tangent;
varying vec3 v_bitangent;
#endif
#if USE_SPECULAR || USE_SPECULAR_MAP
varying vec3 v_half;
#endif
#if USE_PARALLAX_MAP
varying vec3 v_eyeVec;
#endif
#endif
float get_shadow()

View File

@ -34,17 +34,14 @@ varying vec2 v_blend;
varying vec3 v_normal;
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX_MAP
#if USE_NORMAL_MAP || USE_PARALLAX_MAP
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP
#if USE_NORMAL_MAP
varying vec4 v_tangent;
varying vec3 v_bitangent;
#endif
#if USE_SPECULAR || USE_SPECULAR_MAP
varying vec3 v_half;
#endif
#if USE_PARALLAX_MAP
varying vec3 v_eyeVec;
#endif
#endif
@ -102,23 +99,20 @@ void main()
v_normal = a_normal;
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX_MAP || USE_TRIPLANAR
#if USE_NORMAL_MAP || USE_PARALLAX_MAP
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_TRIPLANAR
#if USE_NORMAL_MAP
vec3 t = vec3(1.0, 0.0, 0.0);
t = normalize(t - v_normal * dot(v_normal, t));
v_tangent = vec4(t, -1.0);
v_bitangent = cross(v_normal, t);
#endif
#if USE_SPECULAR || USE_SPECULAR_MAP || USE_PARALLAX_MAP
#if USE_SPECULAR || USE_SPECULAR_MAP
vec3 eyeVec = cameraPos.xyz - position.xyz;
#if USE_SPECULAR || USE_SPECULAR_MAP
vec3 sunVec = -sunDir;
v_half = normalize(sunVec + normalize(eyeVec));
#endif
#if USE_PARALLAX_MAP
v_eyeVec = eyeVec;
#endif
#endif
#endif