1
0
Fork 0

Merge branch 'master' of gitorious.org:fg/fgdata

This commit is contained in:
Martin Spott 2010-11-03 21:49:53 +01:00
commit 1fa95adf25
3 changed files with 210 additions and 13 deletions

View file

@ -107,6 +107,7 @@ var active_walker = func {
var Walker = {
new : func (view_name, constraints = nil, managers = nil) {
var obj = { parents : [Walker] };
obj.view_name = view_name;
obj.view = view.views[view.indexof(view_name)];
obj.constraints = constraints;
obj.managers = managers;
@ -180,17 +181,26 @@ var Walker = {
var cur = props.globals.getNode("/sim/current-view");
me.heading = cur.getNode("heading-offset-deg").getValue();
me.position[0] -=
me.speed_fwd * dt * math.cos(me.heading * TO_RAD) +
me.speed_side * dt * math.sin(me.heading * TO_RAD);
me.position[1] -=
me.speed_fwd * dt * math.sin(me.heading * TO_RAD) -
me.speed_side * dt * math.cos(me.heading * TO_RAD);
var new_pos =
[me.position[0] -
me.speed_fwd * dt * math.cos(me.heading * TO_RAD) +
me.speed_side * dt * math.sin(me.heading * TO_RAD),
me.position[1] -
me.speed_fwd * dt * math.sin(me.heading * TO_RAD) -
me.speed_side * dt * math.cos(me.heading * TO_RAD),
me.position[2]];
var cur_height = me.position[2];
if (me.constraints != nil) {
me.position = me.constraints.constrain(me.position);
me.goal_height = me.position[2] + me.eye_height;
new_pos = me.constraints.constrain(new_pos);
if (new_pos == NO_POS) {
printlog("warn",
"WalkView: Constraint for " ~ me.view_name ~
" returned NO_POS.");
} else {
me.position = new_pos;
me.goal_height = me.position[2] + me.eye_height;
}
}
# Change the view height smoothly
if (math.abs(me.goal_height - cur_height) > 2.0 * dt) {
@ -399,6 +409,27 @@ var ActionConstraint = {
}
};
# Conditional constraint
# The area is only available when the predicate function returns true.
# constraint - the area in question : constraint
# predicate() - boolean function that determines if the area is available.
var ConditionalConstraint = {
new : func (constraint, predicate = nil) {
var obj = { parents : [ConditionalConstraint] };
obj.constraint = constraint;
obj.predicate = predicate;
return obj;
},
constrain : func (pos) {
if (me.predicate == nil or me.predicate()) {
return me.constraint.constrain(pos);
} else {
return NO_POS;
}
}
};
###############################################################################
# Manager classes.
@ -443,6 +474,8 @@ var JSBSimPointmass = {
var TO_RAD = math.pi/180;
var TO_DEG = 180/math.pi;
var NO_POS = [-9999.0, -9999.0, -9999.0];
var walkers = {};
var closerXY = func (pos, p1, p2) {

View file

@ -7,20 +7,19 @@
<depth-factor type="float">0.008</depth-factor>
<night-color type="vec3d">0.75 0.59 0.05</night-color>
<quality-level><use>/sim/rendering/quality-level</use></quality-level>
<max-lod-level>10</max-lod-level>
</parameters>
<generate>
<normal type="int">15</normal>
<tangent type="int">6</tangent>
<binormal type="int">7</binormal>
</generate>
<technique n="9">
<technique n="8">
<predicate>
<and>
<property>/sim/rendering/urban-shader</property>
<property>/sim/rendering/shader-effects</property>
<less-equal>
<value type="float">2.0</value>
<value type="float">4.0</value>
<float-property>/sim/rendering/quality-level</float-property>
</less-equal>
<or>
@ -157,4 +156,125 @@
</uniform>
</pass>
</technique>
<technique n="9">
<predicate>
<and>
<property>/sim/rendering/urban-shader</property>
<property>/sim/rendering/shader-effects</property>
<less-equal>
<value type="float">2.0</value>
<float-property>/sim/rendering/quality-level</float-property>
</less-equal>
<or>
<less-equal>
<value type="float">2.0</value>
<glversion/>
</less-equal>
<and>
<extension-supported>GL_ARB_shader_objects</extension-supported>
<extension-supported>GL_ARB_shading_language_100</extension-supported>
<extension-supported>GL_ARB_vertex_shader</extension-supported>
<extension-supported>GL_ARB_fragment_shader</extension-supported>
</and>
</or>
</and>
</predicate>
<pass>
<lighting>true</lighting>
<material>
<ambient><use>material/ambient</use></ambient>
<diffuse><use>material/diffuse</use></diffuse>
<specular><use>material/specular</use></specular>
<color-mode>ambient-and-diffuse</color-mode>
</material>
<blend><use>transparent</use></blend>
<alpha-test><use>transparent</use></alpha-test>
<shade-model>smooth</shade-model>
<cull-face>back</cull-face>
<render-bin>
<bin-number><use>render-bin/bin-number</use></bin-number>
<bin-name><use>render-bin/bin-name</use></bin-name>
</render-bin>
<texture-unit>
<unit>0</unit>
<image><use>texture[0]/image</use></image>
<filter><use>texture[0]/filter</use></filter>
<wrap-s><use>texture[0]/wrap-s</use></wrap-s>
<wrap-t><use>texture[0]/wrap-t</use></wrap-t>
<internal-format>
<use>texture[0]/internal-format</use>
</internal-format>
</texture-unit>
<texture-unit>
<unit>1</unit>
<image><use>texture[2]/image</use></image>
<filter><use>texture[2]/filter</use></filter>
<wrap-s><use>texture[2]/wrap-s</use></wrap-s>
<wrap-t><use>texture[2]/wrap-t</use></wrap-t>
<internal-format>
<use>texture[2]/internal-format</use>
</internal-format>
</texture-unit>
<texture-unit>
<unit>2</unit>
<type>noise</type>
</texture-unit>
<program>
<vertex-shader>Shaders/urban.vert</vertex-shader>
<fragment-shader>Shaders/urban.frag</fragment-shader>
<attribute>
<name>tangent</name>
<index>6</index>
</attribute>
<attribute>
<name>binormal</name>
<index>7</index>
</attribute>
<attribute>
<name>normal</name>
<index>15</index>
</attribute>
</program>
<uniform>
<name>BaseTex</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>NormalTex</name>
<type>sampler-2d</type>
<value type="int">1</value>
</uniform>
<uniform>
<name>NoiseTex</name>
<type>sampler-3d</type>
<value type="int">2</value>
</uniform>
<uniform>
<name>depth_factor</name>
<type>float</type>
<value><use>depth-factor</use></value>
</uniform>
<uniform>
<name>tile_size</name>
<type>float</type>
<value><use>xsize</use></value>
</uniform>
<uniform>
<name>night_color</name>
<type>float-vec3</type>
<value><use>night-color</use></value>
</uniform>
<uniform>
<name>quality_level</name>
<type>float</type>
<value><use>quality-level</use></value>
</uniform>
<uniform>
<name>snowlevel</name>
<type>float</type>
<value><use>snow-level</use></value>
</uniform>
</pass>
</technique>
</PropertyList>

View file

@ -2,7 +2,6 @@
// Licence: GPL v2
// Author: Frederic Bouvier.
// Adapted from the paper by F. Policarpo et al. : Real-time Relief Mapping on Arbitrary Polygonal Surfaces
// Adapted from the paper and sources by M. Drobot in GPU Pro : Quadtree Displacement Mapping with Height Blending
#version 120
@ -30,6 +29,7 @@ uniform float snowlevel; // From /sim/rendering/snow-level-m
uniform vec3 night_color;
const float scale = 1.0;
int linear_search_steps = 10;
int GlobalIterationCount = 0;
int gIterationCap = 64;
@ -111,7 +111,7 @@ void QDM(inout vec3 p, inout vec3 v)
p = p2;
}
float ray_intersect(vec2 dp, vec2 ds)
float ray_intersect_QDM(vec2 dp, vec2 ds)
{
vec3 p = vec3( dp, 0.0 );
vec3 v = vec3( ds, 1.0 );
@ -119,8 +119,52 @@ float ray_intersect(vec2 dp, vec2 ds)
return p.z;
}
float ray_intersect_relief(vec2 dp, vec2 ds)
{
float size = 1.0 / float(linear_search_steps);
float depth = 0.0;
float best_depth = 1.0;
for(int i = 0; i < linear_search_steps - 1; ++i)
{
depth += size;
float t = step(0.95, texture2D(NormalTex, dp + ds * depth).a);
if(best_depth > 0.996)
if(depth >= t)
best_depth = depth;
}
depth = best_depth;
const int binary_search_steps = 5;
for(int i = 0; i < binary_search_steps; ++i)
{
size *= 0.5;
float t = step(0.95, texture2D(NormalTex, dp + ds * depth).a);
if(depth >= t)
{
best_depth = depth;
depth -= 2.0 * size;
}
depth += size;
}
return(best_depth);
}
float ray_intersect(vec2 dp, vec2 ds)
{
if ( quality_level >= 4.0 )
return ray_intersect_QDM( dp, ds );
else
return ray_intersect_relief( dp, ds );
}
void main (void)
{
if ( quality_level >= 3.5 ) {
linear_search_steps = 20;
}
vec3 ecPos3 = ecPosition.xyz / ecPosition.w;
vec3 V = normalize(ecPos3);
vec3 s = vec3(dot(V, VTangent), dot(V, VBinormal), dot(VNormal, -V));