Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


DX11 Uber Shading - Lighting


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Migi0027 =A=   Crossbones+   -  Reputation: 1921

Like
0Likes
Like

Posted 16 February 2013 - 05:52 PM

Hi guys,

 

right now I'm facing a problem with lighting in Uber Shading, my Shader file looks as following:

 

cbuffer ConstantObjectBuffer
{
	float4x4 final;
	float4x4 rotation;
	float4 ambientcol;
}

cbuffer ConstantFrameBuffer
{
	float4 lightvec;
	float4 lightcol;
}

cbuffer UberData
{
	int _diffuse;
	int _texture;
	int _directionall;
	int _bumpmap;
}

cbuffer ConstantMatrixBuffer
{
	float4 world;
	float4 view;
	float4 projection;
}

Texture2D txt;
Texture2D txt2;
SamplerState ss;

struct VOut
{
    float4 position : SV_POSITION;
    float2 texcoord : TEXCOORD;    // texture coordinates
	float4 normal : NORMAL;
    float4 color : COLOR;
};

VOut VShader(float4 position : POSITION, float4 normal : NORMAL, float2 texcoord : TEXCOORD)
{
    VOut output;
    output.position = mul(final, position);

	output.color = float4(0, 0, 0, 1);

    // set the ambient light
	if (_diffuse == 1)
	{
		output.color = ambientcol;
	}

	if (_texture == 1)
	{
		output.texcoord = texcoord;
	}

	if (_directionall == 1)
	{
		float4 norm = normalize(mul(rotation, normal));
		float diffusebrightness = saturate(dot(norm, lightvec));
		output.color += lightcol * diffusebrightness;

		float4 light = normalize(lightvec);
		float4 eye = float4(1.0, 1.0, 1.0, 0.0);
		float4 vhalf = normalize(light + eye);

		float4 specularMaterial = float4(1, 1, 1, 1.0);
		float specular = dot(normal, vhalf);

		output.color += specular*specularMaterial;
	}

    return output;
}

float4 PShader(VOut input) : SV_TARGET
{
	float4 color = input.color;

	if (_texture == 1)
	{
		color *= txt.Sample(ss, input.texcoord);
	}

    return color;
}

 

 

As you can see I have a section of lighting, and this Shader file is used once per mesh. But the problem is what if I have more than one light? Maybe 3? As hlsl cannot declare dynamic arrays, is the only option to have limited lights?

 

I am aware of this deffered rendering, just not how it works, though I can't say I have put a lot of research effort into that, but would that fit here?

 

Thank You


Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to kill everyone you meet, ohh, AND STEAL ALL ZE TRIANGLES FROM ZHEM!

Sponsor:

#2 qorthos   Members   -  Reputation: 165

Like
0Likes
Like

Posted 16 February 2013 - 08:45 PM

Yup!  Deferred shading is great for large numbers of light sources of varying magnitudes, sizes and intensities.



#3 Hodgman   Moderators   -  Reputation: 30885

Like
0Likes
Like

Posted 17 February 2013 - 12:54 AM

As hlsl cannot declare dynamic arrays, is the only option to have limited lights?

You can declare the array to be some limited size, n, and then if you have more than n lights, you can render the model in ceil(lights / n) passes. The first pass can be opaque, and then every successive pass can be additively blended over the top.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS