Пример #1
0
kmVec3* kmVec3SmoothStep(kmVec3* pOut, const kmVec3* v1, const kmVec3* v2, const kmScalar t) {
    pOut->x = smoothstep(v1->x, v2->x, t);//v1->x + (v2->x - v1->x) * t;
    pOut->y = smoothstep(v1->y, v2->y, t);//v1->y + (v2->y - v1->y) * t;
    pOut->z = smoothstep(v1->z, v2->z, t);//v1->z + (v2->z - v1->z) * t;
    
    return pOut;    
}
Пример #2
0
void main(void) {                                                                       \
                                                                                        \
    vec4 basecolor = color;                                                             \
                                                                                        \
    if(dft == 0) {                                                                      \
        basecolor = vec4(color.r, color.g, color.b, texture(texture0, tcoord).a);       \
        if(effect == 1) {                                                               \
            basecolor += glowColor*texture(texture0, tcoord + shadowOffset);            \
        }                                                                               \
    } else {                                                                            \
        if(dft == 1) {                                                                  \
                                                                                        \
            float dist = texture(texture0, tcoord).a;                                   \
            basecolor = color*smoothstep(smooth_step_buffer - gamma, smooth_step_buffer + gamma, dist);         \
                                                                                        \
            if(effect == 1) {                                                           \
                float glowTexel 	=  texture(texture0, tcoord + shadowOffset).a;      \
                vec4 glowc				=  glowColor*smoothstep(0.3, 0.5, glowTexel);   \
                                                                                        \
                basecolor = glowc + basecolor;                                          \
                                                                                        \
            } else if(effect == 2) {                                                    \
                float glowTexel 	=  texture(texture0, tcoord).a;                     \
                vec4 glowc				=  glowColor*smoothstep(0.1, 0.2, glowTexel);   \
                                                                                        \
                basecolor = glowc + basecolor;                                          \
                                                                                        \
            } else {                                                                    \
                basecolor *= color*smoothstep(smooth_step_buffer - gamma, smooth_step_buffer + gamma, dist);    \
            }                                                                           \
        }                                                                               \
    }                                                                                   \
    ocolor = basecolor;                                                                 \
}                                                                                       \
Пример #3
0
        void Shake::updateProgress()
        {
            Animator::updateProgress();

            if (NodePtr targetNode = node.lock())
            {
                float x = length * progress * timeScale;

                uint64_t x1 = static_cast<uint32_t>(x);
                uint64_t x2 = x1 + 1;
                float t = x - static_cast<float>(x1);

                Vector2 previousPosition;
                Vector2 nextPosition;

                if (x1 != 0)
                {
                    previousPosition.x = (2.0f * (static_cast<float>(fnvHash(seedX | (x1 << 32))) / std::numeric_limits<uint64_t>::max()) - 1.0f) * distance.x;
                    previousPosition.y = (2.0f * (static_cast<float>(fnvHash(seedY | (x1 << 32))) / std::numeric_limits<uint64_t>::max()) - 1.0f) * distance.y;
                }

                if (x2 != static_cast<uint32_t>(timeScale))
                {
                    nextPosition.x = (2.0f * (static_cast<float>(fnvHash(seedX | (x2 << 32))) / std::numeric_limits<uint64_t>::max()) - 1.0f) * distance.x;
                    nextPosition.y = (2.0f * (static_cast<float>(fnvHash(seedY | (x2 << 32))) / std::numeric_limits<uint64_t>::max()) - 1.0f) * distance.y;
                }

                Vector2 noise(smoothstep(previousPosition.x, nextPosition.x, t),
                              smoothstep(previousPosition.y, nextPosition.y, t));

                targetNode->setPosition(startPosition + noise);
            }
        }
