Exemplo n.º 1
0
	void RenderableTriangle::Init()
	{
		RenderFactory& rf = Context::Instance().RenderFactoryInstance();

		RenderEffectPtr effect = SyncLoadRenderEffect("RenderableHelper.fxml");
		technique_ = simple_forward_tech_ = effect->TechniqueByName("LineTec");
		v0_ep_ = effect->ParameterByName("v0");
		v1_ep_ = effect->ParameterByName("v1");
		v2_ep_ = effect->ParameterByName("v2");
		color_ep_ = effect->ParameterByName("color");
		mvp_param_ = effect->ParameterByName("mvp");

		float vertices[] =
		{
			0, 1, 2
		};

		ElementInitData init_data;
		init_data.row_pitch = sizeof(vertices);
		init_data.slice_pitch = 0;
		init_data.data = vertices;

		rl_ = rf.MakeRenderLayout();
		rl_->TopologyType(RenderLayout::TT_TriangleList);

		GraphicsBufferPtr vb = rf.MakeVertexBuffer(BU_Static, EAH_GPU_Read | EAH_Immutable, &init_data);
		rl_->BindVertexStream(vb, make_tuple(vertex_element(VEU_Position, 0, EF_R32F)));

		tc_aabb_ = AABBox(float3(0, 0, 0), float3(0, 0, 0));

		*(effect->ParameterByName("pos_center")) = float3(0, 0, 0);
		*(effect->ParameterByName("pos_extent")) = float3(1, 1, 1);

		effect_attrs_ |= EA_SimpleForward;
	}
Exemplo n.º 2
0
	SSRPostProcess::SSRPostProcess()
			: PostProcess(L"ScreenSpaceReflection")
	{
		input_pins_.push_back(std::make_pair("g_buffer_0_tex", TexturePtr()));
		input_pins_.push_back(std::make_pair("g_buffer_1_tex", TexturePtr()));
		input_pins_.push_back(std::make_pair("front_side_depth_tex", TexturePtr()));
		input_pins_.push_back(std::make_pair("front_side_tex", TexturePtr()));
		input_pins_.push_back(std::make_pair("foreground_depth_tex", TexturePtr()));

		params_.push_back(std::make_pair("min_samples", RenderEffectParameterPtr()));
		params_.push_back(std::make_pair("max_samples", RenderEffectParameterPtr()));

		RenderEffectPtr effect = SyncLoadRenderEffect("SSR.fxml");
		this->Technique(effect->TechniqueByName("ScreenSpaceReflectionPostProcess"));

		if (technique_ && technique_->Validate())
		{
			proj_param_ = effect->ParameterByName("proj");
			inv_proj_param_ = effect->ParameterByName("inv_proj");
			near_q_far_param_ = effect->ParameterByName("near_q_far");
			ray_length_param_ = effect->ParameterByName("ray_length");
		}

		this->SetParam(0, static_cast<int32_t>(20));
		this->SetParam(1, static_cast<int32_t>(30));
	}
Exemplo n.º 3
0
	SSSBlurPP::SSSBlurPP()
			: PostProcess(L"SSSBlurPP")
	{
		RenderDeviceCaps const & caps = Context::Instance().RenderFactoryInstance().RenderEngineInstance().DeviceCaps();
		mrt_blend_support_ = (caps.max_simultaneous_rts > 1) && caps.independent_blend_support;

		input_pins_.emplace_back("src_tex", TexturePtr());
		input_pins_.emplace_back("depth_tex", TexturePtr());

		output_pins_.emplace_back("output", TexturePtr());

		params_.emplace_back("strength", nullptr);
		params_.emplace_back("correction", nullptr);

		RenderEffectPtr effect = SyncLoadRenderEffect("SSS.fxml");
		copy_tech_ = effect->TechniqueByName("Copy");
		blur_x_tech_ = effect->TechniqueByName("BlurX");
		if (mrt_blend_support_)
		{
			std::string blur_y_name = "BlurY1";
			for (uint32_t i = 0; i < 3; ++ i)
			{
				blur_y_name[5] = static_cast<char>('1' + i);
				blur_y_techs_[i] = effect->TechniqueByName(blur_y_name);
			}
		}
		else
		{
			blur_y_techs_[0] = blur_x_tech_;
			std::string accum_name = "Accum1";
			for (uint32_t i = 0; i < 3; ++ i)
			{
				accum_name[5] = static_cast<char>('1' + i);
				accum_techs_[i] = effect->TechniqueByName(accum_name);
			}
		}
		this->Technique(effect, blur_x_tech_);

		RenderFactory& rf = Context::Instance().RenderFactoryInstance();
		blur_x_fb_ = rf.MakeFrameBuffer();
		blur_y_fb_ = rf.MakeFrameBuffer();

		src_tex_param_ = effect->ParameterByName("src_tex");
		step_param_ = effect->ParameterByName("step");
		far_plane_param_ = effect->ParameterByName("far_plane");
	}
