Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 05 Jun 2007
Offline Last Active Mar 25 2016 01:18 AM

#5190334 Surface to texture

Posted by on 31 October 2014 - 05:43 AM

Use CreateTexture to create new texture then use GetSurfaceLvl to grab its surface then use UpdateSurface to copy to it from your surface,  tho i don't understand why do you even load surface from file instead texture?

#5190269 Surface to texture

Posted by on 30 October 2014 - 07:42 PM

Maybe he wants to copy some surface to new texture?

#5187491 Should I try to optimise the World matrix build like this?

Posted by on 16 October 2014 - 03:47 PM

I don't even use scaling (i don't need it at runtime for my project), as for translation and rotation i just compose into one matrix from vector and quaternion, and this is done only for "dynamic" objects since i have lot of static objects (where world is identity) so i can skip lots of unnecessary world*view*proj (so i have just one view*proj for all of those).

#5179981 Light - Dot function

Posted by on 12 September 2014 - 04:15 PM

As kauna said you need to normalize light vector and normal of the surface to get reasonable result from dot product (-1, 1) and then use saturate to get value (0, 1) so you can scale your diffuse color (0 - 100%) based on light/normal orientation, on top of that ambient color should be uniform from all directions so you might want to add it instead multiply, something like:

float3 diffuseMap = txDiffuse.Sample(...);
float3 LightDir = normalize(PosD);
float3 Normal = normalize(In.Normal);
float3 LighD = float3 (0.5f, 0.5f, 0.5f);
float3 LighA = float3 (0.2f, 0.2f, 0.2f);
float NdotL = saturate(dot(Normal, LightDir));
FinalColor.rgb = (NdotL * diffuseMap * LighD) + LighA;

#5174162 Cannot render the navigation mesh

Posted by on 16 August 2014 - 04:43 PM

I created simple class for you that wrap whole thing in one place




and then you can write simple shader to draw with:


float4x4 WorldViewProjection;
struct VERTEX
    float3 Position : POSITION;
    float3 Color    : COLOR;

struct V2P
    float4 Position : POSITION;
    float3 Color    : COLOR;
struct P2A
    float4 Color : COLOR;

void vs(in VERTEX IN, out V2P OUT)
    OUT.Position = mul(float4(IN.Position.xyz, 1.0f), WorldViewProjection);
    OUT.Color = IN.Color;

void ps(in V2P IN, out P2A OUT)
    OUT.Color = float4(IN.Color, 1.0f);
technique Tech
    pass p0
        VertexShader = compile vs_3_0 vs();
        PixelShader = compile ps_3_0 ps();

#5174069 Cannot render the navigation mesh

Posted by on 16 August 2014 - 05:04 AM

I think i read somewhere that in "Debug" mode every variable is intialized with 0, "Release" gives you garbage values.


What happend, the mesh is created with D3DXCreateMesh (which then you never use as i can see), but its verticess/indices are not yet assigned and you used them which is wrong!

You need to extract that info from rcPolyMeshDetail and pass that to SetProps



edit: remove * 3 in CreateVertexBuffer and CopyMemory


//CopyMemory ( pData, (void*)&m_Vertices, sizeof(CPerfectVertex) * 3 * m_Vertices.size());
CopyMemory ( pData, (void*)&m_Vertices[0], sizeof(CPerfectVertex) * m_Vertices.size()); // notice [0], it is very different thing!

edit3: You need to call SetStreamSource right before DrawPrimitive (unless this is the only thing you render which i doubt).

#5174058 Cannot render the navigation mesh

Posted by on 16 August 2014 - 03:12 AM

There are so many things wrong in your code, i will try to show some of them:


1.  How this can even compile?

std::vector m_Vertices; 

2. You are recreating VB every Render call which is very bad.


3. You fill the vector with all mesh vertices but your VB can hold only 1 triangle and then you try to draw all of them:

g_pDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, m_Vertices.size() / 3 );


4. You need to set FVF or vertex declaration before DrawPrimitive  call.


5. Navigation mesh is static, build it once and draw anytime, no need to lock/unlock every render.


6. Use dx debug runtime to your advantage.

