0
我想在Ogre3D 1.9中为我的游戏制作Phong lightning着色器。Phong底纹与定向光造成全白色多边形
我可以做漫反射并添加一个法线贴图到一架飞机,但是当我添加镜面反射部件时,所有东西都会变成明亮的白色。
这里是没有镜面反射分量的图像
奇怪的是,当我在FX Composer的把完全相同的着色器代码,它的工作原理
这里是着色器代码
float4x4 worldViewProj;
float4x4 world;
float4 ambientColor;
float4x4 worldInverseTranspose;
float shininess = 8;
sampler textureSampler : register(s0);
sampler bumpSampler : register(s1);
struct VertexShaderInput
{
float4 position : POSITION0;
float3 normal : NORMAL;
float2 textureCoord : TEXCOORD0;
float3 tangent : TANGENT;
};
struct VertexShaderOutput
{
float4 position : POSITION0;
float3 normal : TEXCOORD0;
float2 textureCoord : TEXCOORD1;
float3 pixelPos : TEXCOORD2;
float3 tangent : TEXCOORD3;
float3 binormal : TEXCOORD4;
};
VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;
output.position = mul (worldViewProj,input.position);
output.normal = normalize(mul(worldInverseTranspose, input.normal));
output.tangent = normalize(mul(worldInverseTranspose,input.tangent));
output.binormal = normalize(mul(worldInverseTranspose,cross(input.tangent.xyz,input.normal)));
output.textureCoord = input.textureCoord;
output.pixelPos = output.position.xyz;
return output;
}
float4 PixelShaderFunction(VertexShaderOutput input, uniform float3 cameraPos, uniform float4 diffLightPos, uniform float lightCorrection) : COLOR0
{
//normal
float3 bump = (tex2D(bumpSampler, input.textureCoord) - (0.5,0.5,0.5));
float3 bumpNormal = normalize(input.normal + (bump.x * input.tangent + bump.y * input.binormal));
//diffuse light
float3 diffuseLightDirection = diffLightPos.xyz;
float diffuseIntensity = dot(normalize(diffuseLightDirection), bumpNormal);
if(diffuseIntensity < lightCorrection)
diffuseIntensity = lightCorrection;
//specular
float3 viewVector = normalize(cameraPos - mul(input.pixelPos, world).xyz);
float3 light = normalize(diffuseLightDirection);
float3 r = normalize(2 * bumpNormal * diffuseIntensity - light);
float3 v = normalize(viewVector);
float dotProduct = dot(r,v);
float4 specular = max(pow(dotProduct,shininess),0);
//texture
float4 textureColor = tex2D(textureSampler, input.textureCoord);
//clip(textureColor.a - 0.3);
textureColor.a = 1;
return ambientColor * ambientColor.x + textureColor * diffuseIntensity + specular;
}
这里是我的程序文件,因为我相信,也许这个问题可能是参数
vertex_program vertexPlanos hlsl
{
source Planos.hlsl
entry_point VertexShaderFunction
target vs_3_0
default_params
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto worldInverseTranspose inverse_transpose_world_matrix
}
}
fragment_program pixelPlanos hlsl
{
source Planos.hlsl
entry_point PixelShaderFunction
target ps_3_0
default_params
{
param_named_auto world world_matrix
param_named_auto cameraPos camera_position_object_space
param_named_auto ambientColor ambient_light_colour
param_named_auto diffLightPos light_position_object_space 0
param_named lightCorrection float 0
}
}
请之一,原谅我这个问题的长度,但我对这个工作周并找不到原因。
谢谢,但问题是在Ogre3d(引擎)。在编写仅返回一个arbritary颜色的着色器时,该对象变为透明。 –