Exemplo n.º 4
0
void RenderableLineBox::Init()
{
    RenderFactory& rf = Context::Instance().RenderFactoryInstance();

    RenderEffectPtr effect = SyncLoadRenderEffect("RenderableHelper.fxml");
    technique_ = simple_forward_tech_ = effect->TechniqueByName("LineTec");
    v0_ep_ = effect->ParameterByName("v0");
    v1_ep_ = effect->ParameterByName("v1");
    v2_ep_ = effect->ParameterByName("v2");
    v3_ep_ = effect->ParameterByName("v3");
    v4_ep_ = effect->ParameterByName("v4");
    v5_ep_ = effect->ParameterByName("v5");
    v6_ep_ = effect->ParameterByName("v6");
    v7_ep_ = effect->ParameterByName("v7");
    color_ep_ = effect->ParameterByName("color");
    mvp_param_ = effect->ParameterByName("mvp");

    float vertices[] =
    {
        0, 1, 2, 3, 4, 5, 6, 7
    };

    uint16_t indices[] =
    {
        0, 1, 1, 3, 3, 2, 2, 0,
        4, 5, 5, 7, 7, 6, 6, 4,
        0, 4, 1, 5, 2, 6, 3, 7
    };

    rl_ = rf.MakeRenderLayout();
    rl_->TopologyType(RenderLayout::TT_LineList);

    ElementInitData init_data;
    init_data.row_pitch = sizeof(vertices);
    init_data.slice_pitch = 0;
    init_data.data = vertices;

    GraphicsBufferPtr vb = rf.MakeVertexBuffer(BU_Static, EAH_GPU_Read | EAH_Immutable, &init_data);
    rl_->BindVertexStream(vb, std::make_tuple(vertex_element(VEU_Position, 0, EF_R32F)));

    init_data.row_pitch = sizeof(indices);
    init_data.slice_pitch = 0;
    init_data.data = indices;

    GraphicsBufferPtr ib = rf.MakeIndexBuffer(BU_Static, EAH_GPU_Read | EAH_Immutable, &init_data);
    rl_->BindIndexStream(ib, EF_R16UI);

    tc_aabb_ = AABBox(float3(0, 0, 0), float3(0, 0, 0));

    *(effect->ParameterByName("pos_center")) = float3(0, 0, 0);
    *(effect->ParameterByName("pos_extent")) = float3(1, 1, 1);

    effect_attrs_ |= EA_SimpleForward;
}
Exemplo n.º 5
0
	SDSMCascadedShadowLayer::SDSMCascadedShadowLayer()
		: frame_index_(0)
	{
		RenderFactory& rf = Context::Instance().RenderFactoryInstance();
		RenderDeviceCaps const & caps = rf.RenderEngineInstance().DeviceCaps();
		cs_support_ = caps.cs_support && (caps.max_shader_model >= ShaderModel(5, 0));

		if (cs_support_)
		{
			interval_buff_ = rf.MakeVertexBuffer(BU_Dynamic, EAH_GPU_Read | EAH_GPU_Write | EAH_GPU_Unordered | EAH_GPU_Structured, nullptr, EF_GR32F);
			scale_buff_ = rf.MakeVertexBuffer(BU_Dynamic, EAH_GPU_Write | EAH_GPU_Unordered | EAH_GPU_Structured, nullptr, EF_BGR32F);
			bias_buff_ = rf.MakeVertexBuffer(BU_Dynamic, EAH_GPU_Write | EAH_GPU_Unordered | EAH_GPU_Structured, nullptr, EF_BGR32F);
			cascade_min_buff_ = rf.MakeVertexBuffer(BU_Dynamic, EAH_GPU_Read | EAH_GPU_Write | EAH_GPU_Unordered | EAH_GPU_Structured, nullptr, EF_BGR32F);
			cascade_max_buff_ = rf.MakeVertexBuffer(BU_Dynamic, EAH_GPU_Read | EAH_GPU_Write | EAH_GPU_Unordered | EAH_GPU_Structured, nullptr, EF_BGR32F);

			interval_buff_->Resize(MAX_NUM_CASCADES * sizeof(float2));
			scale_buff_->Resize(MAX_NUM_CASCADES * sizeof(float3));
			bias_buff_->Resize(MAX_NUM_CASCADES * sizeof(float3));
			cascade_min_buff_->Resize(MAX_NUM_CASCADES * sizeof(float3));
			cascade_max_buff_->Resize(MAX_NUM_CASCADES * sizeof(float3));

			for (uint32_t i = 0; i < 2; ++ i)
			{
				interval_cpu_buffs_[i] = rf.MakeVertexBuffer(BU_Dynamic, EAH_CPU_Read, nullptr);
				scale_cpu_buffs_[i] = rf.MakeVertexBuffer(BU_Dynamic, EAH_CPU_Read, nullptr);
				bias_cpu_buffs_[i] = rf.MakeVertexBuffer(BU_Dynamic, EAH_CPU_Read, nullptr);

				interval_cpu_buffs_[i]->Resize(interval_buff_->Size());
				scale_cpu_buffs_[i]->Resize(scale_buff_->Size());
				bias_cpu_buffs_[i]->Resize(bias_buff_->Size());
			}

			RenderEffectPtr effect = SyncLoadRenderEffect("CascadedShadow.fxml");

			clear_z_bounds_tech_ = effect->TechniqueByName("ClearZBounds");
			reduce_z_bounds_from_depth_tech_ = effect->TechniqueByName("ReduceZBoundsFromDepth");
			compute_log_cascades_from_z_bounds_tech_ = effect->TechniqueByName("ComputeLogCascadesFromZBounds");
			clear_cascade_bounds_tech_ = effect->TechniqueByName("ClearCascadeBounds");
			reduce_bounds_from_depth_tech_ = effect->TechniqueByName("ReduceBoundsFromDepth");
			compute_custom_cascades_tech_ = effect->TechniqueByName("ComputeCustomCascades");

			interval_buff_param_ = effect->ParameterByName("interval_buff");
			interval_buff_uint_param_ = effect->ParameterByName("interval_buff_uint");
			interval_buff_read_param_ = effect->ParameterByName("interval_buff_read");
			scale_buff_param_ = effect->ParameterByName("scale_buff");
			bias_buff_param_ = effect->ParameterByName("bias_buff");
			cascade_min_buff_uint_param_ = effect->ParameterByName("cascade_min_buff_uint");
			cascade_max_buff_uint_param_ = effect->ParameterByName("cascade_max_buff_uint");
			cascade_min_buff_read_param_ = effect->ParameterByName("cascade_min_buff_read");
			cascade_max_buff_read_param_ = effect->ParameterByName("cascade_max_buff_read");
			depth_tex_param_ = effect->ParameterByName("depth_tex");
			num_cascades_param_ = effect->ParameterByName("num_cascades");
			inv_depth_width_height_param_ = effect->ParameterByName("inv_depth_width_height");
			near_far_param_ = effect->ParameterByName("near_far");
			upper_left_param_ = effect->ParameterByName("upper_left");
			xy_dir_param_ = effect->ParameterByName("xy_dir");
			view_to_light_view_proj_param_ = effect->ParameterByName("view_to_light_view_proj");
			light_space_border_param_ = effect->ParameterByName("light_space_border");
			max_cascade_scale_param_ = effect->ParameterByName("max_cascade_scale");
		}
		else
		{
			reduce_z_bounds_from_depth_pp_ = SyncLoadPostProcess("CascadedShadow.ppml", "reduce_z_bounds_from_depth");
			reduce_z_bounds_from_depth_mip_map_pp_ = SyncLoadPostProcess("CascadedShadow.ppml", "reduce_z_bounds_from_depth_mip_map");
			compute_log_cascades_from_z_bounds_pp_ = SyncLoadPostProcess("CascadedShadow.ppml", "compute_log_cascades_from_z_bounds");

			interval_tex_ = rf.MakeTexture2D(MAX_NUM_CASCADES, 1, 1, 1, EF_GR16F, 1, 0, EAH_GPU_Read | EAH_GPU_Write, nullptr);
			for (uint32_t i = 0; i < 2; ++ i)
			{
				interval_cpu_texs_[i] = rf.MakeTexture2D(MAX_NUM_CASCADES, 1, 1, 1, EF_GR16F, 1, 0, EAH_CPU_Read, nullptr);
			}
		}
	}