Skip to content

Instantly share code, notes, and snippets.

@zao
Created February 2, 2012 21:02
Show Gist options
  • Save zao/1725736 to your computer and use it in GitHub Desktop.
Save zao/1725736 to your computer and use it in GitHub Desktop.
Pixel shader for mesh
ctx->PSSetShader(shaders.ps, NULL, 0);
ctx->PSSetShaderResources(0, 1, &diffuse_texture.view.p);
ctx->PSSetSamplers(0, 1, &diffuse_texture.state.p);
Texture2D diffuse_tex;
SamplerState sample_type;
struct pixel_input_type
{
float4 position : SV_POSITION;
float3 normal : NORMAL;
float2 tex : TEXCOORD0;
};
float3 blend(float3 a, float3 b, float lo, float hi, float s)
{
float r = hi - lo;
s = (s - lo)/r;
return (s <= 0 || s > 1)
? float3(0, 0, 0)
: lerp(a, b, s);
}
float4 pixel_shader(pixel_input_type input) : SV_TARGET
{
float3 n = normalize(input.normal);
float3 l = float3(0.0, 1.0, 0.0);
float intensity = dot(n, l);
// float3 bg = float3(102, 84, 70) / 255.0;
// float3 mid = float3(174, 204, 182) / 255.0;
// float3 fg = float3(222, 242, 196) / 255.0;
// float3 diffuse
// = blend(bg, bg, -1.0, -0.8, intensity)
// + blend(bg, mid, -0.8, 0.0, intensity)
// + blend(mid, fg, 0.0, 1.0, intensity)
// ;
// float3 diffuse = input.tex.xyx;
float3 diffuse = diffuse_tex.Sample(sample_type, input.tex);
return float4(0.8 * diffuse, 0.4);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment