Purpose:
Create a Shader to Implement the Phong and Blinn-Phong Specular Lighting.
Solution:
1.Study of the Phong Specular Lighting from <<Introduction to 3D Game Programming with DirectX 10>>
2.the Blinn Modification to Phong
the major different between Phong and Blinn is the H(Half) vector, Phong calculate reflectance between R and V, the Blinn calculate with H and N(Normal).
3.Shader Source
float4x4 wvp : WorldViewProjection <string UIWidget="None" ;>;
float4x4 w : World <string UIWidget="None";>;
float4x4 vi: ViewInverse <string UIWidget="None";>;
float4 LightPosition : POSITION
<
string UIName="Light Position";
string Object="PointLight";
string Space="World";
int refID=0;
> =float4(100,100,100,0);
float4 LightColor: LIGHTCOLOR
<
int LightRef=0;
> =float4(1,1,1,0);
float Glossiness
<
string UIName="Glossiness";
int UIMin=1;
int UIMax=99;
int UIStep=1;
> = 0;
float SpecularLevel
<
string UIName="Specular Level";
int UIMin=0;
int UIMax=99;
int UIStep=1;
> = 0;
bool EnableSpecular
<
string UIName="Enable Specular Lighting";
> = true;
struct VS_INPUT
{
float4 Pos: POSITION;
float4 Normal: NORMAL;
};
struct VS_OUTPUT
{
float4 Pos : POSITION0;
float3 L: TEXCOORD0;
float3 N: TEXCOORD1;
float3 V: TEXCOORD2;
};
VS_OUTPUT vs_main(VS_INPUT Input)
{
VS_OUTPUT Result;
Result.Pos = mul(Input.Pos,wvp);
float3 worldPos=mul(Input.Pos,w);
Result.L=LightPosition-worldPos;
Result.N=mul(Input.Normal,w);
Result.V=vi[3]-worldPos;
return Result;
}
float4 ps_main(VS_OUTPUT Input):COLOR
{
float3 N=normalize(Input.N);
float3 L=normalize(Input.L);
float3 V=normalize(Input.V);
float3 H=normalize(L+V);
float NdotL=max(0.0f,dot(N,L));
float NdotH=max(0.0f,dot(H,N));
float3 Diffuse=LightColor*NdotL;
float3 Specular=EnableSpecular?Glossiness*pow(NdotH,SpecularLevel):0;
return float4(Diffuse+Specular,1);
}
float4 ps_phong_main(VS_OUTPUT Input):COLOR
{
float3 N=normalize(Input.N);
float3 L=normalize(Input.L);
float3 V=normalize(Input.V);
float3 R=-reflect(L,N);
float NdotL=max(0,dot(N,L));
float RdotV=max(0,dot(R,V));
float3 Diffuse=LightColor*NdotL;
float3 Specular=EnableSpecular?Glossiness*pow(RdotV,SpecularLevel):0;
return float4(Diffuse+Specular,1);
}
technique BlinnSpecular
{
pass Blinn
{
VertexShader = compile vs_2_0 vs_main();
PixelShader = compile ps_2_0 ps_main();
}
};
technique PhongSpecular
{
pass Phong
{
VertexShader = compile vs_2_0 vs_main();
PixelShader = compile ps_2_0 ps_phong_main();
}
};
4.Preview
Specular lighting disabled
Phong and Blinn compares
Phong
Blinn
Phong
Blinn
Phong
Blinn
- 大小: 167.1 KB
- 大小: 21.8 KB
- 大小: 91 KB
- 大小: 183.5 KB
- 大小: 197.8 KB
- 大小: 165.2 KB
- 大小: 176 KB
- 大小: 192.4 KB
- 大小: 162.1 KB
分享到:
相关推荐
HLSL for windows shaders programming
唯一一本介绍了dx和hlsl的实时渲染书籍
本教程针对HLSL(High Level Shading Language)初学者,从应用的角度对HLSL、顶点着色器、像素着色器和Effect效果框架进行了介绍,教程中去掉了对HLSL语法等一些细节内容的讨论,力求帮助读者尽可能快地理解HLSL...
【0积分下载】版本:1.1.302 原作者最近更新于2020/12/15
HLSL效果在Silverlight中应用--------------------------------------------------------------------------
本教程针对HLSL(High Level Shading Language)初学者,从应用的角度对HLSL、顶点着色器、像素着色器和Effect效果框架进行了介绍,教程中去掉了对HLSL语法等一些细节内容的讨论,力求帮助读者尽可能快地理解HLSL...
自己备份用
4.GLSL和HLSL的比较 3 5. Cg和HLSL的比较 3 2:HLSL的变量 3 1.标量型 3 2.向量型 3 3.矩阵型 4 4.对象型 5 5.结构体型 6 6.用户自定义型 6 7.变量类型的转换 6 8.修饰变量的关键字 7 9.变量重组 7 3:HLSL的...
新闻 不再支持Visual Studio 2013 ,不再正式支持Microsoft Visual Studio 2013。 请至少升级到Visual Studio 2015。 版本控制方案正在改进,您可能会注意到一些差异。 这是当前在制品,但即将推出。...
通过 HLSL 中的 Pixel Shader 让一张图片 黑白化, 中文注释版本。
DirectX 3D HLSL高级实例精讲_HLSL程序入门
Deferred Shading for Volume Shadows Section 13.4. Summary Section 13.5. Further Information Chapter 14. Surface Characteristics Section 14.1. Refraction Section 14.2. Diffraction Section 14.3. BRDF ...
hlsl2glsl hlsl转换为glsl图形化工具hlsl2glsl hlsl转换为glsl图形化工具
SHADER入門必備知識 利用HLSL的強大渲染技術 讓你在開發遊戲的時候無往不利!配合DTRECT3D 讓你在開發遊戲時更迅速
D3D HLSL phong 光照模型 基本的HLSL入门例子
本文会对Direct3D/HLSL做一个简单的介绍,但是假设读者已经了解和掌握了Direct3D/HLSL的基本知识。 简介. 1)Direct3D和HLSL 众所周知,Direct3D是微软开发的用于编写Windows下高性能图形程序的3D API。通过Direct...
direct3d/d3d11/sdkmesh/HLSL/DDSWithoutD3D
Hlsl反编译器 将Shader Model 3.0着色器反编译为HLSL代码 用法 HlslDecompiler [--ast] shader.fxc 程序将在shader.asm中输出程序集列表,例如 ps_3_0 def c0, 1, 0, 2, 0 dcl_texcoord v0.xz mov oC0.x, -v0.z_abs...