Пример #4
0
    float eval(Vec2f p) const
    {
        int xi = std::floor(p.x);
        int yi = std::floor(p.y);

        float tx = p.x - xi;
        float ty = p.y - yi;

        int rx0 = xi & kMaxTableSizeMask;
        int rx1 = (rx0 + 1) & kMaxTableSizeMask;
        int ry0 = yi & kMaxTableSizeMask;
        int ry1 = (ry0 + 1) & kMaxTableSizeMask;

        // random values at the corners of the cell using permutation table
        const float & c00 = r[permutationTable[permutationTable[rx0] + ry0]];
        const float & c10 = r[permutationTable[permutationTable[rx1] + ry0]];
        const float & c01 = r[permutationTable[permutationTable[rx0] + ry1]];
        const float & c11 = r[permutationTable[permutationTable[rx1] + ry1]];

        // remapping of tx and ty using the Smoothstep function 
        float sx = smoothstep(tx);
        float sy = smoothstep(ty);

        // linearly interpolate values along the x axis
        float nx0 = lerp(c00, c10, sx);
        float nx1 = lerp(c01, c11, sx);

        // linearly interpolate the nx0/nx1 along they y axis
        return lerp(nx0, nx1, sy);
    }
Пример #5
0
float3 smoothstep(const float edge0, const float edge1, float3 vec)
{
	vec.x = smoothstep(edge0, edge1, vec.x);
	vec.y = smoothstep(edge0, edge1, vec.y);
	vec.z = smoothstep(edge0, edge1, vec.z);
	return vec;
}
Пример #6
0
TScalar TWood::wood (const TScalar ktX,
                     const TScalar ktY,
                     const TScalar ktZ,
                     const TScalar ktRINGSCALE,
                     const TScalar ktGRAINFACTOR) const
{
  TVector  tQ;
  TScalar  tT;
  TScalar  tR;
  TScalar  tS;

  tT =  ktZ / ktRINGSCALE;
  tQ =  TVector (ktX * 8.0, ktY * 8.0, ktZ);
  tT += tNoise.noise (tQ) / 16.0;

  tQ =  TVector (ktX, tT, ktY + 12.93);
  tR =  ktRINGSCALE * tNoise.noise (tQ);
  tR -= tfloor (tR);
  tR =  0.2 + 0.8 * smoothstep (0.2, 0.55, tR) * (1.0 - smoothstep (0.75, 0.8, tR));
  
  tQ =  TVector (ktX * 128.0 + 5.0, ktZ * 8.0 - 3.0, ktY * 128.0 + 1);
  tS =  ktGRAINFACTOR * (1.3 - tNoise.noise (tQ)) + (1.0 - ktGRAINFACTOR);
  
  return tR * tS * tS;

}  /* wood */
Пример #7
0
vec3 clover( float x, float y )
{
    float a = atan(x,y);
    float r = sqrt(x*x+y*y);
    float s = 0.5 + 0.5*sin(3.0*a + time);
    float g = sin(1.57+3.0*a+time);
    float d = 0.3 + 0.6*sqrt(s) + 0.15*g*g;
    float h = r/d;
    float f = 1.0-smoothstep( 0.95, 1.0, h );
    h *= 1.0-0.5*(1.0-h)*smoothstep(0.95+0.05*h,1.0,sin(3.0*a+time));
    return mix( vec3(1.0), vec3(0.4*h,0.2+0.3*h,0.0), f );
}
Пример #8
0
void main() {
	float mountainMinHeight = sealevel + 5000.;
	float mountainMaxHeight = sealevel + 15000.0;
	if(vDisplacement > sealevel){
		float x = smoothstep(mountainMinHeight, mountainMaxHeight, vDisplacement);
		gl_FragColor =  mix(vec4(color, 1.0), TOP, x);
	} else if (vDisplacement > 1.){
		float x = smoothstep(-sealevel, sealevel, vDisplacement);
		gl_FragColor =  mix(BOTTOM, vec4(color*.75, 1.0), x);
	} else {
		gl_FragColor =  vec4(0,0,0,1);
	}
}
Пример #9
0
// Move the unit around a bit..
void CHoverAirMoveType::UpdateHovering()
{
	#if 0
	#define NOZERO(x) std::max(x, 0.0001f)

	float3 deltaVec = goalPos - owner->pos;
	float3 deltaDir = float3(deltaVec.x, 0.0f, deltaVec.z);

	const float driftSpeed = math::fabs(owner->unitDef->dlHoverFactor);
	const float goalDistance = NOZERO(deltaDir.Length2D());
	const float brakeDistance = 0.5f * owner->speed.SqLength2D() / decRate;

	// move towards goal position if it's not immediately
	// behind us when we have more waypoints to get to
	// *** this behavior interferes with the loading procedure of transports ***
	const bool b0 = (aircraftState != AIRCRAFT_LANDING && owner->commandAI->HasMoreMoveCommands());
	const bool b1 = (goalDistance < brakeDistance && goalDistance > 1.0f);

	if (b0 && b1 && dynamic_cast<CTransportUnit*>(owner) == NULL) {
		deltaDir = owner->frontdir;
	} else {
		deltaDir *= smoothstep(0.0f, 20.0f, goalDistance) / goalDistance;
		deltaDir -= owner->speed;
	}

	if (deltaDir.SqLength2D() > (maxSpeed * maxSpeed)) {
		deltaDir *= (maxSpeed / NOZERO(math::sqrt(deltaDir.SqLength2D())));
	}

	// random movement (a sort of fake wind effect)
	// random drift values are in range -0.5 ... 0.5
	randomWind.x = randomWind.x * 0.9f + (gs->randFloat() - 0.5f) * 0.5f;
	randomWind.z = randomWind.z * 0.9f + (gs->randFloat() - 0.5f) * 0.5f;

	wantedSpeed = owner->speed + deltaDir;
	wantedSpeed += (randomWind * driftSpeed * 0.5f);

	UpdateAirPhysics();
	#endif

	#if 1
	randomWind.x = randomWind.x * 0.9f + (gs->randFloat() - 0.5f) * 0.5f;
	randomWind.z = randomWind.z * 0.9f + (gs->randFloat() - 0.5f) * 0.5f;

	// randomly drift (but not too far from goal-position)
	wantedSpeed = (randomWind * math::fabs(owner->unitDef->dlHoverFactor) * 0.5f);
	wantedSpeed += (smoothstep(0.0f, 20.0f * 20.0f, (goalPos - owner->pos)) * (goalPos - owner->pos));

	UpdateAirPhysics();
	#endif
}
static scalar get_sun_intensity(
	const vector &ray_dir,
	const vector &sun_dir,
	scalar   haze,
	scalar   sun_disk_size,
	scalar   sun_disk_intensity,
	scalar   sun_glow_size,
	scalar   sun_glow_intensity,
	scalar   sun_glow_falloff)
{
	sun_disk_size *= 0.0465f;
	sun_glow_size *= 0.0465f;
	scalar sun_total_size = sun_disk_size + sun_glow_size;

	scalar intensity = 1.0f;
	scalar gamma = acosf(dot(ray_dir, sun_dir));
	if (gamma < sun_total_size)
	{
		scalar r = 1.0f - gamma / sun_total_size;
		intensity += sun_disk_intensity * smoothstep(0.0f, haze * 2.0f, r) + sun_glow_intensity * fastpow(r, sun_glow_falloff * haze);
		if (gamma < sun_disk_size)
		{
			intensity += sun_disk_intensity;
		}
	}
	return intensity;
}
Пример #11
0
float filteredpulsetrain (float edge,float period,float x,float dx)
{
	/* First, normalize so period == 1 and our domain of interest is > 0 */
    float w = dx/period;
    float x0 = x/period - w/2.0f;
    float x1 = x0+w;
    float nedge = edge / period;



	float result;
	if( x0 == x1 )
	{
		/* Trap the unfiltered case so it doesn't return 0 (when dx << x). */
		result = (x0 - floor(x0) < nedge) ? 0.0f : 1.0f;
	}
	else
	{
    	result = (integral(x1, nedge) - integral(x0, nedge)) / w;

		/*
			The above integral is subject to its own aliasing as we go beyond
			where the pattern should be extinct. We try to avoid that by
			switching to a constant value.
		*/
		float extinct = smoothstep( 0.4f, 0.5f, w );
		result = result + extinct * (1.0f - nedge - result);
	}

	return result;
}
Пример #12
0
Point3 SinWaveDeformer::Map(int i, Point3 p)
	{
	Point3 pt = p * tm;
	float r, oldZ, u, a, len;
		
	if (amp!=amp2) {
		len  = Length(pt);
		if (len==0.0f) {
			a = amp;
		} else {
			u = (float)acos(pt.x/len)/PI;
	 		u = (u > 0.5) ? (1.0f-u) : u;
			u *= 2.0f;
	 		//u = u*u;
	 		u = smoothstep(0.0f,1.0f,u);
	 		a = amp*(1.0f-u) + amp2*u;
			}
	} else {
		a = amp;
		}	
	
	oldZ = pt.z;
	pt.z = float(0);	
	r    = Length(pt);
	pt.z = oldZ + flex * WaveFunc(r, time, a, wave, phase, decay);
	return pt * itm;
	}
