• Advertisement
Sign in to follow this  

Image Based Specular Problem

This topic is 1906 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.


(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.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;

Share this post

Link to post
Share on other sites
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 [eqn]f_r(theta_h,theta_d)[/eqn]. 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

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
Multiply your specular value with saturate(dot(N,L). This will get rid of that halo. This is also physically correct.

Share this post

Link to post
Share on other sites
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:
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

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement