Ludum Dare 33
Coming August 21st-24th!

Ludum Dare 32 Results
See the winners!

Do shaders count as “content”?

Posted by
April 17th, 2009 3:08 am

Just wondering:

Do HLSL shaders count as “content” (in which case they must be written during the compo) or “part of a graphics library” (in which case they can be written before the compo)?

Tags: , ,

2 Responses to “Do shaders count as “content”?”

  1. dertom says:

    I would say it is something that counts as library. To be sure add a link to your HLSL-script.

  2. 5parrowhawk says:

    I’ll do that as soon as I’ve written it. 😀 Probably within the next 3-4 hours, actually.

    edit: lol, here you go. mostly borrowed from Mike Schuld with a bit of hackery-pokery. this comment thing doesn’t seem to like indents but I’m too tired to care right now.

    float4x4 World;
    float4x4 View;
    float4x4 Projection;
    sampler TextureSampler;
    float3 EyePosition;
    float4 DiffuseColor;
    float4 AmbientColor;
    float4 SpecularColor;
    float SpecularPower;
    float3 LightPosition;
    float4 LightDiffuseColor;
    float4 LightAmbientColor;
    float4 LightSpecularColor;
    struct VS_INPUT
    float4 Position : POSITION0;
    float2 Texcoord : TEXCOORD0;
    float3 Normal : NORMAL0;
    struct VS_OUTPUT
    float4 Position : POSITION0;
    float2 Texcoord : TEXCOORD0;
    float3 Normal : TEXCOORD1;
    float3 ViewDirection : TEXCOORD2;
    float3 LightDirection : TEXCOORD3;
    VS_OUTPUT Transform(VS_INPUT Input)
    float4x4 WorldViewProject = mul(mul(World, View), Projection);
    float3 ObjectPosition = mul(Input.Position, World);
    VS_OUTPUT Output;
    Output.Position = mul(Input.Position, WorldViewProject);
    Output.Normal = mul(Input.Normal, World);
    Output.ViewDirection = EyePosition - ObjectPosition;
    Output.Texcoord = Input.Texcoord;
    Output.LightDirection = LightPosition - ObjectPosition;
    return Output;
    struct PS_INPUT
    float2 Texcoord : TEXCOORD0;
    float3 Normal : TEXCOORD1;
    float3 ViewDirection : TEXCOORD2;
    float3 LightDirection : TEXCOORD3;
    float4 BasicShader(PS_INPUT Input) : COLOR0
    float3 Normal = normalize(Input.Normal);
    float3 ViewDirection = normalize(Input.ViewDirection);
    float3 LightDirection = normalize(Input.LightDirection);
    float EdgeComponent = dot(Normal, ViewDirection);
    float OutlineComponent = saturate(max(EdgeComponent,0));
    float4 TotalAmbient = saturate(AmbientColor * LightAmbientColor * ((EdgeComponent/4.0)+0.75));
    float NDotL = dot(Normal, LightDirection);
    float4 DiffuseAverage = DiffuseColor * LightDiffuseColor;
    float4 TotalDiffuse = saturate(DiffuseAverage * NDotL);
    float3 Reflection = normalize(2.0f * NDotL * Normal - LightDirection);
    float RDotV = max(0.0f, dot(Reflection, ViewDirection));
    float4 TotalSpecular = saturate(LightSpecularColor * pow(RDotV, SpecularPower));
    float4 FinalColor = saturate(TotalAmbient + TotalDiffuse);
    return saturate(FinalColor * ((FinalColor * 0.1)+(tex2D(TextureSampler, Input.Texcoord)*0.9)) + TotalSpecular);
    technique BasicShader
    pass P0
    VertexShader = compile vs_2_0 Transform();
    PixelShader = compile ps_2_0 BasicShader();
    AlphaBlendEnable = false;
    AlphaTestEnable = false;
    ZEnable = true;
    ZWriteEnable = true;
    CullMode = None;

Leave a Reply

You must be logged in to post a comment.

[cache: storing page]