• Create Account

# Daniel Wilson

Member Since 31 May 2012
Offline Last Active Aug 26 2012 04:16 PM

### How to change colour based on viewing angle

13 August 2012 - 02:52 PM

I would like to fake some caustics on a glassy surface very quickly, and the idea I have is to overlay a static caustic texture that appears based on the viewing angle, so when the angle is more grazing, more of the texture appears. How might I do this? A small piece of code would be seriously amazing.

Thankyou!

### When to normalize vectors in a shader?

02 August 2012 - 06:43 AM

Hi, I am currently working on a shader and the result is not quite right. One question that bugs me I cannot seem to find the answer to is why and when exactly we normalize vectors in a shader. I understand that it seems to only be important for direction vectors such as the light, but is it important to do so in certain spaces with other vectors aswell? I took a naive approach at first and normalized all the time. I am not so much concerned with efficiency, just why and when it is okay or not okay to normalize a vector.

For example, the shader I am writing at them moment requires the vector from the view position to the vertex position in world space. Some shaders I see normalize this when it is in the fragment shader, but does that not destroy the value of the vector for further calculations?

### Tool to mathematically create a mesh

17 July 2012 - 07:59 AM

Hi I need a good tool to mathematically create a surface and then get it into 3ds max, for example a sphere is defined algeraically as x^2 + y^2 + z^2 = r^2. Any examples? The only one I can find is 3D-Math Xplor, but the full version only works on a mac and I have Windows 7. The Java version that works on all platforms does not have the export functionality!

### What to do with an attenuated light vector in my shader

05 July 2012 - 11:22 AM

Hi, I am working on implementing a subsurface scattering light shader and have it all coded I just need to debug. I have a question I cannot solve though, say I have the attenuated light vector that has come from the light, scattered as it enters the surface of the object, and now goes to the viewers eye. What would I do with this output vector for for a mesh that has a standard Blinn-Phong shader? The image has the vector I am talking about, vector PC

In my normal lighting shader I have this:

```
float3 l = normalize(IN.light.xyz - IN.oPosition);
float3 v = normalize(IN.oPosition);

// compute diffuse and specular terms
float diff = saturate(dot(l,IN.normal));
float spec = saturate(dot(normalize(l-v),IN.normal));
spec = pow(spec, shine);
// attenuation factor
float att = saturate(dot(l, IN.normal));

// compute final color
float3 finalcolor;
finalcolor =  ambient.xyz*color.xyz +
att*(color.xyz*diffuse.xyz*diff +
specular*spec);

return float4(finalcolor.xyz, 1.0);
```

With no normal map or anything, how might I slot PC into this code. I'm thinking it would replace the view direction v that I have. Someone else told me the *= it with the final colour, but that just produces weird rainbow type colours, and my light is white

### Floating point texture in FX Composer

02 July 2012 - 09:36 AM

Hi, I need to use FX Composer because I have to debug my shader. I was using Ogre and cg (ps_3_0) before. Previously my app saved values to a floating point texture (containing a matrix) which was passed to the cg shader file. Does anyone know if it's even possible to create a matrix in fx composer, and save it to a floating point texture for future lookups? All I see in FX Composer is the ability to create color and depth targets.

PARTNERS