Пример #13
0
    void teleop_gui_t::render_limits(kinematics::Skeleton *robot,
                                     kinematics::BodyNode *link,
                                     const robot::robot_state_t& state,
                                     Eigen::Vector4d color_ok,
                                     Eigen::Vector4d color_limit)
    {
        glPushMatrix();
        // Color to render at
        Eigen::Vector4d color = color_ok;
        // What limit are we at?
        kinematics::Joint *joint = link->getParentJoint();
        int i = state.get_index(joint->getName());
        if(i != -1) {
            double dof = state.dofs(i);
            Eigen::Vector2d limits = state.get_limits(i);
            if(dof < limits[0] || limits[1] < dof) {
                std::vector<int> jind;
                jind.push_back(i);
                // state.print_limits(jind);
                // std::cout << "\tvalue" << dof << std::endl;
            }

            double middle = (limits[1]+limits[0])/2;

            double t = fabs(dof - middle)/(fabs(middle-limits[0]));

            color = smoothstep(color_ok, color_limit, t);
        }
        // Render shape w/ color
        kinematics::Shape *shape = link->getVisualizationShape();
        if(shape) {
            shape->draw(mRI, color, false);
        }
        glPopMatrix();
    }
Пример #14
0
void main(void)\
{\
vec3 d=normalize(o*vec3(1.,.6,1.));\
vec3 r=vec3(0.,0.,8.*p[0][1]-8.);\
float s=sin(p[0][3]*9.42);\
float c=cos(p[0][3]*9.42);\
r.xz=r.xz*mat2(c,-s,s,c);\
d.xz=d.xz*mat2(c,-s,s,c);\
s=sin(p[0][2]*9.42);\
c=cos(p[0][2]*9.42);\
r.yz=r.yz*mat2(c,-s,s,c);\
d.yz=d.yz*mat2(c,-s,s,c);\
vec3 l=vec3(0.,0.,0.);\
float m=0.;\
vec3 w=vec3(.016,.012,.009)*p[1][0];\
while(length(r)<15.&&m<0.95)\
{\
float i=min(length(r+vec3(0.,9.,0.))-8.2+20.*p[2][1],max(abs(r.y)-1.1-p[1][3]*20.,abs(length(r.xz)-2.+2.*p[1][2])*(.5+p[2][0])-2.*p[1][2]+1.2));\
vec3 n=r;\
n.y-=p[0][0]*.66;\
vec3 c=e(n*0.03,2)*.04*p[1][1];\
n.y=n.y*(.05+p[1][1])-.5*p[0][0];\
float v=e(c+n*.08,6).r;\
i-=.5*v;\
l+=w;\
m+=.003;\
float t=(1.-m)*clamp(1.-exp(i),0.,1.);\
float f=smoothstep(-2.5,-1.5,-length(r)+v*6.*(p[2][1]+1.));\
l+=(mix(vec3(.7,.2,.0),vec3(.1,.45,.85),f)*clamp(abs(f-.5),-0.5,1.)+clamp(r.y+v.x-2.*p[1][3]-1.,.0,100.))*t;\
m+=t;\
r+=d*max(.02,(i)*.5);\
}\
l+=(1.-m)*mix(vec3(.0,.1,.2),vec3(.0,.0,.1),normalize(r).y);\
gl_FragColor=vec4(l-.3,1.);\
}";
Пример #15
0
// Move the unit around a bit..
void CTAAirMoveType::UpdateHovering()
{
#define NOZERO(x) std::max(x, 0.0001f)

    const float driftSpeed = fabs(owner->unitDef->dlHoverFactor);
    float3 deltaVec = goalPos - owner->pos;
    float3 deltaDir = float3(deltaVec.x, 0, deltaVec.z);
    float l = NOZERO(deltaDir.Length2D());
    deltaDir *= smoothstep(0.0f, 20.0f, l) / l;

    // move towards goal position if it's not immediately
    // behind us when we have more waypoints to get to
    // *** this behavior interferes with the loading procedure of transports ***
    if (aircraftState != AIRCRAFT_LANDING && owner->commandAI->HasMoreMoveCommands() &&
            (l < 120) && (deltaDir.SqDistance(deltaVec) > 1.0f) && dynamic_cast<CTransportUnit*>(owner) == NULL) {
        deltaDir = owner->frontdir;
    }

    deltaDir -= owner->speed;
    l = deltaDir.SqLength2D();
    if (l > (maxSpeed * maxSpeed)) {
        deltaDir *= maxSpeed / NOZERO(sqrt(l));
    }
    wantedSpeed = owner->speed + deltaDir;

    // random movement (a sort of fake wind effect)
    // random drift values are in range -0.5 ... 0.5
    randomWind = float3(randomWind.x * 0.9f + (gs->randFloat() - 0.5f) * 0.5f, 0,
                        randomWind.z * 0.9f + (gs->randFloat() - 0.5f) * 0.5f);
    wantedSpeed += randomWind * driftSpeed * 0.5f;

    UpdateAirPhysics();
}
Пример #16
0
/* virtual */ void
CFlowInspectorDefault::DrawRecords(const std::deque<TFlowRecord>& inRecords, int inBaseRow, float inMaxAge) const
{
	// records are pushed back, but we want to draw new records on top
	// so we draw from bottom to top, ensuring linear mem access
	int row=inRecords.size() -1 + inBaseRow; 
	string val;
	ColorF color;

	std::deque<TFlowRecord>::const_iterator	iter (inRecords.begin());
	while (iter != inRecords.end())
	{
		const TFlowRecord& rec (*iter);
		float age = (m_currentTime - rec.m_tstamp).GetSeconds()-0.5f;  // -0.5 grace time
		float ageFactor = inMaxAge > 0 ? age / inMaxAge : 0;
		if (ageFactor < 0) ageFactor = 0;
		if (ageFactor > 1) ageFactor = 1;
		ageFactor = smoothstep(1.0f - ageFactor);
		color = DRAW_COLORS[rec.m_type];
		color.a *= ageFactor;
		DrawLabel(2.f,(float)row,color,0.0f, rec.m_message.c_str());
		--row;
		++iter;
	}
}
Пример #17
0
void lit_spot_spec(\n\
	float3 in_pos,\n\
	float3 in_nor,\n\
	float3 cam_vec,\n\
	float shin,\n\
	float3 l_pos,\n\
	float3 l_dir,\n\
	float inner_cone,\n\
	float outer_cone,\n\
	float3 l_diff,\n\
	float3 l_spec,\n\
	inout float3 out_diff,\n\
	inout float3 out_spec\n\
	)\n\
{\n\
	float diff_int, spec_int, angle, spot_eff;\n\
	float3 dir;\n\
	float3 half_vec;\n\
\n\
	diff_int = dot(in_nor, dir = -l_dir);\n\
	if(diff_int > 0.0)\n\
	{\n\
		angle = dot(normalize(in_pos - l_pos), l_dir);\n\
		spot_eff = smoothstep(outer_cone, inner_cone, angle);\n\
		out_diff += l_diff * diff_int * spot_eff;\n\
		half_vec = normalize(cam_vec + dir);\n\
		spec_int = dot(in_nor, half_vec);\n\
		out_spec += l_spec * pow(saturate(spec_int), shin);\n\
	}\n\
}\n\
Пример #18
0
void lit_spot_range(\n\
	float3 in_pos,\n\
	float3 in_nor,\n\
	float3 l_pos,\n\
	float3 l_dir,\n\
	float inner_cone,\n\
	float outer_cone,\n\
	float3 l_diff,\n\
	float2 l_range,\n\
	inout float3 out_diff\n\
	)\n\
{\n\
	float diff_int, angle, spot_eff;\n\
	float3 dir;\n\
\n\
	diff_int = dot(in_nor, dir = -l_dir);\n\
	if(diff_int > 0.0)\n\
	{\n\
		angle = dot(normalize(in_pos - l_pos), l_dir);\n\
		if(angle > outer_cone)\n\
		{\n\
			float att = 1 - saturate(distance(in_pos, l_pos) * l_range[0]);\n\
\n\
			spot_eff = smoothstep(outer_cone, inner_cone, angle);\n\
			out_diff += l_diff * diff_int * spot_eff * att;\n\
		}\n\
	}\n\
}\n\
vec3 times(float n)
{
    float k = fract(time*n) * 3.0;
    vec3 t = vec3(clamp(k, 0.0, 1.0),
                clamp(k-1.0, 0.0, 1.0),
                clamp(k-2.0, 0.0, 1.0));
    return floor(time*n) + smoothstep(0.0, 1.0, t);
}
Пример #20
0
static gboolean
stretch_map (GstGeometricTransform * gt, gint x, gint y, gdouble * in_x,
    gdouble * in_y)
{
  GstCircleGeometricTransform *cgt = GST_CIRCLE_GEOMETRIC_TRANSFORM_CAST (gt);
  GstStretch *stretch = GST_STRETCH_CAST (gt);

  gdouble norm_x, norm_y;
  gdouble r;

  gdouble width = gt->width;
  gdouble height = gt->height;
  gdouble a, b;

  /* normalize in ((-1.0, -1.0), (1.0, 1.0) and traslate the center */
  norm_x = 2.0 * (x / width - cgt->x_center);
  norm_y = 2.0 * (y / height - cgt->y_center);

  /* calculate radius, normalize to 1 for future convenience */
  r = sqrt (0.5 * (norm_x * norm_x + norm_y * norm_y));

  /* actually "stretch" name is a bit misleading, what the transform
   * really does is shrink the center and gradually return to normal
   * size while r increases. The shrink thing drags pixels giving
   * stretching the image around the center */

  /* a is the current maximum shrink amount, it goes from 1.0 to
   * MAX_SHRINK_AMOUNT * intensity */
  /* smoothstep goes from 0.0 when r == 0 to b when r == radius */
  /* total shrink factor is MAX_SHRINK_AMOUNT at center and gradually
   * decreases while r goes to radius */
  a = 1.0 + (MAX_SHRINK_AMOUNT - 1.0) * stretch->intensity;
  b = a - 1.0;

  norm_x *= a - b * smoothstep (0.0, cgt->radius, r);
  norm_y *= a - b * smoothstep (0.0, cgt->radius, r);

  /* unnormalize */
  *in_x = (0.5 * norm_x + cgt->x_center) * width;
  *in_y = (0.5 * norm_y + cgt->y_center) * height;

  GST_DEBUG_OBJECT (stretch, "Inversely mapped %d %d into %lf %lf",
      x, y, *in_x, *in_y);

  return TRUE;
}
Пример #21
0
	void main(void)
	{
		vec4 rgb = texture2D(texture, fragmentTextureCoordinate.xy);
		vec3 hsl = RgbToHsl(rgb.rgb);

		rgb *= smoothstep(threshold*sharpness, threshold*(2-sharpness), hsl.z);

		gl_FragColor = rgb;
	}
