OlegBuryat Posted September 16 Share Posted September 16 I can't make the car windows more transparent using a shader. If I apply a shader with transparency to vehiclegeneric256, it works more or less (screenshot 1). But as soon as I use custom lighting, all other parts of the vehiclegeneric256 texture also become transparent (screenshot 2). The reason I started doing this is that dl_core and other shaders don't work through car windows (screenshots 3 and 4), and I haven't found a solution to this problem. What I'm using: dl_core dl_lightmanager dl_vehicles Shader (used on engineApplyShaderToWorldTexture(vwShader, "vehiclegeneric256", source)): Spoiler float4 gColor = float4(1,1,1,0); bool bIsGTADiffuse = true; //--------------------------------------------------------------------- // Include some common stuff //--------------------------------------------------------------------- #include "mta-helper.fx" //--------------------------------------------------------------------- // Sampler for the main texture //--------------------------------------------------------------------- sampler Sampler0 = sampler_state { Texture = (gTexture0); }; //--------------------------------------------------------------------- // Structure of data sent to the vertex shader //--------------------------------------------------------------------- struct VSInput { float3 Position : POSITION0; float4 Diffuse : COLOR0; float2 TexCoord : TEXCOORD0; }; //--------------------------------------------------------------------- // Structure of data sent to the pixel shader ( from the vertex shader ) //--------------------------------------------------------------------- struct PSInput { float4 Position : POSITION0; float4 Diffuse : COLOR0; float2 TexCoord : TEXCOORD0; }; //------------------------------------------------------------------------------------------ // VertexShaderFunction // 1. Read from VS structure // 2. Process // 3. Write to PS structure //------------------------------------------------------------------------------------------ PSInput VertexShaderFunction(VSInput VS) { PSInput PS = (PSInput)0; // Calculate screen pos of vertex PS.Position = MTACalcScreenPosition ( VS.Position ); // Pass through tex coord PS.TexCoord = VS.TexCoord; // Calculate GTA lighting for buildings float4 Diffuse = MTACalcGTABuildingDiffuse( VS.Diffuse ); PS.Diffuse = 0; if (bIsGTADiffuse) PS.Diffuse = Diffuse; else PS.Diffuse = float4(1,1,1,Diffuse.a); PS.Diffuse *= gColor; return PS; } //------------------------------------------------------------------------------------------ // PixelShaderFunction // 1. Read from PS structure // 2. Process // 3. Return pixel color //------------------------------------------------------------------------------------------ float4 PixelShaderFunction(PSInput PS) : COLOR0 { // Get texture pixel float4 texel = tex2D(Sampler0, PS.TexCoord); // Apply diffuse lighting float4 finalColor = texel * PS.Diffuse; return finalColor; } //------------------------------------------------------------------------------------------ // Techniques //------------------------------------------------------------------------------------------ technique colorize { pass P0 { CullMode = 1; VertexShader = compile vs_2_0 VertexShaderFunction(); PixelShader = compile ps_2_0 PixelShaderFunction(); } } // Fallback technique fallback { pass P0 { // Just draw normally } } Spoiler It's ok Other vehiclegeneric256 textures makes transparent I can see dl_light But I can't see the light through the car windows Link to comment
Laxante101 Posted September 29 Share Posted September 29 check that the color variable is correct; change float4 gColor = float4(1,1,1,0); to float4 gColor = float4(1,1,1,1); so that it is fully opaque. Without PixelShaderFunction, add finalColor.a = texel.a * PS.Diffuse.a; to ensure that texture transparency is applied. Disabling Culling, changing CullMode = 1; to CullMode = 0;, and testing the shader without lighting to see if the problem persists. Check that the windows texture has an alpha channel that is being applied correctly, and consider testing with the fallback shader to rule out interference Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now