Jump to content

  • Log In with Google      Sign In   
  • Create Account


Image Based Specular Problem


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
4 replies to this topic

#1 Endemoniada   Members   -  Reputation: 306

Like
0Likes
Like

Posted 30 October 2012 - 11:51 AM

Hi guys, I'm trying to use an image (not a cubemap) for my specular component. It's working fine except that there is an outline where it's getting full light when it should be getting zero light. I don't really understand what I'm doing wrong.

Posted Image

(the left side is the render, the right is my specular image map)

Here is the pertinent HLSL:

***
View=view matrix;
Light=light position in world coords;

vertex shader:

float4 pos=position in world coords;

output.light=Light.xyz-pos.xyz;
output.view=View[3].xyz-pos.xyz;
output.normal=the normal;
output.colour=the colour;

pixel shader:

float3 L=normalize(input.light);
float3 N=normalize(input.normal);
float3 V=normalize(input.view);

float NL=saturate(dot(N,L));
float3 R=reflect(V,N);

// diffuse is just colour
float3 diffuse=input.color.rgb;

// make uv for specular image lookup
float2 uv=R.xy/2+0.5;

// look up specular
float3 specular=tex2D(Sampler0,uv).rgb;

// put together
float3 out=diffuse*NL+specular;
***

Sponsor:

#2 CryZe   Members   -  Reputation: 768

Like
0Likes
Like

Posted 30 October 2012 - 01:29 PM

Your sampler is probably misconfigured. You should set your D3DSAMP_ADDRESSU and D3DSAMP_ADDRESSV to D3DTADDRESS_CLAMP, so that it clamps the texture coordinates of your samples to [0.0, 1.0].

May I ask, why you are using this lookup table for your specular highlights anyway? Do you want to use it as an environment map or do you want to "paint" the shape of your specular highlights? If so, I'd recommend encoding this "BRDF" as . This way you can have physically correct specular highlights as a lookup table. As long as they are isotropic you can use a 2-dimensional texture, otherwise you need a 3-dimensional texture. You can even download captured BRDFs encoded this way from the Mitsubishi MERL BRDF database.

Edited by CryZe, 30 October 2012 - 01:34 PM.


#3 Endemoniada   Members   -  Reputation: 306

Like
0Likes
Like

Posted 30 October 2012 - 02:39 PM

Hi CryZe,

Unfortunately it's not the sampler.

Will you please give me some more info on the BRDF you described, how do I implement it ? It looks like what I want to do.

I'm doing this because the phong specular model is too limiting, it just makes a circle. I want to experiment with something a little better looking, like maybe multiple highlights, square highlights, etc.

Thanks for helping.

#4 kalle_h   Members   -  Reputation: 1307

Like
0Likes
Like

Posted 30 October 2012 - 06:43 PM

Multiply your specular value with saturate(dot(N,L). This will get rid of that halo. This is also physically correct.

#5 macnihilist   Members   -  Reputation: 368

Like
1Likes
Like

Posted 31 October 2012 - 02:34 AM

First, there seems to be some confusion about coordinate spaces.
You probably want to convert R form world space into tangent space for the texture lookup.
But, as pointed out by CryZe, R is not good for this kind of thing.
Consider using a function of the half-way vector.

Here is a slightly more complicated, but much better way to do it:
http://www.cs.utah.edu/~premoze/dbrdf/
Basically, you paint a microfacet distribution.
Given its simplicity, the d-BRDF works pretty well.

EDIT: Here is the pdf I wanted to link in the first place, but couldn't find:
http://www.cs.utah.edu/~michael/brdfs/facets.pdf

Edited by macnihilist, 31 October 2012 - 02:39 AM.





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