# HLSL: I "scorch" my alpha transparency!

This topic is 3090 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Once upon a time, I used shader ver. 2.0 when rendering terrains. That meant, that I had to use multipass rendering.
Then I upgraded to shader ver. 3.0 at some point, without bothering with maintaining the ver 2.0, but now I want to support ver. 2.0 again.

The new version blends 6 layers in one pass, without using alpha blending, since it based on the alphavalues on the layers, blends everything itself directly in the shader for the final result.

I hauled up my old version of the program to re-implement the multipass version, where each layer is rendered with an alpha-value, but of some reason, the alpha'ed areas get "scorched" (see image).

As you can see, the new version is blackened out, compared to the old one, which transitions nicely.

I use the following renderstates:
SetRenderState(D3DRS_ALPHABLENDENABLE, true)
SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA)
SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA)

Has anyone encountered something, that will result in this problem? Do I need another renderstate? Or is an already set state foiling my attempts?

It has been three years since I created the old version, and after having looked extensively through both versions, I simply cannot find the error.

##### Share on other sites
The image looks more like you have a problem with your texture coordinates or the size of your textures.

##### Share on other sites
It is the same system.

The only reason why it is butt-ugly in the lower version, is because I have turned off everything, that could interfere, like lighting etc.

The shader in the new implementation has been reduced to this:

float4 PS_light_normal_standard(float2 a_texcoord0: TEXCOORD0, float3 a_normal : TEXCOORD1, float4 a_world_position : TEXCOORD2, float3 a_tangent : TEXCOORD3, float3 a_binormal : TEXCOORD4, float4 a_worldview_position : TEXCOORD5, float a_positiondistance : TEXCOORD6) : COLOR{		float2 l_texcoord = a_texcoord0;		float4 l_basecolor = tex2D(g_layer1_texturemap_sampler, l_texcoord);		float l_layeralphafactor = tex2D(g_alphamapsampler, a_texcoord0)[g_alphachannel_index];		l_basecolor.w = l_layeralphafactor;										// "pode" the pixel with the alpha value		return l_basecolor;}

##### Share on other sites

SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE)
SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA)

should fix the problem. It appears your texture uses premultiplied alpha (info here) but you're blending it with the scene as though it weren't. Incidentally, you might want to consider moving all your blending over to this method, as there are a number of free quality improvements involving bilinear filtering behavior, etc. as mentioned in the linked Wikipedia article.

##### Share on other sites
I added these, as a blind shot. I have no idea why it works, but it does. I never used those before, not in my version from three years ago either.

SetRenderState(D3DRS_DESTBLENDALPHA, D3DBLEND_ONE);
SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE);

I really would like to know, why I have this problem, so if anyone has more input, as to why this happens, I would be glad.

##### Share on other sites
D3DRS_SEPARATEALPHABLENDENABLE
TRUE enables the separate blend mode for the alpha channel. The default value is FALSE.

When set to false, the render-target blending factors and operations applied to alpha are forced to be the same as those defined for color.

I am not sure it is related unless you are trying to write alpha color?

Btw, is that GUI bar from Ultima Online?

##### Share on other sites
Shanee, yes, that bar is from UO :)

I played that game for many years and was a big fan of it, so when I made a demo to use with job applications, I put the UO bar in, as homage to the old game, which IMO is the best MMO (at least in the old version) ever made, even to this date.

---

Im not sure how it is related. Maybe it cancels out another renderstate, that "scorches" my alphas? Not sure, but if I don't have it in, it will look scorced again.

What do you mean with "trying to write alpha color"?
From my shader-code (see above), you can see I do this:
l_basecolor.w = l_layeralphafactor;
return l_basecolor;

Not sure if that qualifies as "trying to write alpha color"?

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633768
• Total Posts
3013741
×