Shader: can't get color of first pixel.
by Lukas Joergensen · in Torque 3D Professional · 04/14/2014 (3:07 pm) · 16 replies
Hey guys!
I've tried just about everything, but I can't make my tex2dlod call return the pixels I need.
Currently working with a 4x4 texture with 1 mip.
I'm trying to get the information from pixel[0;0] and pixel[1;0]
My current hlsl code:
The texture does have information in the pixels, I checked it using Pix. And uvx is calculated to be 0.25 and uvy to be 0.
I did this to define the sampler:
This is where I set the texture:
Any help is greatly appreciated, no matter what I try Output.basis_col0 is always (0,0,0).
I've tried just about everything, but I can't make my tex2dlod call return the pixels I need.
Currently working with a 4x4 texture with 1 mip.
I'm trying to get the information from pixel[0;0] and pixel[1;0]
My current hlsl code:
uniform sampler2D LightInfoDDS : register(S2); uniform float2 lightMapSize; // Irrelevant code float uvy = 0*lightMapSize.y; float uvx = 1*lightMapSize.x; Output.basis_col0 = tex2Dlod(LightInfoDDS, float4(0,0,0,0)); Output.basis_col1 = tex2Dlod(LightInfoDDS, float4(uvx,uvy,0,0));
The texture does have information in the pixels, I checked it using Pix. And uvx is calculated to be 0.25 and uvy to be 0.
I did this to define the sampler:
d.samplers[2] = GFXSamplerStateDesc::getClampPoint();I don't know if that is not enough, or wrong.
This is where I set the texture:
GFXTexHandle *hdl = new GFXTexHandle(dds, &GFXDefaultStaticDiffuseProfile, true, "LightInfoDDS");
GFXTextureObject *obj = hdl->getPointer();
GFX->setTexture(2, obj);
mParticleShaderConsts.mShaderConsts->set( mParticleShaderConsts.mLightCount, idx);
mParticleShaderConsts.mShaderConsts->set( mParticleShaderConsts.mLightMapSize, Point2F(1.f/ddsHeight, 1.f/ddsWidth));
GFX->drawIndexedPrimitive( GFXTriangleList, 0, 0, ri->count * 4, 0, ri->count * 2 );
SAFE_DELETE(hdl);Any help is greatly appreciated, no matter what I try Output.basis_col0 is always (0,0,0).
About the author
IPS Bundle available at: https://www.winterleafentertainment.com/Products/IPS.aspx
#2
In the console type:
Btw, you must enable the postFX to see something.
04/17/2014 (1:22 am)
Lucas, if this is a PostFX there is a nice little tool in Torque which allows you to see what is happening.In the console type:
PfxVis::open(your_postfx_name);
Btw, you must enable the postFX to see something.
#3
Also, I'm using Pix to debug the shader, and according to Pix the texture is sent to the shader, it's just not getting the colors of the pixel.
I guess it must have something to do with how I calculate the coordinates, but (0,0) should be upper left corner shouldn't it?
04/17/2014 (4:23 am)
It's not a PostFX unfortunately, although what does PfxVis do?Also, I'm using Pix to debug the shader, and according to Pix the texture is sent to the shader, it's just not getting the colors of the pixel.
I guess it must have something to do with how I calculate the coordinates, but (0,0) should be upper left corner shouldn't it?
#4
04/18/2014 (2:00 am)
With PfxVis you get little windows showing the samplers of your postFX. It can be really useful.
#5
04/18/2014 (5:11 am)
Do you sample with NEAREST ?
#6
From MSDN:
04/18/2014 (5:38 am)
float m_MipLevel = 1 // Maybe 1? float2 UV1 = float2(0,0) float2 UV2 = float2(0,1) // tex2Dlod ( MAP , INFO) // Where INFO is a float4. The first 2 values are U and V, the third // is ignored, and the fourth the level of the mipmap // So: tex2Dlod ( MAP , float4( U, V, IGNORED, MIPLEVEL)) Output.basis_col0 = tex2Dlod(LightInfoDDS, float4(UV1.x, UV1.y, 0, m_MipLevel)); Output.basis_col1 = tex2Dlod(LightInfoDDS, float4(UV2.x, UV2.y, 0, m_MipLevel));
From MSDN:
Quote:
To use the intrinsic-style texture lookup functions, such as tex2Dlod, with shader model 4 and higher, use D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY to compile. However, if you want to target shader model 4 and higher (even *_4_0_level_9_*) with newer object-oriented style code, migrate to the newer HLSL syntax.
#7
@Alfio, I will try with Miplevel 1
04/22/2014 (2:16 am)
@Ivan the only thing I really did wasd.samplers[2] = GFXSamplerStateDesc::getClampPoint();Are you talking about another setting?
@Alfio, I will try with Miplevel 1
#8

