jeudi 16 juillet 2015

[Shaders] Unlit brush faces

Hi everyone!
I am trying to create custom lightmapped shader, but in game (SDK 2013) brush faces with my shader are unlit:

http://ift.tt/1e2a9XA

As I found out, engine does not load TEXTURE_LIGHTMAP (only gray color) or correct lightmap texture coordinates.
(btw SDK_LightmappedGeneric unlit too)

Somebody knows how to solve the problem?

Here is my code:
Vertex shader:
Code:

#include "common_vs_fxc.h"

struct VS_INPUT
{
        float4 Position : POSITION0;
        float2 Texcoord : TEXCOORD0;
        float2 LightmapTexcoord : TEXCOORD1;

};

struct VS_OUTPUT
{
        float4 Position : POSITION0;
        float2 Texcoord : TEXCOORD0;
        float2 LightmapTexcoord : TEXCOORD1;

};

VS_OUTPUT main( VS_INPUT Input )
{
        VS_OUTPUT Output;

        Output.Position = mul(Input.Position, cModelViewProj);
        Output.Texcoord = Input.Texcoord;
        Output.LightmapTexcoord = Input.LightmapTexcoord;

        return Output;
}

Pixel shader:
Code:

#include "common_ps_fxc.h"

sampler BaseTexture : register(s0);
sampler Lightmap    : register(s1);

struct PS_INPUT
{
        float2 Texcoord : TEXCOORD0;
        float2 LightmapTexcoord : TEXCOORD1;

};

float4 main(PS_INPUT Input) : COLOR0
{
        float4 Base        = tex2D( BaseTexture, Input.Texcoord );
        float4 Lightmap = tex2D( Lightmap, Input.LightmapTexcoord );
        return Base * Lightmap;
}

Code in game_shader_dx9:
Code:

#include "basevsshader.h"

#include "test_shader_ps30.inc"
#include "test_shader_vs30.inc"

#include "tier0/memdbgon.h"


BEGIN_VS_SHADER( test_shader, "Help for test_shader" )

        BEGIN_SHADER_PARAMS
        END_SHADER_PARAMS

        SHADER_INIT_PARAMS()
        {
                SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
        }
        SHADER_INIT
        {
                // Load the base texture here!
                LoadTexture( BASETEXTURE );
        }

        SHADER_FALLBACK
        {
                return 0;
        }

        SHADER_DRAW
        {
                SHADOW_STATE
                {
                        pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
                        pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );

                        int fmt = VERTEX_POSITION | VERTEX_COLOR;
                        // Two texture coordinates: for base and lightmap
                        pShaderShadow->VertexShaderVertexFormat( fmt, 2, 0, 0 );

                        DECLARE_STATIC_VERTEX_SHADER(test_shader_vs30);
                        SET_STATIC_VERTEX_SHADER(test_shader_vs30);
                        DECLARE_STATIC_PIXEL_SHADER(test_shader_ps30);
                        SET_STATIC_PIXEL_SHADER(test_shader_ps30);

                }
                DYNAMIC_STATE
                {
                        BindTexture( SHADER_SAMPLER0, BASETEXTURE );
                        // Load lightmap texture here
                        pShaderAPI->BindStandardTexture(SHADER_SAMPLER1, TEXTURE_LIGHTMAP);

                        DECLARE_DYNAMIC_VERTEX_SHADER(test_shader_vs30);
                        SET_DYNAMIC_VERTEX_SHADER(test_shader_vs30);
                        DECLARE_DYNAMIC_PIXEL_SHADER(test_shader_ps30);
                        SET_DYNAMIC_PIXEL_SHADER(test_shader_ps30);
                                       
                }
                Draw();
        }
END_SHADER

[Shaders] Unlit brush faces

0 commentaires:

Enregistrer un commentaire

Popular Posts

Categories

Unordered List

Text Widget

Blog Archive

Followers

Fourni par Blogger.