Skip to main content
GameDev.net gamedev.net
🔒 Locked

HLSL opacity question

Started by eboy Feb 26, 2009 at 11:25 AM 1 replies 2.8k views
Original Post
eboy
eboy
Hello, first of all I am an absolute beginner with this shader business, but very keen to learn how to create some custom shaders for my 3d models. I've been trying out FX Composer and was going through the shader library. I came across a shader that does the job I need apart from I want to add an opacity slider in the properties. I understand it's something like: float Opacity < string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 1.0; float UIStep = 0.1; string UIName = "Opacity"; > = 0.5; But then to get that working I have no idea. Like I said, very new to this. I have included a link below to the shader. If what I'm talking about is possible maybe someone can help? [smile] LINK
MJP
MJP
Okay at the very end of your pixel shader you have this line:
return float4(result.rgb,1.0);


So that basically says "take the red, green, and blue values from 'result' and use 1.0 as the alpha." What you want to do now is use your Opacity value as the alpha. Which looks like this:
return float4(result.rgb, Opacity);


Now there's one more thing you need to do...in order for alpha-blending to work you need to set the appropriate render states. You can do this by adding Effect States to your pass definition. You already have a few in there, to enable z-culling and z-writes. You'll want to modify that part so it looks like this:
VertexShader = compile vs_2_0 mainVS();ZEnable = true;ZWriteEnable = true;CullMode = None;AlphaBlendEnable = true;SrcBlend = SRCALPHA;DestBlend = INVSRCALPHA;PixelShader = compile ps_2_b mainPS();



eboy
eboy
MJP, thank you so much, it's fixed!

Getting my head round this is not easy. But it's fun when it works.

Looking forward to building up my shader knowledge.

[SMILE]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.