It's a 4x4 image with a single mipmap at "Mip 0" according to Pix.
And basically all I want is the color of those 2 pixels.
Additional info:
04/23/2014 (12:46 pm)
Just some more info, this is the sampler I send to the shader:
It's a 4x4 image with a single mipmap at "Mip 0" according to Pix.
And basically all I want is the color of those 2 pixels.
Additional info:
Type: D3D9 Texture Format: D3DFMT_A32B32G32R32
#9
in D3D's terminology, 'nearest' is actually 'point'.
D3DTEXF_POINT in D3D = GL_NEAREST in OGL
d.samplers[2].minFilter = GFXTextureFilterPoint;
d.samplers[2].mipFilter = GFXTextureFilterPoint;
d.samplers[2].magFilter = GFXTextureFilterPoint;
04/24/2014 (8:20 am)
Sorry, Lucas,in D3D's terminology, 'nearest' is actually 'point'.
D3DTEXF_POINT in D3D = GL_NEAREST in OGL
d.samplers[2].minFilter = GFXTextureFilterPoint;
d.samplers[2].mipFilter = GFXTextureFilterPoint;
d.samplers[2].magFilter = GFXTextureFilterPoint;
#10
Seems like that is what getClampPoint() does.
Perhaps theres something else I fail to set up, I just can't see what it is.
04/28/2014 (4:54 am)
@IvanSeems like that is what getClampPoint() does.
Perhaps theres something else I fail to set up, I just can't see what it is.
#11
04/29/2014 (11:23 am)
Some sort of progress, it works completely fine in the pixel shader, it's just the vertex shader that is failing to get the color.
#12
I believe you are using shader model 3.
I have not tried VTF in DirectX, but it should work. It is said the supported formats are A32B32G32R32 and R16.
btw keep in mind you skip texture filtering for some GPUs and even if it run on your PC, this code is platform and hardware dependent anyway.
04/30/2014 (7:12 am)
How many vertices do you have ?I believe you are using shader model 3.
I have not tried VTF in DirectX, but it should work. It is said the supported formats are A32B32G32R32 and R16.
btw keep in mind you skip texture filtering for some GPUs and even if it run on your PC, this code is platform and hardware dependent anyway.
#13
Using:
And:
How platform dependent is it? I don't understand why it wouldn't run on everything.
For the record I use a Geforce GTX 550 TI
Edit: oh btw I don't know how many vertices.. Atm it'd be <1000
04/30/2014 (7:43 am)
@Ivan yes shader model 3.Using:
dds->mFormat = GFXFormat::GFXFormatR32G32B32A32F;
And:
singleton ShaderData( ParticlesLightingShaderData )
{
DXVertexShaderFile = "shaders/common/particlesLightV.hlsl";
DXPixelShaderFile = "shaders/common/particlesLightP.hlsl";
//OGLVertexShaderFile = "shaders/common/gl/particlesV.glsl";
//OGLPixelShaderFile = "shaders/common/gl/particlesP.glsl";
pixVersion = 3.0;
};How platform dependent is it? I don't understand why it wouldn't run on everything.
For the record I use a Geforce GTX 550 TI
Edit: oh btw I don't know how many vertices.. Atm it'd be <1000
#14
I know that ATI implemented this in a different way. That's why I said it is hardware dependent.
Anyway I would go sampling in the pixel shader.
It is slower, but it works - you have rasterization and texture filtration.
It is very important to have it when working with light data and light equations.
In the vertex shader you "may" have it.
04/30/2014 (8:38 am)
I have tried it using GLES2(or GLES3, don't remember exactly).I know that ATI implemented this in a different way. That's why I said it is hardware dependent.
Anyway I would go sampling in the pixel shader.
It is slower, but it works - you have rasterization and texture filtration.
It is very important to have it when working with light data and light equations.
In the vertex shader you "may" have it.
#15
I want to calculate the lighting for the particles in the vertex shader to avoid having to do it millions of times in the pixel shader.. Imagine 50 lights in the scene, affecting the particles.. It'd simply be too much..
04/30/2014 (8:51 am)
@Ivan, in this case I believe it to be so much slower that it has to be in the vertex shader.I want to calculate the lighting for the particles in the vertex shader to avoid having to do it millions of times in the pixel shader.. Imagine 50 lights in the scene, affecting the particles.. It'd simply be too much..
#16
I would generate the light volumes and colors, draw them to 2 paraboloid RTs with low resolution.
In the second pass I would generate the paraboloid uvs in the vertex shaders.
Having just 2 samples in the pixel shader for 50 lights, it is very fast.
05/09/2014 (5:09 am)
For 50 lights I will never use VTF.I would generate the light volumes and colors, draw them to 2 paraboloid RTs with low resolution.
In the second pass I would generate the paraboloid uvs in the vertex shaders.
Having just 2 samples in the pixel shader for 50 lights, it is very fast.
Torque Owner Lukas Joergensen
WinterLeaf Entertainment