Example #1
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));
	}
Example #2
0
	void RenderableTriBox::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, 2, 3, 3, 1, 0,
			5, 7, 6, 6, 4, 5,
			4, 0, 1, 1, 5, 4,
			4, 6, 2, 2, 0, 4,
			2, 6, 7, 7, 3, 2,
			1, 3, 7, 7, 5, 1
		};

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

		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, 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;
	}
Example #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_.push_back(std::make_pair("color_tex", TexturePtr()));
	input_pins_.push_back(std::make_pair("depth_tex", TexturePtr()));

	output_pins_.push_back(std::make_pair("output", TexturePtr()));

	params_.push_back(std::make_pair("strength", RenderEffectParameterPtr())); 
	params_.push_back(std::make_pair("correction", RenderEffectParameterPtr()));

	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(blur_x_tech_);

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

	color_tex_param_ = technique_->Effect().ParameterByName("color_tex");
	step_param_ = technique_->Effect().ParameterByName("step");
	far_plane_param_ = technique_->Effect().ParameterByName("far_plane");
}
Example #4
0
	void RenderableLine::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");
		color_ep_ = effect->ParameterByName("color");
		mvp_param_ = effect->ParameterByName("mvp");

		float vertices[] =
		{
			0, 1
		};

		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_LineList);

		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;
	}
Example #5
0
	RenderableSkyBox::RenderableSkyBox()
		: RenderableHelper(L"SkyBox")
	{
		RenderFactory& rf = Context::Instance().RenderFactoryInstance();

		RenderEffectPtr effect = SyncLoadRenderEffect("SkyBox.fxml");
		if (deferred_effect_)
		{
			this->BindDeferredEffect(effect);
			depth_tech_ = effect->TechniqueByName("DepthSkyBoxTech");
			gbuffer_rt0_tech_ = effect->TechniqueByName("GBufferSkyBoxRT0Tech");
			gbuffer_rt1_tech_ = effect->TechniqueByName("GBufferSkyBoxRT1Tech");
			gbuffer_mrt_tech_ = effect->TechniqueByName("GBufferSkyBoxMRTTech");
			special_shading_tech_ = effect->TechniqueByName("SkyBoxTech");
			this->Technique(gbuffer_rt0_tech_);

			effect_attrs_ |= EA_SpecialShading;
		}
		else
		{
			this->Technique(effect->TechniqueByName("SkyBoxTech"));
		}

		float3 xyzs[] =
		{
			float3(1.0f, 1.0f, 1.0f),
			float3(1.0f, -1.0f, 1.0f),
			float3(-1.0f, 1.0f, 1.0f),
			float3(-1.0f, -1.0f, 1.0f),
		};

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

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

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

		pos_aabb_ = MathLib::compute_aabbox(&xyzs[0], &xyzs[4]);
		tc_aabb_ = AABBox(float3(0, 0, 0), float3(0, 0, 0));
	}
Example #6
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);
			}
		}
	}
