- 好友
- 1
- 在线时间
- 41 小时
- 最后登录
- 2020-6-21
扈从
- UID
- 2790595
- 第纳尔
- 226
- 精华
- 0
- 互助
- 4
- 荣誉
- 0
- 贡献
- 0
- 魅力
- 0
- 注册时间
- 2016-12-31
鲜花( 0) 鸡蛋( 0)
|
本帖最后由 白日依山尽L 于 2020-3-9 23:17 编辑
我打算写一个骑砍的旗子飘动shader但是遇到了问题,我在RenderMonkey中测试了我的代码可以飘动。然后我尝试着添加到骑砍官方提供的shader工具包mb.fx文件里代码如下:VS_OUTPUT_ENVMAP_SPECULAR vs_envmap_specular_Instanced(uniform const int PcfMode, float4 vPosition : POSITION, float3 vNormal : NORMAL,
float2 tc : TEXCOORD0, float4 vColor : COLOR0,
//instance data:
float3 vInstanceData0 : TEXCOORD1, float3 vInstanceData1 : TEXCOORD2,
float3 vInstanceData2 : TEXCOORD3, float3 vInstanceData3 : TEXCOORD4)
{
INITIALIZE_OUTPUT(VS_OUTPUT_ENVMAP_SPECULAR, Out);
vPosition.y = vPosition.y*sin(time_var*15)*vPosition.y*10;
float4x4 matWorldOfInstance = build_instance_frame_matrix(vInstanceData0, vInstanceData1, vInstanceData2, vInstanceData3);
float4 vWorldPos = mul(matWorldOfInstance, vPosition);
float3 vWorldN = normalize(mul((float3x3)matWorldOfInstance, vNormal));
vWorldPos.y = vWorldPos.y*sin(time_var*15)*vWorldPos.y*10;
if(bUseMotionBlur) //motion blur flag!?!
{
float4 vWorldPos1;
float3 moveDirection;
if(true) //instanced meshes dont have valid matMotionBlur!
{
const float blur_len = 0.2f;
moveDirection = -normalize( float3(matWorldOfInstance[0][0],matWorldOfInstance[1][0],matWorldOfInstance[2][0]) ); //using x axis !
moveDirection.y -= blur_len * 0.285; //low down blur for big blur_lens (show more like a spline)
vWorldPos1 = vWorldPos + float4(moveDirection,0) * blur_len;
}
else
{
vWorldPos1 = mul(matMotionBlur, vPosition);
moveDirection = normalize(vWorldPos1 - vWorldPos);
}
float delta_coefficient_sharp = (dot(vWorldN, moveDirection) > 0.12f) ? 1 : 0;
float y_factor = saturate(vPosition.y+0.15);
vWorldPos = lerp(vWorldPos, vWorldPos1, delta_coefficient_sharp * y_factor);
float delta_coefficient_smooth = saturate(dot(vWorldN, moveDirection) + 0.5f);
float extra_alpha = 0.1f;
float start_alpha = (1.0f+extra_alpha);
float end_alpha = start_alpha - 1.8f;
float alpha = saturate(lerp(start_alpha, end_alpha, delta_coefficient_smooth));
vColor.a = saturate(0.5f - vPosition.y) + alpha + 0.25;
}
Out.Pos = mul(matViewProj, vWorldPos);
Out.Tex0.xy = tc;
float3 relative_cam_pos = normalize(vCameraPos - vWorldPos);
float2 envpos;
float3 tempvec = relative_cam_pos - vWorldN;
float3 vHalf = normalize(relative_cam_pos - vSunDir);
float3 fSpecular = spec_coef * vSunColor * vSpecularColor * pow( saturate( dot( vHalf, vWorldN) ), fMaterialPower);
Out.vSpecular = fSpecular;
Out.vSpecular *= vColor.rgb;
envpos.x = (tempvec.y);// + tempvec.x);
envpos.y = tempvec.z;
envpos += 1.0f;
// envpos *= 0.5f;
Out.Tex0.zw = envpos;
float4 diffuse_light = vAmbientColor;
// diffuse_light.rgb *= gradient_factor * (gradient_offset + vWorldN.z);
//directional lights, compute diffuse color
diffuse_light += saturate(dot(vWorldN, -vSkyLightDir)) * vSkyLightColor;
//point lights
#ifndef USE_LIGHTING_PASS
diffuse_light += calculate_point_lights_diffuse(vWorldPos, vWorldN, false, false);
#endif
//apply material color
// Out.Color = min(1, vMaterialColor * vColor * diffuse_light);
Out.Color = (vMaterialColor * vColor * diffuse_light);
//shadow mapping variables
float wNdotSun = max(-0.0001f,dot(vWorldN, -vSunDir));
Out.SunLight = (wNdotSun) * vSunColor * vMaterialColor * vColor;
Out.SunLight.a = vColor.a;
if (PcfMode != PCF_NONE)
{
float4 ShadowPos = mul(matSunViewProj, vWorldPos);
Out.ShadowTexCoord = ShadowPos;
Out.ShadowTexCoord.z /= ShadowPos.w;
Out.ShadowTexCoord.w = 1.0f;
Out.ShadowTexelPos = Out.ShadowTexCoord * fShadowMapSize;
//shadow mapping variables end
}
//apply fog
float3 P = mul(matView, vWorldPos); //position in view space
float d = length(P);
Out.Fog = get_fog_amount_new(d, vWorldPos.z);
return Out;
}
这个Vertex Shader的代码是envmap_shader_Instanced的,游戏里itm_pike(枪)物品材质所用的着色器。我把代码(红色部分)添加到了这里,编译也没报错然后我把编译的fxo文件
复制替换到了骑砍的根目录下并新添加了一个brf文件导入了着色层技术栏也改成了envmap_shader_Instanced但是附加到我做的模型上进游戏却没有效果。我不知道自己哪个步骤出了问题
希望各位指点迷津
|
-
-
|