Пример #22
0
	// http://www.geeks3d.com/20091020/shader-library-lens-circle-post-processing-effect-glsl/
	void main(void)
	{
		vec4 col = texture2D(texture, fragmentTextureCoordinate.xy);
		float dist = distance(fragmentTextureCoordinate.xy, vec2(0.5,0.5));
		vec4 mixed = mix(edgeColor, col, smoothstep(outerRadius, innerRadius, dist) );
		col = mix(col, mixed, edgeColor.a);
		// col.rgb *= smoothstep(outerRadius, innerRadius, dist);
		gl_FragColor = col;
	}
Пример #23
0
string TiltShiftFilter::_getFragSrc() {
    return GLSL_STRING(120,
        uniform sampler2D inputImageTexture;
        uniform sampler2D inputImageTexture2;

        uniform float topFocusLevel;
        uniform float bottomFocusLevel;
        uniform float focusFallOffRate;

        void main() {
            vec2 uv = gl_TexCoord[0].xy;
            vec4 sharpImageColor = texture2D(inputImageTexture, uv);
            vec4 blurredImageColor = texture2D(inputImageTexture2, uv);
            
            float blurIntensity = 1.0 - smoothstep(topFocusLevel - focusFallOffRate, topFocusLevel, uv.y);
            blurIntensity += smoothstep(bottomFocusLevel, bottomFocusLevel + focusFallOffRate, uv.y);
            
            gl_FragColor = mix(sharpImageColor, blurredImageColor, blurIntensity);
        }
Пример #24
0
void CGrassDrawer::CreateGrassDispList(int listNum)
{
	CVertexArray* va = GetVertexArray();
	va->Initialize();
	grng.Seed(15);

	for (int a = 0; a < strawPerTurf; ++a) {
		// draw a single blade
		const float lngRnd = grng.NextFloat();
		const float length = mapInfo->grass.bladeHeight * (1.0f + lngRnd);
		const float maxAng = mapInfo->grass.bladeAngle * std::max(grng.NextFloat(), 1.0f - smoothstep(0.0f, 1.0f, lngRnd));

		float3 sideVect;
		sideVect.x = grng.NextFloat() - 0.5f;
		sideVect.z = grng.NextFloat() - 0.5f;
		sideVect.ANormalize();
		float3 bendVect = sideVect.cross(UpVector); // direction to bend into
		sideVect *= mapInfo->grass.bladeWidth * (-0.15f * lngRnd + 1.0f);

		const float3 basePos = grng.NextVector2D() * (turfSize - (bendVect * std::sin(maxAng) * length).Length2D());

		// select one of the 16 color shadings
		const float xtexCoord = grng.NextInt(16) / 16.0f;
		const int numSections = 2 + int(maxAng * 1.2f + length * 0.2f);

		float3 normalBend = -bendVect;

		// start btm
		va->AddVertexTN(basePos + sideVect - float3(0.0f, 3.0f, 0.0f), xtexCoord              , 0.f, normalBend);
		va->AddVertexTN(basePos - sideVect - float3(0.0f, 3.0f, 0.0f), xtexCoord + (1.0f / 16), 0.f, normalBend);

		for (float h = 0.0f; h < 1.0f; h += (1.0f / numSections)) {
			const float ang = maxAng * h;
			const float3 n = (normalBend * std::cos(ang) + UpVector * std::sin(ang)).ANormalize();
			const float3 edgePos  = (UpVector * std::cos(ang) + bendVect * std::sin(ang)) * length * h;
			const float3 edgePosL = edgePos - sideVect * (1.0f - h);
			const float3 edgePosR = edgePos + sideVect * (1.0f - h);

			va->AddVertexTN(basePos + edgePosR, xtexCoord + (1.0f / 32) * h              , h, (n + sideVect * 0.04f).ANormalize());
			va->AddVertexTN(basePos + edgePosL, xtexCoord - (1.0f / 32) * h + (1.0f / 16), h, (n - sideVect * 0.04f).ANormalize());
		}

		// end top tip (single triangle)
		const float3 edgePos = (UpVector * std::cos(maxAng) + bendVect * std::sin(maxAng)) * length;
		const float3 n = (normalBend * std::cos(maxAng) + UpVector * std::sin(maxAng)).ANormalize();
		va->AddVertexTN(basePos + edgePos, xtexCoord + (1.0f / 32), 1.0f, n);

		// next blade
		va->EndStrip();
	}

	glNewList(listNum, GL_COMPILE);
	va->DrawArrayTN(GL_TRIANGLE_STRIP);
	glEndList();
}
Пример #25
0
float SpotLight::isInDualConeSpot(Vec4 pit)
{
    if(angle_inner_light == 0) return isInConeSpot(pit);
    Vec4 p(position_light->x(),position_light->y(),position_light->z());
    Vec4 d(direction_light->x(),direction_light->y(),direction_light->z());
    Vec4 v = (pit-p).unitary();
    float cosOuter = cos((float)angle_light*M_PI/180.0);
    float cosInner = cos((float)angle_inner_light*M_PI/180.0);
    float cosDirection = v*d;
    return smoothstep(cosOuter,cosInner,cosDirection);
}
Пример #26
0
float Player::interpolate(float original, float target, double clock)
{
    float current;
    if (clock < 1.0)
    {
        double v;
        v = smoothstep(clock);
        current = (target * v) + (original * (1.0 - v));
    }
    else
    {
        current = target;
    }
    return current;
}
Пример #27
0
b2Vec2 Player::interpolate(b2Vec2 original, b2Vec2 target, double clock)
{
    b2Vec2 current;
    if (clock < 1.0)
    {
        double v;
        v = smoothstep(clock);
        current.x = (target.x * v) + (original.x * (1.0 - v));
        current.y = (target.y * v) + (original.y * (1.0 - v));
    }
    else
    {
        current = target;
    }
    return current;
}
Пример #28
0
void CGrassDrawer::CreateGrassBladeTex(unsigned char* buf)
{
	float3 redish = float3(0.95f, 0.70f, 0.4f);
	float3 col = mix(mapInfo->grass.color, redish, 0.1f * rng.RandFloat());
	col.x = Clamp(col.x, 0.f, 1.f);
	col.y = Clamp(col.y, 0.f, 1.f);
	col.z = Clamp(col.z, 0.f, 1.f);

	SColor* img = reinterpret_cast<SColor*>(buf);
	for (int y=0; y<64; ++y) {
		for (int x=0; x<16; ++x) {
			const float brightness = smoothstep(-0.8f, 0.5f, y/63.0f) + ((x%2) == 0 ? 0.035f : 0.0f);
			const float3 c = col * brightness;
			img[y*256+x] = SColor(c.r, c.g, c.b, 1.0f);
		}
	}
}
Пример #29
0
float Splat::splatter(Point3 p) {
	float fact, ss, q[3], t;

	q[0] = p[0]/size;
	q[1] = p[1]/size;
	q[2] = p[2]/size;
	fact = 1.0f;
	for (int i = 0; i < iter; i++) {
		t = NOISE(q);
		if (t > 1.0) 
			t = 1.0f;
		ss = smoothstep(thresh-EPSILON, thresh+EPSILON, t);
		fact *= ss;
		q[0] *= 2.0f;	q[1] *= 2.0f;	q[2] *= 2.0f;
	}
	return(1.0f-fact);
}
Пример #30
0
void CWind::Update()
{
    if (status == 0) {
        oldWind = curWind;
        newWind = oldWind;

        //! generate new wind direction
        float len;
        do {
            newWind.x -= (gs->randFloat() - 0.5f) * maxWind;
            newWind.z -= (gs->randFloat() - 0.5f) * maxWind;
            len = newWind.Length();
        } while (len == 0.f);

        //! clamp: windMin <= strength <= windMax
        newWind /= len;
        len = Clamp(len, minWind, maxWind);
        newWind *= len;

        status++;
    } else if (status <= UpdateRate) {
        float mod = status / float(UpdateRate);
        mod = smoothstep(0.f, 1.f, mod);

        //! blend between old & new wind directions
#define blend(x,y,a) x * (1.0f - a) + y * a
        curWind = blend(oldWind, newWind, mod);
        curStrength = curWind.Length();
        if (curStrength != 0.f) {
            curDir = curWind / curStrength;
        }

        status++;
    } else {
        status = 0;
    }

    if (status == UpdateRate / 3) {
        //! update units
        const float newStrength = newWind.Length();
        for (std::map<int, CUnit*>::iterator it = windGens.begin(); it != windGens.end(); ++it) {
            (it->second)->UpdateWind(newWind.x, newWind.z, newStrength);
        }
    }
}