Jump to content

A problem on deferred rendering fragment


photo

Recommended Posts

Posted

Hi,

 

I'm learning the source code of deferred rendering fragment (UUSL) coming from "Creating a Custom Shader for Deferred Rendering Pass" Doc.
It works just fine. The outcome is a white object.
 
#include <core/shaders/common/fragment.h>

STRUCT(FRAGMENT_IN)
INIT_POSITION // Projected position
INIT_IN(float4,0) // Texcoord (uv)
END

MAIN_BEGIN_DEFERRED(FRAGMENT_IN)

GBuffer gbuffer = GBufferDefault();
setGBuffer(gbuffer);

MAIN_END

// end

But when I modified the code like that:
MAIN_BEGIN_DEFERRED(FRAGMENT_IN)

 float4 texcoord = IN_DATA(0);// Get the UV coords 
 float4 texture_data = TEXTURE(TEX_COLOR,texcoord.xy); 

 GBuffer gbuffer = GBufferDefault();
 gbuffer.albedo = texture_data.rgb;
 setGBuffer(gbuffer);
MAIN_END
The outcome turns to be a black object. 
 
Please help me to figure it out, Thanks.
Posted

Hi lin.xianming,

 

As I understand you're trying to add a texture to your material, correct me if I'm wrong.

 

In order to do this you have to add a texture slot to your material in the *.mat file.

		<material name="custom_mesh_material" editable="1">
		
		<!-- States -->
		<state name="deferred">1</state>
		
		<!-- Deferred rendering shaders -->
		<shader pass="deferred" object="mesh_static"
			deferred="1"
			defines="BASE_DEFERRED"
			vertex="<your project folder>/shaders/vertex/deferred.vert"
			fragment="<your project folder>/shaders/fragment/deferred.frag"/>
		
		<!-- Bindings -->
		<bind object="mesh_dynamic" to="mesh_static"/>
		<bind object="mesh_skinned" to="mesh_static"/>
		<texture unit="0" name="albedo" anisotropy="1" shader="fragment" pass="deferred">core/textures/common/white.dds</texture>
		</material>

And You have to insert a line initializing the texture slot named TEX_COLOR which you're trying to use into the fragment shader file:

// Include the UUSL language header
#include <core/shaders/common/fragment.h>

// Initialize the texture slot for a texture named TEX_COLOR
INIT_TEXTURE(0, TEX_COLOR)

// Input data struct
STRUCT(FRAGMENT_IN)
	INIT_POSITION				// Projected position
	INIT_IN(float4,0)			// Texcoord (uv)
END

MAIN_BEGIN_DEFERRED(FRAGMENT_IN)

 float4 texcoord = IN_DATA(0);// Get the UV coords 
 float4 texture_data = TEXTURE(TEX_COLOR,texcoord.xy); 

 GBuffer gbuffer = GBufferDefault();
 gbuffer.albedo = texture_data.rgb;
 setGBuffer(gbuffer);
MAIN_END

// end

I hope this helps!

 

Thank You!

Posted
It's helpful. Thank you so much. 
 
Go a step further. I'd like to let this specific object get rid of the influence of all lights, just exactly looks like the original texture. How should I assign the gbuffer? Like...
MAIN_BEGIN_DEFERRED(FRAGMENT_IN)

 float4 texcoord = IN_DATA(0);// Get the UV coords 
 float4 texture_data = TEXTURE(TEX_COLOR,texcoord.xy); 

 GBuffer gbuffer = GBufferDefault();
 gbuffer.albedo = texture_data.rgb;
 gbuffer.Normal = ...
 gbuffer.Shading = ...
 setGBuffer(gbuffer);
MAIN_END

I have try a lot. No one works.

Posted

Hi lin.xianming,

 

The point is that you can't ignore lighting in a deferred pass shader, as lights are rendered in a different pass.

Could you please specify the problem you are trying to solve, give me a more detailed description so I could help you to find a proper solution.

 

Thank You!

Posted

Hi Fox,

 

Say there is a TV screen in my application, the texture of the screen comes from a video file, I'd like to show what the video exactly is.

 

Thanks

Posted

Hi lin.xianming,

 

Actually Unigine offers a simpler and more convenient way to solve your problem.

 

There is a WidgetSpriteVideo class you can use to create a virtual monitor that plays a video file (the video must be in ogv format).

You can check out the following samples:

  1. developer.unigine.com/docs/code/uniginescript/samples/objects/gui_00
  2. developer.unigine.com/docs/code/uniginescript/samples/objects/gui_01

Or you can use the C++ code sample attached. Convert your video to ogv format, place it to the data folder of your application and insert the code from the attached files to your application. Don't forget to specify the name of your video file in the code instead of "YOUR_VIDEO_FILE_NAME.ogv"

 

Hope this solves your problem with a TV screen!

Thank You!

AppWorldLogic.h

AppWorldLogic.cpp

×
×
  • Create New...