Beispiel #1
0
	void shader_prog(const vs_input& in, vs_output& out)
	{
		vec4 pos = in.attribute(0);
		vec4 nor = in.attribute(1);

		out.position() = out.attribute(0) = vec4(0.0f, 0.0f, 0.0f, 0.0f);
		pos.w(1.0f);
		nor.w(0.0f);

		for(int i = 0; i < 4; ++i)
		{
			union {float f; int i;} f2i;
			f2i.f = in.attribute(3)[i];
			float w = in.attribute(4)[i];
			int boneIndex = f2i.i;
			if(boneIndex == -1){break;}
			vec4 skin_pos;
			vec4 skin_nor;
			transform(skin_pos, invMatrices[boneIndex], pos);
			transform(skin_pos, boneMatrices[boneIndex], skin_pos);
			transform(skin_nor, invMatrices[boneIndex], nor);
			transform(skin_nor, boneMatrices[boneIndex], skin_nor);
			out.position() += (skin_pos*w);
			out.attribute(0) += (skin_nor*w);
		}
		
		transform(out.position(), out.position(), wvp);

		// out.attribute(0) = in.attribute(1);
		out.attribute(1) = in.attribute(2);
		out.attribute(2) = light_pos - pos;
		out.attribute(3) = eye_pos - pos;
	}
Beispiel #2
0
	bool shader_prog(const vs_output& in, ps_output& out)
	{
        float occlusion = 0.0f;
        if(dsamp_)
        {
            vec3 lis_pos( in.attribute(4).xyz() / in.attribute(4).w() );
            vec2 sm_center( (lis_pos.x() + 1.0f)*0.5f, (1.0f-(lis_pos.y()+1.0f)*0.5f) );

			float sm_offset = 1 / 512.0f;
			vec2 sm_coords[] = 
			{
				sm_center + vec2(-sm_offset, -sm_offset),
				sm_center + vec2(      0.0f, -sm_offset),
				sm_center + vec2(+sm_offset, -sm_offset),
				sm_center + vec2(-sm_offset,       0.0f),
				sm_center + vec2(      0.0f,       0.0f),
				sm_center + vec2(+sm_offset,       0.0f),
				sm_center + vec2(-sm_offset, +sm_offset),
				sm_center + vec2(      0.0f, +sm_offset),
				sm_center + vec2(+sm_offset, +sm_offset)
			};

            float shadow_depth[9];
			for(int i = 0; i < 9; ++i)
			{
				vec4 sm_coord_lod(sm_coords[i].x(), sm_coords[i].y(), 0.0f, 0.0f);
				shadow_depth[i] = tex2dlod(*dsamp_, sm_coord_lod).r;
			}

			float occluder = 0.0f;
			for(int i = 1; i < 9; ++i)
			{
				occluder += gaussian_weights[i] * exp(esm_constant * (shadow_depth[i] - shadow_depth[0]));
			}
			occluder += gaussian_weights[0];
			occluder = log(occluder);
			occluder += esm_constant * shadow_depth[0];

			occlusion = eflib::clamp(exp(occluder - esm_constant * lis_pos[2]), 0.0f, 1.0f);
        }

        color_rgba32f tex_color(1.0f, 1.0f, 1.0f, 1.0f);
        if(texsamp_)
        {
            tex_color = tex2d(*texsamp_ , 0);
        }

		vec3 norm( normalize3( in.attribute(1).xyz() ) );
		vec3 light_dir( normalize3( in.attribute(2).xyz() ) );
		vec3 eye_dir( normalize3( in.attribute(3).xyz() ) );
		
		float illum_diffuse = clamp( dot_prod3( light_dir, norm ), 0.0f, 1.0f );
		float illum_specular = clamp( dot_prod3(-reflect3(light_dir, norm), eye_dir), 0.0f, 1.0f );
		vec4 illum = ambient + ( diffuse * illum_diffuse + specular * pow(illum_specular, shininess) ) * occlusion;

        out.color[0] = tex_color.get_vec4() * illum;
		out.color[0][3] = 1.0f;

		return true;
	}
