Skip to main content
gamedev.net
🔒 Locked

Beginning shaders

Started by blaze02 May 25, 2006 at 10:29 PM 0 replies 550+ views
Original Post
blaze02
blaze02
I've heard that pixel shaders do not support some of the blending options in the fixed function pipeline. I want to do something much like setting DestBlend and SrcBlend to D3DBLEND_ONE. I want to blit a lot of textures to a surface, and at each pixel, color += texture_color. I would like to have a little more control (like multiplying some of the channels by alpha), but it isn't absolutely necessary. So is it possible to grab the destination pixel color in a pixel shader so I can add to it? I've heard its possible but slow. What kind of a hit will I take if I'm accessing the destination surface a lot? If the above isn't possible, what exactly does setting the source and dest. blend factors to one do to the alpha channel of the render surface? Thanks.
Namethatnobodyelsetook
Namethatnobodyelsetook
Regular alpha blending works using the output from the shader (except for floating point render targets, in which case it may not be supported).

Here's a simple FX file doing two textures. Currently it's lerping between the two based on an alpha, then additive blending them. Commented out above the lerp is some other mixing shown as an example.

Because the shader is 1.1 we need to output the UVs twice from the vertex shader. In ps.2.0 or higher you can use the same UVs to read from multiple textures.

//// Simple Lighting Model// Copyright (c) Microsoft Corporation. All rights reserved.//// Note: This effect file works with EffectEdit.// Note: This effect file is SAS 1.0.1 compliant and will work with DxViewer.//int sas : SasGlobal<    bool SasUiVisible = false;    int3 SasVersion= {1,1,0};>;string XFile< bool SasUiVisible = false; > = "tiger\\tiger.x";   // modelint    BCLR< bool SasUiVisible = false; > = 0xff202080;          // background// texturetexture Tex0 <     string SasUiLabel = "Texture Map";    string SasUiControl= "FilePicker";    string name = "tiger\\tiger.bmp"; >;sampler Sampler<bool SasUiVisible = false;> = sampler_state{    Texture   = (Tex0);    MipFilter = LINEAR;    MinFilter = LINEAR;    MagFilter = LINEAR;};texture Tex1 <     string SasUiLabel = "Texture Map";    string SasUiControl= "FilePicker";    string name = "trees\\tree35S.dds"; >;sampler Sampler1<bool SasUiVisible = false;> = sampler_state{    Texture   = (Tex1);    MipFilter = LINEAR;    MinFilter = LINEAR;    MagFilter = LINEAR;};float4x4 WorldViewProj : WorldViewProjection;struct VS_OUTPUT{    float4 Pos  : POSITION;    float2 Tex  : TEXCOORD0;    float2 TexCoord1  : TEXCOORD1;};VS_OUTPUT VS(    float4 Pos  : POSITION,     float2 Tex  : TEXCOORD0){    VS_OUTPUT Out;    Out.Pos = mul(Pos, WorldViewProj);                                       Out.Tex = Tex;    Out.TexCoord1 = Tex;    return Out;}float4 PS(VS_OUTPUT IN) : COLOR{    float4 t1 = tex2D(Sampler, IN.Tex);    float4 t2 = tex2D(Sampler1, IN.TexCoord1);    float3 color;//    color = t1.rgb * 0.25 + t2.rgb * t2.a;    color = lerp(t1.rgb, t2.rgb, t2.a);    return float4(color, 1);}technique TVertexAndPixelShader{    pass P0    {        // shaders        VertexShader = compile vs_1_1 VS();        PixelShader  = compile ps_1_1 PS();        AlphaBlendEnable = true;        SrcBlend = ONE;        DestBlend = ONE;    }  }

Topic Locked

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

Sign in to reply to this topic.