Jump to content

  • Log In with Google      Sign In   
  • Create Account

markypooch

Member Since 26 Mar 2013
Offline Last Active Oct 19 2014 06:36 PM

Posts I've Made

In Topic: OmniDirectional Shadow Mapping

14 September 2014 - 12:42 AM

Your right I was approaching it in a pretty convoluted fashion :P

Anyhow I got it working using a single matrice for the point light. Now I just have deal with some peter-panning of the shadows

 

P.s. I don't know why but it makes me cringe to have to send more data to the shader then just a few matrices and a variable or two.

      I would imagine however doing PCF in the pixel shader to be a bit more intensive


In Topic: Pipeline Configuration for Post-Processing Shaders

24 July 2014 - 06:52 PM

Drawing without a vertex buffer is a common idiom for fullscreen quads.  See Using the Input-Assembler Stage without Buffers on MSDN for a description and sample code.

Very informative. So Really for my simple Post-Process Shader, I can pretty much skip Buffer submission to D3D and just define my quad in the Vertex Shader...I Like it!

 

I guess my orginal thought regarding Post-Processing is more akin to utilitizing a Compute Shader (Don't know why at the time I thought no Geometry would be involved, It was a looooong day yesterday!)

 

Thanks for the replies, and sorry for the newebish question. it did give me some interesting ideas!

 

Marcus


In Topic: Pipeline Configuration for Post-Processing Shaders

23 July 2014 - 07:15 PM

You still need a vertex shader - the geometry is a quad or triangle that covers your entire screen!

To work without any geometry at all, you'd use a compute shader instead of a pixel shader, an Dispatch instead of Draw.

tongue.png It's been a looooong day.

 

I knew better, thank you so much.

 

Marcus


In Topic: Bad Performance On Intel HD

08 July 2014 - 11:11 AM

Status update!

Having my pixel shader only sample diffuse textures does make the game run at a playable frame rate. BUT only if I set a pretty low frustrum cull bound for the geometry ( which with the old shader still would be unplayable).

So I guess try instancing next. Maybe buffer batching? I have a bad feeling that maybe d3d is a bit thicker then I thought it was. And all the draw calls I have are eating my performance. When I could potentially consolidate many of them.

Wouldn't Intel HD if it only supported D3D10.1 crash my program when I create the device and explicitly tell it to use a d3d11 feature level and set the driver type to hardware?

Looks like downgrading the pixel shader helped some. I still can't render the whole scene without lagging and (with the whole scen in question) im not rendering more then 6000 triangles.

So ill give the profilier a shot. And if anyone else has any suggestions let me know!

Thanks for the replies!

In Topic: Assimp and Flipping Normals

26 June 2014 - 06:10 AM

In Blender when I'm creating the meshes, they are iron-maidening correctly with their normals.

Krohm did bring up a point. I am using two seperate shaders for Mesh's without textures and those WITH textures (diffuse, normal, spec, ect.)

 

So I am for my models using a seperate shader (so seperate pipeline) for rendering without textures. BUT for all intents and purposes the code should be indentical

minus the Texture2D type and mulitplication of that and the final fragment color.

 

I'll check my material shader and ill post here. Ill be gone for most of the day. Work and all that fun stuff, so thanks for the replies!

 

[/code]

 

///////////////////////////////////////////////////////
//
//                Material Shader
//
////////////////////////////////////////////////////////


//Load Unused Texture Sampler into GPU Register(s0)
//Load clamp Sampler for Shadow Map into GPU Register(s1)
//////////////////////////////////////////////////////////////////
SamplerState            colorSampler        : register(s0);
SamplerState            sampleTypeClamp        : register(s1);

//CONSTANT BUFFERS=========================
//CB's for Matrices, allows C++ Code to send constants
//to the shader and bind them into Registers (b0, b1, b2 respectively)
//===========================================================
cbuffer world : register(b0)
{
    matrix worldMat;
}

cbuffer view  : register(b1)
{
    matrix viewMat;
}

cbuffer proj  : register(b2)
{
    matrix projMat;
}

cbuffer lView : register(b3)
{
    matrix lightViewMat;
}

cbuffer lProj : register(b4)
{
    matrix lightProjMat;
}

cbuffer camBuffer : register(b5)
{
    float3 camPos;
    float  pad;
};
//==================================================

//Structures for Shader Constants
//===================================
struct Light
{
    float3 dir;
    float3 pos;
    float  range;
    float3 att;
    float4 diffuse;
    float4 ambient;
};
//===================================

//Load the main light into the shader and bind it to register b0
cbuffer LightCB  : register(b0)
{
    Light light[6];
}


//Structures for Vertex and Pixel
/////////////////////////////////////////
struct VS_Input
{
    float4 pos       : POSITION;
    float4 color     : COLOR;
    float3 norm      : NORMAL;
};

struct PS_Input
{
    float4 pos            : SV_POSITION;
    float4 wPos            : POSITION;
    float4 color        : COLOR;
    float3 norm            : NORMAL;

    float4 lightViewP    : TEXCOORD1;
    float3 lightPos     : TEXCOORD2;
    float3 viewDir      : TEXCOORD3;
};
///////////////////////////////////////////

//Vertex Shader
///////////////////////////////////
PS_Input VS(VS_Input vertex)
{
    //Init Output Struct
    /////////////////////////////////////
    PS_Input vsOut     = (PS_Input)0;
    vertex.pos.w = 1.0f;
    float4   cameraPos = 0.0f;

    //Transform Vertices into worldSpace
    ///////////////////////////////////////////
    vsOut.pos = mul(vertex.pos, worldMat);
    vsOut.pos = mul(vsOut.pos , viewMat);
    vsOut.pos = mul(vsOut.pos , projMat);

    //Transform LightMatrix into worldSpace - ShadowMapping
    ///////////////////////////////////////////
    vsOut.lightViewP = mul(vertex.pos, worldMat);
    vsOut.lightViewP = mul(vsOut.lightViewP, lightViewMat);
    vsOut.lightViewP = mul(vsOut.lightViewP, lightProjMat);

    //Transform VertexNormal into WorldSpace, normalize it
    //////////////////////////////////////////
    vsOut.norm = mul(vertex.norm, worldMat);
    vsOut.norm = normalize(vsOut.norm);
    
    //Grab the relative worldSpace position of a vertice (Usefull for lighting calculations)
    /////////////////////////////////////////
    vsOut.wPos   = mul(vertex.pos, worldMat);

    //Transform cameraPosition to worldSpace - SpecularMapping
    ////////////////////////////////////////
    vsOut.viewDir = camPos.xyz - vsOut.wPos.xyz;
    vsOut.viewDir = normalize(vsOut.viewDir);

    vsOut.color   = vertex.color;

    //Return output structure as Input into PixelShader
    ////////////////////////////////////////
    return vsOut;
}
//////////////////////////////////
//

//
float4 PS(PS_Input texel) : SV_TARGET
{
    //texel.lightViewP.xyz /= texel.lightViewP.w;
    
    //Variable Initalization
    /////////////////////////////////////////////////
    float2 projectTexCoord = float2(0.0f, 0.0f);
    float  bias            = 0.0000003f;
    float  lightIntensity  = 0.0f;
    float  depthValue      = 0.0f;
    float  lightDepthValue = 0.0f;
    float4 color           = float4(0.0f, 0.0f, 0.0f, 0.0f);
    float4 lightObject     = light[5].diffuse;
    float4 specular        = float4(0.0f, 0.0f, 0.0f, 0.0f);
    bool   lightHit        = false;
    /////////////////////////////////////////////////

    //Grab the lightPosition at the vertex
    /////////////////////////////////////////
    texel.lightPos = light[5].pos.xyz - texel.wPos.xyz;
    texel.lightPos = normalize(texel.lightPos);
    /////////////////////////////////////////

    //return lightObject;
    lightIntensity = saturate(dot(texel.norm, light[5].pos));

    texel.lightViewP.xyz /= texel.lightViewP.w;
 
    //if position is not visible to the light - dont illuminate it
    //results in hard light frustum
    if( texel.lightViewP.x < -1.0f || texel.lightViewP.x > 1.0f ||
        texel.lightViewP.y < -1.0f || texel.lightViewP.y > 1.0f ||
        texel.lightViewP.z < 0.0f  || texel.lightViewP.z > 1.0f )
    {
        
        lightObject = light[5].ambient;
    }
 
    //transform clip space coords to texture space coords (-1:1 to 0:1)
    texel.lightViewP.x = texel.lightViewP.x/2 + 0.5;
    texel.lightViewP.y = texel.lightViewP.y/-2 + 0.5;
 
    texel.lightViewP.z -= bias;

    //sample shadow map - point sampler
    float shadowMapDepth = colorMap.Sample(sampleTypeClamp, texel.lightViewP).r;
 
    //if clip space z value greater than shadow map value then pixel is in shadow
    if ( shadowMapDepth < texel.lightViewP.z)
    {
        lightObject = light[5].ambient;
    }

    float4 color2 = lightObject;
    color = saturate(color2 + lightObject) * texel.color;

    float4 finalColor = float4(0.0f, 0.0f, 0.0f, 0.0f);

        
    [unroll]
    for (int i = 0; i < 5; i++)
    {
        float3 lightToPixelVec = light[i].dir - texel.wPos;
        //Find the distance between the light pos and pixel pos
        float d = length(lightToPixelVec);

        //If pixel is too far, return pixel color with ambient light
        if( d > 100.0f)
            continue;
        
        //Turn lightToPixelVec into a unit length vector describing
        //the pixels direction from the lights position
        lightToPixelVec /= d;
    
        //Calculate how much light the pixel gets by the angle
        //in which the light strikes the pixels surface
        float howMuchLight = dot(lightToPixelVec, texel.norm);

        //If light is striking the front side of the pixel
        if( howMuchLight > 0.0f )
        {    
            //Add light to the finalColor of the pixel
            finalColor += howMuchLight * texel.color * light[i].diffuse;
        
            //Calculate Light's Falloff factor
            finalColor /= light[i].att[0] + (light[i].att[1] * d) + (light[i].att[2] * (d*d));
        }    
        
        //make sure the values are between 1 and 0, and add the ambient
        color = saturate(color + finalColor);
    }
    
    //color += float4(0.5f, 0.0f, 0.0f, 1.0f);
    return color;
}

 

[/code]

 

P.s. It seems I have forgotten how to do the code brackets :P

 

Marcus


PARTNERS