Example #7
0
	void OnCreate()
	{
		RenderEffectPtr effect = SyncLoadRenderEffect(fxml_name);

		ofstream ofs((fxml_name + ".shader").c_str(), std::ios_base::binary);
		ofs << "#define KLAYGE_D3D11 1" << "\r\n";
		ofs << "#define KLAYGE_SHADER_MODEL (5 * 4 + 0)" << "\r\n";
		ofs << "#define KLAYGE_MAX_TEX_ARRAY_LEN 512" << "\r\n";
		ofs << "#define KLAYGE_MAX_TEX_DEPTH 512" << "\r\n";
		ofs << "#define KLAYGE_MAX_TEX_UNITS 32" << "\r\n";
		ofs << "#define KLAYGE_NO_TEX_LOD 0" << "\r\n";
		ofs << "#define KLAYGE_FLIPPING -1" << "\r\n";
		ofs << "#define KLAYGE_DERIVATIVES 1" << "\r\n";
		ofs << "\r\n";

		for (uint32_t i = 0; i < effect->NumMacros(); ++ i)
		{
			std::pair<std::string, std::string> const & name_value = effect->MacroByIndex(i);
			ofs << "#define " << name_value.first << " " << name_value.second << "\r\n";
		}
		ofs << "\r\n";

		for (uint32_t i = 0; i < effect->NumCBuffers(); ++ i)
		{
			RenderEffectConstantBufferPtr const & cbuff = effect->CBufferByIndex(i);
			ofs << "cbuffer " << *cbuff->Name() << std::endl;
			ofs << "{" << "\r\n";

			for (uint32_t j = 0; j < cbuff->NumParameters(); ++ j)
			{
				RenderEffectParameter& param = *effect->ParameterByIndex(cbuff->ParameterIndex(j));
				switch (param.Type())
				{
				case REDT_texture1D:
				case REDT_texture2D:
				case REDT_texture3D:
				case REDT_textureCUBE:
				case REDT_texture1DArray:
				case REDT_texture2DArray:
				case REDT_texture3DArray:
				case REDT_textureCUBEArray:
				case REDT_sampler:
				case REDT_buffer:
				case REDT_structured_buffer:
				case REDT_byte_address_buffer:
				case REDT_rw_buffer:
				case REDT_rw_structured_buffer:
				case REDT_rw_texture1D:
				case REDT_rw_texture2D:
				case REDT_rw_texture3D:
				case REDT_rw_texture1DArray:
				case REDT_rw_texture2DArray:
				case REDT_rw_byte_address_buffer:
				case REDT_append_structured_buffer:
				case REDT_consume_structured_buffer:
					break;

				default:
					ofs << "\t" << effect->TypeName(param.Type()) << " " << *param.Name();
					if (param.ArraySize())
					{
						ofs << "[" << *param.ArraySize() << "]";
					}
					ofs << ";" << "\r\n";
					break;
				}
			}

			ofs << "};" << "\r\n\r\n";
		}

		for (uint32_t i = 0; i < effect->NumParameters(); ++ i)
		{
			RenderEffectParameter& param = *(effect->ParameterByIndex(i));

			switch (param.Type())
			{
			case REDT_texture1D:
				{
					std::string elem_type;
					param.Var()->Value(elem_type);
					ofs << "Texture1D<" << elem_type << "> " << *param.Name() << ";" << "\r\n";
				}
				break;

			case REDT_texture2D:
				{
					std::string elem_type;
					param.Var()->Value(elem_type);
					ofs << "Texture2D<" << elem_type << "> " << *param.Name() << ";" << "\r\n";
				}
				break;

			case REDT_texture3D:
				{
					std::string elem_type;
					param.Var()->Value(elem_type);
					ofs << "Texture3D<" << elem_type << "> " << *param.Name() << ";" << "\r\n";
				}
				break;

			case REDT_textureCUBE:
				{
					std::string elem_type;
					param.Var()->Value(elem_type);
					ofs << "TextureCube<" << elem_type << "> " << *param.Name() << ";" << "\r\n";
				}
				break;

			case REDT_texture1DArray:
				{
					std::string elem_type;
					param.Var()->Value(elem_type);
					ofs << "Texture1DArray<" << elem_type << "> " << *param.Name() << ";" << "\r\n";
				}
				break;

			case REDT_texture2DArray:
				{
					std::string elem_type;
					param.Var()->Value(elem_type);
					ofs << "Texture2DArray<" << elem_type << "> " << *param.Name() << ";" << "\r\n";
				}
				break;

			case REDT_textureCUBEArray:
				{
					std::string elem_type;
					param.Var()->Value(elem_type);
					ofs << "TextureCubeArray<" << elem_type << "> " << *param.Name() << ";" << "\r\n";
				}
				break;

			case REDT_buffer:
				{
					std::string elem_type;
					param.Var()->Value(elem_type);
					ofs << "Buffer<" << elem_type << "> " << *param.Name() << ";" << "\r\n";
				}
				break;

			case REDT_sampler:
				ofs << "sampler " << *param.Name() << ";" << "\r\n";
				break;

			case REDT_structured_buffer:
				{
					std::string elem_type;
					param.Var()->Value(elem_type);
					ofs << "StructuredBuffer<" << elem_type << "> " << *param.Name() << ";" << "\r\n";
				}
				break;

			case REDT_byte_address_buffer:
				{
					ofs << "ByteAddressBuffer " << *param.Name() << ";" << "\r\n";
				}
				break;

			case REDT_rw_buffer:
				{
					std::string elem_type;
					param.Var()->Value(elem_type);
					ofs << "RWBuffer<" << elem_type << "> " << *param.Name() << ";" << "\r\n";
				}
				break;

			case REDT_rw_structured_buffer:
				{
					std::string elem_type;
					param.Var()->Value(elem_type);
					ofs << "RWStructuredBuffer<" << elem_type << "> " << *param.Name() << ";" << "\r\n";
				}
				break;

			case REDT_rw_texture1D:
				{
					std::string elem_type;
					param.Var()->Value(elem_type);
					ofs << "RWTexture1D<" << elem_type << "> " << *param.Name() << ";" << "\r\n";
				}
				break;

			case REDT_rw_texture2D:
				{
					std::string elem_type;
					param.Var()->Value(elem_type);
					ofs << "RWTexture2D<" << elem_type << "> " << *param.Name() << ";" << "\r\n";
				}
				break;

			case REDT_rw_texture3D:
				{
					std::string elem_type;
					param.Var()->Value(elem_type);
					ofs << "RWTexture3D<" << elem_type << "> " << *param.Name() << ";" << "\r\n";
				}
				break;
			case REDT_rw_texture1DArray:
				{
					std::string elem_type;
					param.Var()->Value(elem_type);
					ofs << "RWTexture1DArray<" << elem_type << "> " << *param.Name() << ";" << "\r\n";
				}
				break;

			case REDT_rw_texture2DArray:
				{
					std::string elem_type;
					param.Var()->Value(elem_type);
					ofs << "RWTexture2DArray<" << elem_type << "> " << *param.Name() << ";" << "\r\n";
				}
				break;

			case REDT_rw_byte_address_buffer:
				{
					ofs << "RWByteAddressBuffer " << *param.Name() << ";" << "\r\n";
				}
				break;

			case REDT_append_structured_buffer:
				{
					std::string elem_type;
					param.Var()->Value(elem_type);
					ofs << "AppendStructuredBuffer<" << elem_type << "> " << *param.Name() << ";" << "\r\n";
				}
				break;

			case REDT_consume_structured_buffer:
				{
					std::string elem_type;
					param.Var()->Value(elem_type);
					ofs << "ConsumeStructuredBuffer<" << elem_type << "> " << *param.Name() << ";" << "\r\n";
				}
				break;

			default:
				break;
			}
		}

		for (uint32_t i = 0; i < effect->NumShaders(); ++ i)
		{
			RenderShaderFunc const & effect_shader = effect->ShaderByIndex(i);
			ofs << effect_shader.str() << "\r\n";
		}
	}