#5173746 how remove a model

Posted by on 14 August 2014 - 06:26 PM


#5173539 Convert view space to world space issues

Posted by on 14 August 2014 - 03:46 AM

I don't know what might be wrong now, but i would suggest to try something but in view-space as it should give you same results as in world-space.


You can transform your check_pos in view-space and do the compare with view-space position:

float3 check_pos_vs = mul( m_V, check_pos ) .xyz;
if (distance(view_pos, check_pos_vs) < 1.0)
return float4(1,0,0,1);


and let me know if that works.

#5173315 Convert view space to world space issues

Posted by on 13 August 2014 - 06:15 AM

Here are the file relevant contents / matrix definitions - I have literally tried them all:

... //code snip

Nothing in there suggest what you need. sad.png


Yes that's in my hmodel.h as well but since I'm doing a post-process (i.e. working on a different shading stage) I doubt I could make use of that matrix (but I'll check).

m_v2w name suggest that it is "view to world" matrix, if you look below in same file in hmodel function:

half3    nw        = mul( m_v2w, normal );

They take view-space normal (probably from g-buffer i guess) and calculate nw "normal in world-space".

The problem Is m_v2w available/passed in that "shading stage"?


Hmm, that's strange. I've seen lots of code parts in the default stalker shaders where it's done the way I have it - but I'll check as well. Haven't seen any pragma specifying row major so far, though.

Matrices might be passed transposed then this order would work:

float3 V = mul( VECTOR, MATRIX );

You need to check documentation (if any?) to see how they expose/pass their matrices.


Btw, what do you mean by "raw" shaders?

I meant they are not using "Effect framework" in which row-major is default.

#5173306 Convert view space to world space issues

Posted by on 13 August 2014 - 04:45 AM

Oh, you are the guy that makes STALKER mods? smile.png


Can i see the file where m_WV is defined, maybe the view-inverse is provided but under different name.


I have Clear Sky unpacked, and In hmodel.h file i see something that might be it:

uniform half3x4                        m_v2w;

Since STALKER is using "raw" shaders, i think column major is default (unless it is overridden somewhere) so you need to swap matrix-vector for mul op:

//float3 V = mul( VECTOR, MATRIX );
float3 V = mul( MATRIX, VECTOR );

#5172886 HLSL Bump Mapping Problem (Solved)

Posted by on 11 August 2014 - 01:40 PM

Why do you delete all your posts? That is rude!

#5172658 Skybox with 'moving' cubemap?

Posted by on 10 August 2014 - 05:02 PM

Rastertek had some tutorials about that, but the site is down, luckily i have backup on my hard drive and i attached it for you.

It is for dx11 but i think you can easely convert it to dx9.


Attached File  Tutorial 12 Perturbed Clouds.rar   778.8KB   146 downloads


If you cant get this to work i can spend some time to dig something from my old dx9 project where i have implemented something similar but not as good.tongue.png 

#5169332 [CSM] Cascaded Shadow Maps split selection

Posted by on 26 July 2014 - 11:01 AM

I use additive blending for accumulation (srcblend = one & destblend = one) also i reuse same shadow_rt for the rest of the lights (spot, point), and i do the lightning on the same pass (deferred rendering).


edit: to not get confused



And how do you do the following part? Simply alpha blending?

shadows_buffer += shadow_rt


i pass shadow_rt as texture when i draw to shadow_buffer to merge + do the lightning.


edit2: might be worth mentioning, in csm pass i use clip function to get correct result because of overlapping, and might be faster then branching?

// on top of the pixel shader
float4 posVS    = tex2D(gbPosition_samp, IN.TexCoord0); // view space position

    clip(posVS.z - SplitDist.x);
    clip(SplitDist.y - posVS.z);

#5169316 [CSM] Cascaded Shadow Maps split selection

Posted by on 26 July 2014 - 10:12 AM

I find that approach restrictive.

I use 2 render targets to handle CSM, one for the actual split (say 4096x4096) and the other is screen-size buffer in which i accumulate all shadows.

     shadows_buffer += shadow_rt


this way i can have arbitrary number of splits/cascades.


4 splits



9 splits