Beispiel #3
0
	void shader_prog(const vs_input& in, vs_output& out)
	{
		vec4 pos = in.attribute(0);
		transform(out.position(), pos, wvp);
		out.attribute(0) = in.attribute(1);
		out.attribute(1) = in.attribute(2);
		out.attribute(2) = light_pos - pos;
		out.attribute(3) = eye_pos - pos;
	}
Beispiel #4
0
	void shader_prog(const vs_input& in, vs_output& out)
	{
		vec4 pos = in.attribute(0);
		vec4 pos_es, normal_es;
		transform(pos_es, pos, wv);
		transform33(normal_es, in.attribute(1), wv);
		transform(out.position(), pos_es, proj);
		out.attribute(0) = vec4(light_pos - pos_es.xyz(), 1);
		out.attribute(1) = vec4(eye_pos - pos_es.xyz(), 1);
		out.attribute(2) = normal_es;
	}
Beispiel #5
0
	bool shader_prog(const vs_output& in, ps_output& out)
	{
		vec3 l = normalize3(in.attribute(0).xyz());
		vec3 e = normalize3(in.attribute(1).xyz());
		vec3 n = normalize3(in.attribute(2).xyz());
		float n_dot_l = dot_prod3(n, l);
		float roughness = 5;
		float spec = (roughness + 2) / 2 * pow(max(dot_prod3(normalize3(l + e), n), 0.0f), roughness);
		float clr = n_dot_l * (0.8f + spec * 0.4f);
		out.color[0] = vec4(clr, clr, clr, 1);
		return true;
	}
 void shader_prog(const vs_input& in, vs_output& out)
 {
     vec4 pos = in.attribute(0);
     transform(out.position(), pos, wvp);
     out.attribute(0) = in.attribute(0);//(vec4(1.0f, 1.0f, 1.0f, 1.0f) - in[0]);
     out.attribute(1) = in.attribute(1);
 }
Beispiel #7
0
	bool shader_prog(const vs_output& in, ps_output& out)
	{
		vec4 diff_color = vec4(1.0f, 1.0f, 1.0f, 1.0f); // diffuse;

		vec3 norm( normalize3( in.attribute(0).xyz() ) );
		vec3 light_dir( normalize3( in.attribute(1).xyz() ) );
		vec3 eye_dir( normalize3( in.attribute(2).xyz() ) );

		float illum_diffuse = clamp( dot_prod3( light_dir, norm ), 0.0f, 1.0f );
		float illum_specular = clamp( dot_prod3( reflect3( light_dir, norm ), eye_dir ), 0.0f, 1.0f );

		out.color[0] = ambient * 0.01f + diff_color * illum_diffuse + specular * illum_specular;
		out.color[0] = diff_color * illum_diffuse;
		// out.color[0] = ( vec4(norm, 1.0f) + vec4(1.0f, 1.0f, 1.0f, 1.0f) ) * 0.5f;

		out.color[0][3] = 1.0f;

		return true;
	}
Beispiel #8
0
	bool shader_prog(const vs_output& in, ps_output& out)
	{
		color_rgba32f tex_color(1.0f, 1.0f, 1.0f, 1.0f);
		if( sampler_ )
		{
			tex_color = tex2d(*sampler_ , 0);
		}
		vec3 norm( normalize3( in.attribute(1).xyz() ) );
		vec3 light_dir( normalize3( in.attribute(2).xyz() ) );
		vec3 eye_dir( normalize3( in.attribute(3).xyz() ) );

		float illum_diffuse = clamp( dot_prod3( light_dir, norm ), 0.0f, 1.0f );
		float illum_specular = clamp( dot_prod3( reflect3( light_dir, norm ), eye_dir ), 0.0f, 1.0f );
		vec4 illum = ambient + diffuse * illum_diffuse + specular * illum_specular;

		out.color[0] = tex_color.get_vec4() * illum;
		out.color[0][3] = 1.0f;

		return true;
	}
