x


Fresnel controlled by texture

Hey everyone,

I'm trying to create a shader which has a fresnel element that is controlled by a texture. In other words, I want to be able to prevent the fresnel effect from showing up in certain directions (the bottom of the model, since having bright fresnel coming from below a model tends to look strange). I almost had it working, but whatever I did, made the fresnel stop responding to the viewDIR, and the texture which is meant to control the fresnel is not working correctly.

This is the texture I want to use to control the fresnel.

alt text

And this is what it looks like, right now (broken).

alt text

See code below.

Thanks a ton for any help.

Shader "WMS/FresnelTex" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _SpecColor ("Specular Color", Color) = (1, 1, 1, 1)
    _RimColor ("Rim Color", Color) = (0.26,0.19,0.16,0.0)
    _RimPower ("FresnelTex", 2D) = "white" {}
    _MainTex ("Diffuse", 2D) = "white" {}
    _BumpMap ("Normal", 2D) = "bump" {}
    _SpecMap ("Specular (R) Polish (G)", 2D) = "black" {}
}
SubShader { 
    Tags { "RenderType"="Opaque" }
    LOD 400

CGPROGRAM
#pragma surface surf BlinnPhong

sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _SpecMap;
sampler2D _RimPower;
fixed4 _Color;
half _Shininess;
float4 _RimColor;


struct Input {
    float2 uv_MainTex;
    float2 uv_BumpMap;
    float2 uv_SpecMap;
    float2 uv_RimPower;
    float3 viewDir;
};

void surf (Input IN, inout SurfaceOutput o) {
    fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    fixed4 specTex = tex2D(_SpecMap, IN.uv_SpecMap);
    fixed4 rimTex = tex2D(_RimPower, IN.uv_RimPower);
    o.Albedo = tex.rgb * _Color.rgb;
    o.Gloss = specTex.r;
    o.Specular = specTex.g;
    o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
    o.Emission = _RimColor.rgb * rimTex.rgb;
}
ENDCG
}

FallBack "Specular"
fresnel.jpg (26.4 kB)
fresnel_broken.jpg (344.2 kB)
more ▼

asked Aug 27 '12 at 07:37 PM

avoorhees gravatar image

avoorhees
3 2 3 5

I should mention, I don't know much at all about coding.

Aug 27 '12 at 07:30 PM avoorhees
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5070
x1652
x5

asked: Aug 27 '12 at 07:37 PM

Seen: 287 times

Last Updated: Aug 27 '12 at 07:37 PM