Beispiel #9
0
	bool shader_prog(const vs_output& in, ps_output& out)
	{
		vec4 ambi_color(0.22f, 0.20f, 0.09f, 1.0f);
		vec4 diff_color(0.75f, 0.75f, 0.25f, 1.0f);
		vec4 spec_color(2.0f, 1.7f, 0.0f, 1.0f);

		vec3 norm( normalize3( in.attribute(0).xyz() ) );
		vec3 light_dir( normalize3( in.attribute(1).xyz() ) );
		vec3 eye_dir( normalize3( in.attribute(2).xyz() ) );

		float illum_diffuse = clamp( dot_prod3( light_dir, norm ), 0.0f, 1.0f );
		float illum_specular = clamp( dot_prod3( reflect3( light_dir, norm ), eye_dir ), 0.0f, 1.0f );
		float powered_illum_spec = illum_specular*illum_specular;
		powered_illum_spec *= powered_illum_spec;
		powered_illum_spec *= powered_illum_spec;
		out.color[0] = ambi_color * 0.01f + diff_color * illum_diffuse + spec_color * powered_illum_spec;
		// out.color[0] = ( vec4(norm, 1.0f) + vec4(1.0f, 1.0f, 1.0f, 1.0f) ) * 0.5f;
		out.color[0][3] = 1.0f;

		return true;
	}
Beispiel #10
0
    bool shader_prog(const vs_output& in, ps_output& out)
    {
        ++count;
        vec4 diff_color = vec4(1.0f, 1.0f, 1.0f, 1.0f); // diffuse;

        if( sampler_ )
        {
            diff_color = tex2d(*sampler_, 0).get_vec4();
        }

        vec3 norm( normalize3( in.attribute(1).xyz() ) );
        vec3 light_dir( normalize3( in.attribute(2).xyz() ) );
        vec3 eye_dir( normalize3( in.attribute(3).xyz() ) );

        float illum_diffuse = clamp( dot_prod3( light_dir, norm ), 0.0f, 1.0f );

        out.color[0] = diff_color * illum_diffuse;
        out.color[0][3] = 1.0f;

        return true;
    }
Beispiel #11
0
	bool shader_prog(const vs_output& in, ps_output& out)
	{
		float height = in.attribute(0)[0];

		vec4 colors[] = 
		{
			vec4(0.0f, 0.0f, 0.5f, 1.0f),
			vec4(0.7f, 0.6f, 0.0f, 1.0f),
			vec4(0.45f, 0.38f, 0.26f, 1.0f),
			vec4(0.0f, 0.7f, 0.8f, 1.0f),
			vec4(0.9f, 0.9f, 1.0f, 1.0f),
			vec4(0.9f, 0.9f, 1.0f, 1.0f) // sentinel
		};

		float boundary_points[] = {0.0f, 0.62f, 0.75f, 0.88f, 1.0f, 1.0f};

		int lower_bound = -1;
		for(int i = 0; i < 5; ++i)
		{
			if( height < boundary_points[i] ){
				break;
			}
			lower_bound = i;
		}
		
		if(lower_bound == -1)
		{
			out.color[0] = colors[0];
		}
		else
		{
			float lower_value = boundary_points[lower_bound];
			float interval = boundary_points[lower_bound+1]-lower_value;
			out.color[0] = lerp( colors[lower_bound], colors[lower_bound+1], (height-lower_value)/interval );
		}

		return true;
	}
 void shader_prog(const vs_input& in, vs_output& out)
 {
     vec4 pos = in.attribute(0);
     transform(out.position(), pos, wvp);
     out.attribute(0) = vec4(in.attribute(0).x(), in.attribute(0).z(), 0, 0);
 }